本文對Hive+mysql的安裝做一個總結,后期會把Hive的一些資料放上來:
1.安裝目標:
Hive搭配遠程Mysql
2.要點總結:
1).Mysql的配置:
假如Hive以hive用戶連接Mysql,以root用戶登錄Mysql:
drop user hive@'%';
grant all on db.* to hive@'%' identified by '密碼';(使用戶可以遠程連接Mysql)
grant all on db.* to hive@'localhost' identified by '密碼';(使用戶可以本地連接Mysql)
flush privileges;
2).Hive的安裝:
a).安裝包和環境的匹配:
本人安裝的是apache hadoop-1.0.x+Hive0.8。
b).Hive安裝
解壓安裝包,並在~/.bash_profile中添加HIVE_HOME環境變量,同時修改Path;
從mysql官網下載自己喜歡version的mysql-connector-java-version-bin.jar,放到$HIVE_HOME/lib下;
在$HIVE_HOME/conf下把hive-site.xml.example rename為hive-site.xml;
將hive.metastore.local屬性設置為true
其它需要修改的屬性為:
<property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.1.234:3306/hivedb?createDatabaseIfNotExist=true</value> <description>JDBC connect string for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> <description>Driver class name for a JDBC metastore</description> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> <description>username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> <description>password to use against metastore database</description> </property>
<property>
<name>hive.cluster.delegation.token.store.zookeeper.connectString</name>
<value>192.168.7.14:2181</value>
<description>The ZooKeeper token store connect string.</description>
</property>
3.metadata遠程存儲和hive.metastore.local屬性的說明:
官網上對hive.metastore.local屬性的解釋為:local or remote metastore (Removed as of Hive 0.10: If hive.metastore.uris is empty local mode is assumed, remoteotherwise);即本地或者遠程的元數據(在hive0.10版本上刪除列這個屬性;如果hive.metastore.uris屬性為空,則默認為本地模式,否則為遠程模式)。
而hive將元數據存儲在 RDBMS 中,有三種模式可以連接到數據庫:
1)ingle User Mode: 此模式連接到一個 In-memory 的數據庫 Derby,一般用於 Unit Test。
2)Multi User Mode:通過網絡連接到一個數據庫中,是最經常使用到的模式。
3)Remote Server Mode:用於非 Java 客戶端訪問元數據庫,在服務器端啟動一個 MetaStoreServer,客戶端利用 Thrift 協議通過 MetaStoreServer 訪問元數據庫。
如果配置遠程存儲metadata,則需要先在遠程端啟動hive的元數據存儲Server服務:hive --service metastore;Server端配置上面介紹的相同即可。默認的端口號是9083,我在conf目錄下所有文件里沒有grep到此端口,但是用netstat -anp |grep 9083能看到此端口處於監聽狀態,停止服務后,端口釋放,所以此版本端口號是在程序里寫死的。
client端的配置:
hive.metastore.uris | thrift://<host_name>:<port> | host and port for the thrift metastore server |
hive.metastore.local | false | this is local store |
hive.metastore.warehouse.dir | <base hdfs path> | default location for Hive tables. |
client端配置好后,執行hive命令去Server端取meta數據,而Server端數據存儲於mysql,將元數據存儲和Hive服務分開,詳細的官方文檔:https://cwiki.apache.org/Hive/adminmanual-metastoreadmin.html#AdminManualMetastoreAdmin-RemoteMetastore
至此,終於明白列hive.metastore.local屬性的作用!