1、下载Hive2.3.0
wget http://mirror.bit.edu.cn/apache/hive/hive-2.3.0/apache-hive-2.3.0-bin.tar.gz
2、解压到指定安装目录
tar -zxvf apache-hive-2.3.0-bin.tar.gzmv apache-hive-2.3.0-bin /usr/local/hivecd /usr/local/hive
3、配置/etc/profile,在/etc/profile中添加如下语句
export HIVE_HOME=/usr/local/hiveexport PATH=$HIVE_HOME/bin:$PATH
使之生效
source /etc/profile
4、安装MySQL数据库
参考
5、创建metastore数据库并为其授权
create database metastore;grant all on metastore.* to hive@'%' identified by 'hive';grant all on metastore.* to hive@'localhost' identified by 'hive';flush privileges;
6、 下载jdbc connector
下载地址
下载完成之后将其拷贝至$HIVE_HOME/lib目录下
mv mysql-connector-java-5.1.43.tar.gz $HIVE_HOME/lib
7、修改hive配置文件
cd /usr/local/hive/conf
7.1复制初始化文件并重改名
cp hive-env.sh.template hive-env.shcp hive-default.xml.template hive-site.xmlcp hive-log4j2.properties.template hive-log4j2.propertiescp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
7.2修改hive-env.sh
export JAVA_HOME=/usr/local/jdk1.7.0_80 ##Java路径export HADOOP_HOME=/usr/local/hadoop ##Hadoop安装路径export HIVE_HOME=/usr/local/hive ##Hive安装路径export HIVE_CONF_DIR=/usr/local/hive/conf ##Hive配置文件路径
7.3在hdfs 中创建下面的目录 ,并且授权
hdfs dfs -mkdir -p /user/hive/warehousehdfs dfs -mkdir -p /user/hive/tmphdfs dfs -mkdir -p /user/hive/loghdfs dfs -chmod -R 777 /user/hive/warehousehdfs dfs -chmod -R 777 /user/hive/tmphdfs dfs -chmod -R 777 /user/hive/log
7.4修改hive-site.xml
hive.exec.scratchdir /user/hive/tmp hive.metastore.warehouse.dir /user/hive/warehouse ## 配置 MySQL 数据库连接信息 hive.querylog.location /user/hive/log javax.jdo.option.ConnectionURL jdbc:mysql://localhost:3306/metastore?createDatabaseIfNotExist=true&characterEncoding=UTF-8&useSSL=false javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver javax.jdo.option.ConnectionUserName hive javax.jdo.option.ConnectionPassword hive
7.5 创建tmp文件
mkdir /home/hadoop/hive-2.1.1/tmp
并在hive-site.xml中修改:
把{system:java.io.tmpdir} 改成 /home/hadoop/hive-2.1.1/tmp/把 {system:user.name} 改成 {user.name}
8、初始化hive
schematool -dbType mysql -initSchema hive hive
9、启动hive
下面介绍有两种启动方式:
9.1 hive CLIhive
9.2 beeline
9.2.1 启动hiveserver2
nohup hiveserver2 &
9.2.2 查看hiveserver2启动状态
netstat -nptl | grep 10000
9.2.3 启动beeline
beeline
9.2.4连接hive
!connect jdbc:hive2://localhost:10000 hive hive
9.2.5 查看数据库
show databases;
10、安装时遇到的问题
10.1 在对数据库表进行查询、插入操作时出现下列异常:
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
原因:客户端内存不够。
解决方法:适当增加内存 在hadoop-env.sh中修改属性HADOOP_CLIENT_OPTS的值,默认值为1024MB,可以根据实际内存大小对其进行修改,我的内存为8G,所以我将其修改为4096MBexport HADOOP_HEAPSIZE=4096
10.2Error: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000: java.net.ConnectException: Connection refused (state=08S01,code=0)
原因:hiveserver2没有启动
解决方案:启动hiveserver2nohup hiveserver2 &