前些日子 在自己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 加入到环境变量
echo export HIVE_HOME=/usr/local/hive >>/etc/profile
echo export PATH=$PATH:$HIVE_HOME/bin >>/etc/profile
前提需要把 mysql 在服务器 上安装好,并启动,
之后 修改 /hive/conf/hive-site.xml 中的几个熟悉,找到这几个属性 ,并把相对路径改为 绝对路径,并把该创建的文件夹创建了,并赋予权限。
`
<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 用户 手动创建 /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 是否正常运行
创建好mysql 用户并分配好相应的访问权限以及数据库端口号等
mysql-connector-java-5.1.26-bin.jar 是否放到hive/lib 目录下 建议修改权限为777 (chmod 777 mysql-connector-java-5.1.26-bin.jar)
修改conf/hive-site.xml 中的 “hive.metastore.schema.verification” 值为 false 即可解决 “Caused by: MetaException(message:Version information not found in metastore. )”
调试 模式命令 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 创建新的用户 比如 dev
进入 mysql交互模式
创建数据库 然后创建用户 给特定的数据库 赋予权限
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库中创建
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
//www.greatytc.com/p/978a77a1d6a2
//www.greatytc.com/p/921e7607fb56
//www.greatytc.com/p/776802db315e