Centos 安裝 hive && 踩坑排錯集錦 AWS aliyun都適應

前些日子 在自己mac 和公司 mac book 安裝 hive 也是感覺 吐血才安裝好了一半 ,默默的心疼自己兩秒鐘。由于上周 公司 數據和算法小組要求 使用hive ,所以這周第一天就開始了 hive 安裝 踩坑 實況。

首先是 直接 登錄 服務器,進入 /usr/local/ 目錄
直接 wget hive 的 壓縮包
wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.0/apache-hive-2.3.0-bin.tar.gz

之后解壓 到 此目錄
tar -zxvf apache-hive-2.3.0-bin.tar.gz -C /usr/local/
重命名
`
mv apache-hive-2.3.0-bin hive

進入 hive/lib/目錄,將 [mysql-connector-java-5.1.36.jar] 放入此目錄
wget http://124.202.164.13/files/516600000AA33837/repo.maven.apache.org/maven2/mysql/mysql-connector-java/5.1.36/mysql-connector-java-5.1.36.jar
進入 hive/conf/ 目錄
cp hive-default.xml.template hive-site.xml
cp hive-env.sh.template hive-env.sh
cp hive-log4j2.properties.template hive-log4j2.properties
cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties

注意 hive 只認 hive-site.xml,如果是 hive-default.xml 會報 各種錯
Hive 2.1.1 MetaException(message:Version information not found in metastore. )
`
在 hive-env.sh配置
JAVA_HOME
HADOOP_HOME

并把 hive 加入到環(huán)境變量
echo export HIVE_HOME=/usr/local/hive >>/etc/profile
echo export PATH=$PATH:$HIVE_HOME/bin >>/etc/profile

前提需要把 mysql 在服務器 上安裝好,并啟動,

之后 修改 /hive/conf/hive-site.xml 中的幾個熟悉,找到這幾個屬性 ,并把相對路徑改為 絕對路徑,并把該創(chuàng)建的文件夾創(chuàng)建了,并賦予權限。
`
<property>
<name>hive.querylog.location</name>
<value>/usr/local/hive/iotmp</value>
<description>Location of Hive run time structured log file</description>
</property>

<property>
<name>hive.exec.local.scratchdir</name>
<value>/usr/local/hive/iotmp</value>
<description>Local scratch space for Hive jobs</description>
</property>

<property>
<name>hive.downloaded.resources.dir</name>
<value>/usr/local/hive/iotmp</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>

mkdir /usr/local/hive/iotmp/
chown -R hadoop:hadoop /usr/local/hive/iotmp/
如果不把這幾個相對路徑修改為 絕對路徑,則報
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
在root 用戶 手動創(chuàng)建 /usr/local/hive/iotmp/ 目錄并賦予hadoop用戶權限,否則會失敗。
Exception in thread "main" java.lang.RuntimeException: Couldn't create directory /usr/local/hive/iotmp
`

還有幾個屬性 需要修改值
比如 mysql 的連接信息
`

jdbc連接方式

<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>

mysql連接配置

<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://172.16.7.191:3306/hive?createDatabaseIfNotExist=true</value>

mysql數據庫的用戶名

<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>

用戶對應的密碼

<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>

`

hive 部署需要注意的幾點以及Version information not found 錯誤解決辦法
安裝HIVE 過程中要注意

1,mysql 是否正常運行

  1. 創(chuàng)建好mysql 用戶并分配好相應的訪問權限以及數據庫端口號等

  2. mysql-connector-java-5.1.26-bin.jar 是否放到hive/lib 目錄下 建議修改權限為777 (chmod 777 mysql-connector-java-5.1.26-bin.jar)

  3. 修改conf/hive-site.xml 中的 “hive.metastore.schema.verification” 值為 false 即可解決 “Caused by: MetaException(message:Version information not found in metastore. )”

  4. 調試 模式命令 hive -hiveconf hive.root.logger=DEBUG,console

還有三個屬性在 hive-site.xml中
`

datanucleus.schema.autoCreateAll=true
或 datanucleus.autoCreateSchema=true

datanucleus.metadata.validate=false

hive.metastore.schema.verification=false
`
<property>
<name>datanucleus.schema.autoCreateAll</name>
<value>true</value>
<description>Auto creates necessary schema on a startup if one doesn't exist. Set this to false, after creating it once.To enable auto create also set hive.metastore.schema.verification=false. Auto creation is not recommended for production use cases, run schematool command instead.</description>
</property>

為 mysql 創(chuàng)建新的用戶 比如 dev
進入 mysql交互模式
創(chuàng)建數據庫 然后創(chuàng)建用戶 給特定的數據庫 賦予權限

create database hive default character set latin1;
grant select,insert,update,delete,create,drop ,index alter on hive.* to dev@localhost identified by 'DmE_34dev'; # 有時候 會丟掉 index 和alter 這兩個,然后就報index 和alter 的權限不足
也可以這樣
GRANT ALL PRIVILEGES ON . TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

這個localhost 建議 寫你的hive 的內網ip ,直接使用localhost 有時候會報錯,比如用
192.168.255.155,或者直接使用 % ,不然 外網無法登錄訪問

FLUSH PRIVILEGES; #一定要刷新權限
參看 http://www.cnblogs.com/shyy/archive/2012/03/30/2453034.html
2017-11-01T19:49:05,404 ERROR [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Metastore Thrift Server threw an exception...
org.apache.hadoop.hive.metastore.api.MetaException: Unable to open a test connection to the given database. JDBC url = jdbc:mysql://192.168.255.155:3306/hive?createDatabaseIfNotExist=true, username = linkdev. Terminating connection pool (set lazyInit to true if you expect to start your database after your app). Original Exception: ------
java.sql.SQLException: Access denied for user 'linkdev'@'linkhadoop-master' (using password: YES)

Caused by: org.datanucleus.store.rdbms.exceptions.MissingTableException: Required table missing : "DBS" in Catalog "" Schema "". DataNucleus requires this table to perform its persistence operations. Either your MetaData is incorrect, or you need to enable "datanucleus.schema.autoCreateTables"

WARN [main] org.apache.hadoop.hive.metastore.HiveMetaStore - Retrying creating default database after error: Error(s) were found while auto-creating/validating the datastore for classes. The errors are printed in the log, and are attached to this exception.
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: INDEX command denied to user 'linkdev'@'linkhadoop-master' for table 'DBS'
at sun.reflect.GeneratedConstructorAccessor23.newInstance(Unknown Source)

之后在 mysql 正在運行的基礎上
1.啟動Hive 的 Metastore Server服務進程
hive --service metastore &
如果沒有報錯,就接著往下走,

2 hive第一次登錄需要初始化,主要是 在 mysql 的hive庫中創(chuàng)建
hive 相關的 表,
schematool -dbType mysql -initSchema
該初始化 等同于在 進行一下操作
`
cd $HIVE_HOME/scripts/metastore/upgrade/mysql/
< Login into MySQL >

mysql> drop database IF EXISTS hive;
mysql> create database hive;
mysql> use hive;
mysql> source hive-schema-2.3.0.mysql.sql;
只能有一次操作,否則會報錯,
Error: Duplicate key name'PCS_STATS_IDX' (state=42000,code=1061)

Initialization script hive-schema-2.3.0.mysql.sql Error: Duplicate key
`

3.登錄hive
/usr/local/hive/bin/hive
不報錯 說明基本可以使用了,主要要用 hadoop 用戶啟動hive,用root用戶會報錯
Caused by: org.apache.hadoop.security.AccessControlException: Permission denied: user=root, access=WRITE, inode="/user":hdfs:supergroup:drwxr-xr-x

參考 博文
http://blog.csdn.net/seashouwang/article/details/77867134
http://www.itdecent.cn/p/978a77a1d6a2
http://www.itdecent.cn/p/921e7607fb56
http://www.itdecent.cn/p/776802db315e

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容