Hive metastore三种配置方式
Hive的meta數(shù)據(jù)支持以下三種存儲(chǔ)方式,其中兩種屬于本地存儲(chǔ),一種為遠(yuǎn)端存儲(chǔ)。遠(yuǎn)端存儲(chǔ)比較適合生產(chǎn)環(huán)境。Hive官方wiki詳細(xì)介紹了這三種方式,鏈接為:Hive Metastore。
一、本地derby
這種方式是最簡(jiǎn)單的存儲(chǔ)方式,只需要在hive-site.xml做如下配置便可
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:derby:;databaseName=metastore_db;create=true</value>
</property><property><name>javax.jdo.option.ConnectionDriverName</name><value>org.apache.derby.jdbc.EmbeddedDriver</value>
</property><property><name>hive.metastore.local</name><value>true</value>
</property><property><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value>
</property>
</configuration> 注:使用derby存儲(chǔ)方式時(shí),運(yùn)行hive會(huì)在當(dāng)前目錄生成一個(gè)derby文件和一個(gè)metastore_db目錄。這種存儲(chǔ)方式的弊端是在同一個(gè)目錄下同時(shí)只能有一個(gè)hive客戶端能使用數(shù)據(jù)庫(kù),否則會(huì)提示如下錯(cuò)誤
hive> show tables;
FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Failed to start database 'metastore_db', see the next exception for details.
NestedThrowables:
java.sql.SQLException: Failed to start database 'metastore_db', see the next exception for details.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask 二、本地mysql
這種存儲(chǔ)方式需要在本地運(yùn)行一個(gè)mysql服務(wù)器,并作如下配置(下面兩種使用mysql的方式,需要將mysql的jar包拷貝到$HIVE_HOME/lib目錄下)。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration>
<property><name>hive.metastore.warehouse.dir</name><value>/user/hive_remote/warehouse</value>
</property><property><name>hive.metastore.local</name><value>true</value>
</property><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://localhost/hive_remote?createDatabaseIfNotExist=true</value>
</property><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value>
</property><property><name>javax.jdo.option.ConnectionUserName</name><value>hive</value>
</property><property><name>javax.jdo.option.ConnectionPassword</name><value>password</value>
</property>
</configuration> 三、遠(yuǎn)端mysql
這種存儲(chǔ)方式需要在遠(yuǎn)端服務(wù)器運(yùn)行一個(gè)mysql服務(wù)器,并且需要在Hive服務(wù)器啟動(dòng)meta服務(wù)。
這里用mysql的測(cè)試服務(wù)器,ip位192.168.1.214,新建hive_remote數(shù)據(jù)庫(kù),字符集位latine1
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration><property><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value>
</property><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://192.168.1.214:3306/hive_remote?createDatabaseIfNotExist=true</value>
</property><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value>
</property><property><name>javax.jdo.option.ConnectionUserName</name><value>hive</value>
</property><property><name>javax.jdo.option.ConnectionPassword</name><value>password</value>
</property><property><name>hive.metastore.local</name><value>false</value>
</property><property><name>hive.metastore.uris</name><value>thrift://192.168.1.188:9083</value>
</property></configuration> 注:這里把hive的服務(wù)端和客戶端都放在同一臺(tái)服務(wù)器上了。服務(wù)端和客戶端可以拆開,將hive-site.xml配置文件拆為如下兩部分
???????? 1)、服務(wù)端配置文件
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration><property><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value>
</property><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://192.168.1.214:3306/hive_remote?createDatabaseIfNotExist=true</value>
</property><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value>
</property><property><name>javax.jdo.option.ConnectionUserName</name><value>root</value>
</property><property><name>javax.jdo.option.ConnectionPassword</name><value>test1234</value>
</property>
</configuration> ??2)、客戶端配置文件
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration><property><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value>
</property><property><name>hive.metastore.local</name><value>false</value>
</property><property><name>hive.metastore.uris</name><value>thrift://192.168.1.188:9083</value>
</property></configuration> 啟動(dòng)hive服務(wù)端程序
$ hive --service metastore 客戶端直接使用hive命令即可
root@my188:~$ hive
Hive history file=/tmp/root/hive_job_log_root_201301301416_955801255.txt
hive> show tables;
OK
test_hive
Time taken: 0.736 seconds
hive> ?
轉(zhuǎn)載于:https://www.cnblogs.com/itboys/p/9254221.html
總結(jié)
以上是生活随笔為你收集整理的Hive metastore三种配置方式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【PHP+JS】uploadify3.2
- 下一篇: Java动态代理和静态代理区别