Hive下載
hive下載地址:http://mirror.bit.edu.cn/apache/hive/
解壓到/usr/local:tar -zxvf apache-hive-2.1.1-bin.tar.gz -C /usr/local/
重命名:mv apache-hive-2.3.4-bin/ hive-2.3.4
修改環境變量並保存
/etc/profile:vim /etc/profile
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HIVE_HOME/bin
修改完後執行 source /etc/profile
執行 hive --version
第一個坑
Caused by: java.net.NoRouteToHostException: No Route to Host from docker-hadoop/127.0.0.1 to docker-hadoop:9000 failed on socket timeout exception: java.net.NoRouteToHostException: No route to host;
解決方案:
關閉防火牆,
centos:
查看狀態 firewall-cmd --state
關閉防火牆:systemctl stop firewalld.service
至此安裝成功,接着配置hive-site.xml:
$ cd /usr/local/hive/conf
$ cp hive-default.xml.template hive-site.xml
在hive-site.xml文件開始的地方,添加mysql配置(後面有坑):
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><configuration>
<!-- WARNING!!! This file is auto generated for documentation purposes ONLY! -->
<!-- WARNING!!! Any changes you make to this file will be ignored by Hive. -->
<!-- WARNING!!! You must make your changes in hive-site.xml instead. -->
<!-- Hive Execution Parameters -->
<!-- 插入一下代碼 -->
<property>
<name>javax.jdo.option.ConnectionUserName</name>用戶名(這4是新添加的,記住刪除配置文件原有的哦!)
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>密碼
<value>123456</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>mysql
<value>jdbc:mysql://192.168.1.68:3306/hive</value> 需要提前在mysql創建好hive數據庫
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>mysql驅動程序
<value>com.mysql.jdbc.Driver</value>
</property>
<!-- 到此結束代碼 -->
<property>
<name>hive.exec.script.wrapper</name>
<value/>
<description/>
</property>
下載mysql connector驅動:https://dev.mysql.com/downloads/file/?id=480091
複製mysql的驅動程序到hive/lib下面
執行hive
$ hive
第二個坑
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
解決方案(會造成後面的坑):
<name>hive.exec.scratchdir</name>
<value>${user.name}</value>
<name>hive.exec.local.scratchdir</name>
<value>${user.name}</value>
<name>hive.downloaded.resources.dir</name>
<value>${user.name}/${hive.session.id}_resources</value>
再次執行hive:
$ hive
在hive命令行執行:show databases;
第三個坑
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
解決方案:
初始化hive的元數據
執行:schematool -dbType mysql -initSchema
第四個坑
Error: Syntax error: Encountered "<EOF>" at line 1, column 64. (state=42X01,code=30000)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
Underlying cause: java.io.IOException : Schema script failed, errorcode 2
Use --verbose for detailed stacktrace.
*** schemaTool failed ***
解決方案:
網上教程都是說在文件頭部加上mysql的連接配置,但是hive-site.xml.templat中原本是有derby的配置,這樣就會被下面的derby配置覆蓋,導致初始化失敗。方法就是可以將mysql配置放在最下面,或者刪除derby的配置
所以將hive-site.xml之前添加的mysql的配置放至文件末尾。
再次執行:show databases;
第五個坑
FAILED: IllegalArgumentException java.net.URISyntaxException: Relative path in absolute URI: file:./root/870a3f68-9c00-4b07-b4fb-11db0fa11955/hive_2018-11-22_15-45-30_756_1321308792612480424-1
解決方案:
修改hive-site.xml配置文件:
<name>hive.exec.scratchdir</name>
<value>/tmp/hive</value>
<name>hive.exec.local.scratchdir</name>
<value>/tmp/hive</value>
<name>hive.downloaded.resources.dir</name>
<value>/tmp/hive/${hive.session.id}_resources</value>
再次執行:show databases;
在mysql客戶端查看hive初始化的元數據表:
至此,告一段落。。。。。