1.前提hdfs環境搭建完畢 (本文參考:https://blog.51cto.com/caiyuanji/2131255 非原創 感謝此作者讓我部署學習了hive)
2.下載hive
apache-hive-2.3.6-bin.tar.gz http://mirror.bit.edu.cn/apache/hive/
3.安裝數據庫 我這是mysql5.6
create database hive character set utf8; grant all on hive.* to 'hive'@'%' identified by 'hive'; flush privileges;
3.解壓
tar xf apache-hive-2.3.6-bin.tar.gz /home/nflow/servers mv /home/nflow/servers/apache-hive-2.3.6-bin /home/nflow/servers/hive
4.修改hive的配置文件
cd /home/nflow/servers/hive/conf cp hive-env.sh.template hive-env.sh cp hive-default.xml.template hive-site.xml
5.修改hive-env.sh(最後添加三行)
##hadoop的home HADOOP_HOME=/home/nflow/servers/hadoop #hive的home export HIVE_CONF_DIR=/home/nflow/servers/hive/conf export HIVE_AUX_JARS_PATH=/home/nflow/servers/hive/lib
6.在hdfs上面創建hive的存儲目錄
cd /home/nflow/server/hdfs/bin ./hdfs dfs -mkdir -p /user/hive/warehouse ./hdfs dfs -mkdir -p /user/hive/tmp ./hdfs dfs -mkdir -p /user/hive/log ./hdfs dfs -chmod -R 777 /user/hive/warehouse ./hdfs dfs -chmod -R 777 /user/hive/tmp ./hdfs dfs -chmod -R 777 /user/hive/log
7.hive加載mysql驅動
cp /tmp/mysql-connector-java-5.1.26-bin.jar /home/nflow/servers/hive/lib/
8.修改hive-site.xml
8.1在HDFS上創建hive所用目錄
<property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> <description>location of default database for the warehouse</description> </property>
8.2搜索hive.exec.scratchdir,將該name對應的value修改爲/user/hive/tmp
<property> <name>hive.exec.scratchdir</name> <value>/user/hive/tmp</value> </property>
8.3搜索hive.querylog.location,將該name對應的value修改爲/user/hive/log/hadoop
<property> <name>hive.querylog.location</name> <value>/user/hive/log/hadoop</value> <description>Location of Hive run time structured log file</description> </property>
8.4搜索javax.jdo.option.connectionURL,將該name對應的value修改爲MySQL的地址
如果此處報錯改爲(
(jdbc:mysql://oversea-stable:3306/hive?createDatabaseIfNotExist=true)
<property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.249.10:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8&useSSL=false</value> <description> JDBC connect string for a JDBC metastore. To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL. For example, jdbc:postgresql://myhost/db?ssl=true for postgres database. </description> </property>
8.5搜索javax.jdo.option.ConnectionDriverName,將該name對應的value修改爲MySQL驅動類路徑
<property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> <description>Driver class name for a JDBC metastore</description> </property>
8.6搜索javax.jdo.option.ConnectionUserName,將對應的value修改爲MySQL數據庫登錄名
<property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> <description>Username to use against metastore database</description> </property>
8.7搜索javax.jdo.option.ConnectionPassword,將對應的value修改爲MySQL數據庫的登錄密碼
<property> <name>javax.jdo.option.ConnectionPassword</name> <value>hive</value> <description>password to use against metastore database</description> </property>
8.8指定hive 運行的tmp目錄(一定要改否則會報錯)
su - nflow mkdir /home/nflow/servers/hive/tmp 並把hive-site.xml 中修改把 ${system:java.io.tmpdir} 改成 /home/nflow/servers/hive/tmp 把 {system:user.name} 改成 {user.name}
9.hive數據初始化
bin/schematool -initSchema -dbType mysql
10. 測試
cd /hom/nflow/servers/hive/bin
hive
create database inspiry; create table test (mykey string,myval string); insert into test values("1","test") select * from test;