閱讀631 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Hive on CDH4部署、調錯及測試

環境介紹

hadoop是cdh4.2.0的版本,搭建見十分鍾搭建自己的hadoop2/CDH4集群

hive版本可以是cdh4.2.0的hive-0.10.0,下載包(win直接下載解壓會失敗,建議linux下wget下載)。也可以是hive-0.9.0(shark-0.7包裏自帶的amp實驗室提供的版本)。兩個版本我都嚐試了,都是可以的,使用後者這個版本比較低的hive的原因是為了使用shark。

metastore則是一個mysql,隻有你有mysql server,隨便create 一個 空的database即可。


Hive部署

1. conf下麵的hive-default等配置不需要改變,增加hive-site.xml,為其添加如下基本配置

dir相關:

<property>
  <name>hive.metastore.warehouse.dir</name>
  <value>/home/mywork/work/data/hive/warehouse-${user.name}</value>
  <description>location of default database for the warehouse</description>
</property>

<property>
  <name>hive.exec.scratchdir</name>
  <value>/home/mywork/work/data/hive/scratch-${user.name}</value>
  <description>Scratch space for Hive jobs</description>
</property>

<property>
  <name>hive.querylog.location</name>
  <value>/home/mywork/work/data/querylog-${user.name}</value>
  <description>
    Location of Hive run time structured log file
  </description>
</property>
hwi相關:

<property>
  <name>hive.hwi.listen.host</name>
  <value>10.65.17.192</value>
  <description>This is the host address the Hive Web Interface will listen on</description>
</property>
<property>
  <name>hive.hwi.listen.port</name>
  <value>9999</value>
  <description>This is the port the Hive Web Interface will listen on</description>
</property>
<property>
  <name>hive.hwi.war.file</name>
  <value>lib/hive-hwi-0.9.0-amplab-4.war</value>
  <description>This is the WAR file with the jsp content for Hive Web Interface</description>
</property>
jdbc相關:

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://xx.xx.xx.com:8306/hive?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8
</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>xxxx</value>
  <description>username to use against metastore database</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>xxxx</value>
  <description>password to use against metastore database</description>
</property>
2. 在HIVE_HOME/lib下要添加mysql-driver

3. HADOOP_HOME如果沒有在環境變量裏的話,請在conf/hive-env.sh裏export

3. 啟動hive,可以用bin/hive,但是這樣報錯無法定位到具體原因,建議使用

./bin/hive -hiveconf hive.root.logger=DEBUG,console
啟動,特別是初次使用和建立的metastore,會遇到一些問題。


Debug Hive

bin/hive初次啟動hive,執行 select tables; 可能會遇到如下錯誤:

FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
使用下麵方式啟動hive,

./bin/hive -hiveconf hive.root.logger=DEBUG,console
可能會遇到如下問題:

問題一

Transaction level-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'
解決方法,用mysql登錄查看hive的metastore數據庫,執行

SET GLOBAL binlog_format = 'ROW';
參考資料https://stackoverflow.com/questions/9665535/why-do-i-get-binary-logging-not-possible-on-my-mysql-server

問題二

MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes)
解決方法,執行

alter database hive character set latin1;
參考資料https://www.cnblogs.com/Blueren/archive/2011/06/29/Sir_001.html

如遇到其他問題,可能多數是和metastore有關,自行查閱之。


Test Hive

啟動自己的hadoop dfs和yarn,啟動hive,創建表:

create table test(num int, name string);
如果出錯信息為:

Field 'IS_STOREDASSUBDIRECTORIES' doesn't have a default value
解決方法是去hive庫裏執行

 ALTER TABLE `SDS` ALTER  `IS_STOREDASSUBDIRECTORIES` SET DEFAULT 0;
然後使用examples目錄下提供的一些測試數據和腳本,嚐試插入數據:

load data local inpath '/home/mywork/work/hive-0.9.0-bin/examples/files/kv1.txt' into table test; 
kv1-kv6共有六份txt,然後執行

select * from test where num > 400;
體驗下MR過程有多蠻長吧。。

(我最簡單對比了下,hive使用了14s,用shark僅1s,後續針對hive vs shark會有專門的博文)


(全文完)


最後更新:2017-04-03 15:22:03

  上一篇:go 知識共享圖文直播---(二)組合查詢
  下一篇:go 網絡子係統7_l2、l3接口