1. 程式人生 > >【Hadoop】Hadoop2.7.3安裝Hive 2.1.0

【Hadoop】Hadoop2.7.3安裝Hive 2.1.0

第一步
下載最新的hive,直接去apache 裡面找hive2.1.0下載就行。

第二步,解壓到伺服器

 tar zxvf apache-hive-2.0.0-bin.tar.gz 
 mv apache-hive-2.0.0-bin /home/hive
 cd /home/hive 

第三步,修改conf。這裡只關心hadoop和hive的配置,其他JAVA HBASE的配置根據自己來

vi /etc/profile 

#for hadoop
export HADOOP_HOME=/home/hadoop/hadoop-2.7.3
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME
/lib/native export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib" export PATH=$PATH:/home/hadoop/hadoop-2.7.3/bin export PATH=$PATH:/home/hadoop/hadoop-2.7.3/sbin #for hive export HIVE_HOME=/home/hive export PATH=$HADOOP_HOME/bin:$JAVA_HOME/bin:$HBASE_HOME/bin:$HIVE_HOME/bin:$PATH

第四步,下載並設定好jdbc connector
我這裡使用了最新的mysql-connector-java-5.1.40.tar.gz
記住,將解壓出來的jar放入hive 的lib中

cp mysql-connector-java-5.1.36-bin.jar $HIVE_HOME/lib/ 

第五步,配置hive-site.xml檔案
檔案來源於hive-default.xml.template

cp hive-default.xml.template hive-site.xml

然後找到

<name>javax.jdo.option.ConnectionURL
</name>

修改其value

     <value>jdbc:mysql://139.196.xxx.xxx:3306/hive?characterEncoding=UTF8&amp;useSSL=false&amp;createDatabaseIfNotExist=true</value>

同時,注意修改對應資料庫的賬號密碼,否則會在執行hive時出錯

    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>root</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>123456</value>
    </property>

第六步 執行hive客戶端

cd /home/hive/bin
hive

第七步,初始化DB
schematool -initSchema -dbType mysql

第八步,檢視成功後的元資料
可以看到對應資料庫hive中,有了各種初始的表

第九步,啟動master,node節點

啟動單機
hive
啟動叢集
hive -hiveconf hbase.zookeeper.quorum=slave1,slave2,slave3

————————————————————————————————————————————
以下是可能出現的錯誤:
一,如果執行hive時候出現報出賬號密碼的錯誤
那麼記得修改hive-site.xml中賬號密碼,參考第五步中的內容。
二,如果出現db沒有初始化,如

Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql))

這種錯誤的時候,請先執行初始化DB。
三,如果提示
SSL相關的內容,請在配置jdbc連結的時候設定ssl為false
jdbc:mysql://139.196.xxx.xxx:3306/hive?useSSL=false&createDatabaseIfNotExist=true

Wed Nov 30 14:24:50 CST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Wed Nov 30 14:24:55 CST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

四,遇到hive出錯的時候

[Fatal Error] hive-site.xml:26:5: The element type "value" must be terminated by the matching end-tag "</value>".
Exception in thread "main" java.lang.RuntimeException: org.xml.sax.SAXParseException; systemId: file:/home/hive/conf/hive-site.xml; lineNumber: 26; columnNumber: 5; The element type "value" must be terminated by the matching end-tag "</value>".
Logging initialized using configuration in jar:file:/home/hive/lib/hive-common-2.1.0.jar!/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D

這裡就是配置檔案Hive-site.xml中,修改system:java.io.tmpdir,指定一個系統存在的目錄即可。

這裡追加兩種啟動方式,方便各位用來進行hive測試。

hive提供了四種執行hive的方式,分別是:

**Hive CLI
HiveServer2 和 Beeline**
HCatalog
WebHCat (Templeton)

這裡主要介紹前兩種
第一種,hive CLI

因為hive的bin目錄已經添加了path變數, 因此, 可以直接使用hive命令啟動:
hive
輸入完命令後可以,直接可以進行hive操作。

第二種HiveServer2 和 Beeline

beeline提供多使用者, 更加安全的服務, 因此beeline用得比較多.
hiveserver2啟動時預設的地址是”localhost:10000”, 因此, 在使用beeline連線的時候, 需要使用” jdbc:hive2://localhost:10000”作為引數.
相關的命令如下:

hiveserver2
beeline -u jdbc:hive2://localhost:10000

同時也可以將 Beeline和HiveServer2在同一個程序裡啟動, 用於測試:
beeline -u jdbc:hive2://
但是,這裡如果用到自定義賬號密碼,必須在配置檔案hive-site.xml中進行相關配置。
上文第五步已經進行了相關介紹,可以參照。