Hadoop——hive安装
安装前先确保安装好MySQL,具体见hadoop_MySQL安装
1.下载hive(下载前先去spark官网看下sparkSQL支持到哪个版本的hive,本文hive版本为1.2.1)
2.解压到/usr/local/hive
tar -zxvf aoacge-hive-1.2.1-bin -C /usr/local/hive
3.配置/etc/profile
1 #HIVE_HOME 2 export HIVE_HOME=/usr/local/hive/apache-hive-1.2.1-bin 3 export HIVE_CONF_DIR=$HIVE_HOME/conf 4 export PATH=$PATH:$HIVE_HOME/bin
4.进入conf,修改mv hive-env.sh.template hive-env.sh
vim hive-env.sh
添加
1 export HADOOP_HOME=/usr/local/hadoop/hadoop-2.6.5 2 export HIVE_HOME=/usr/local/hive/apache-hive-1.2.1-bin 3 export HIVE_CONF_DIR=$HIVE_HOME/conf
5.进入conf ,添加hive-site.xml文件,原先没有这个文件
echo > hive-site.xml
vim hive-site.xml
添加
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 3 <configuration> 4 <property> 5 <name>javax.jdo.option.ConnectionURL</name> 6 <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value> 7 <description>JDBC connect string for a JDBC metastore</description> 8 </property> 9 <property> 10 <name>javax.jdo.option.ConnectionDriverName</name> 11 <value>com.mysql.jdbc.Driver</value> 12 <description>Driver class name for a JDBC metastore</description> 13 </property> 14 <property> 15 <name>javax.jdo.option.ConnectionUserName</name> 16 <value>root</value> 17 <description>username to use against metastore database</description> 18 </property> 19 <property> 20 <name>javax.jdo.option.ConnectionPassword</name> 21 <value>******</value> 22 <description>password to use against metastore database</description> 23 </property> 24 <property> 25 <name>hive.metastore.warehouse.dir</name> 26 <value>/user/hive/warehouse</value> 27 <description>default warehouse for metastore database</description> 28 </property> 29 </configuration>
其中的用户名和密码自行修改
6.下载mysql jdbc 包,下载地址:mysql-connector-java-x.x.x-bin.jar
tar -zxvf mysql-connector-java-5.1.40.tar.gz //解压
cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar /usr/local/hive/apache-hive-1.2.1-bin/lib
//将mysql-connector-java-5.1.40-bin.jar拷贝到/usr/local/hive/lib目录下
7.进入hive/bin,修改hive-config.sh
添加
1 export JAVA_HOME=/usr/local/jdk/jdk1.8.0_121 2 export HADOOP_HOME=/usr/local/hadoop/hadoop-2.6.5 3 export SPARK_HOME=/usr/local/spark/spark-2.1.0-bin-hadoop2.6
8.hadoop的版本是2.6.5,hive的版本是1.2.1,$HIVE_HOME/lib目录下的jline-2.12.jar比$HADOOP_HOME/share/hadoop/yarn/lib下的jline-0.9.94.jar版本高,
版本不一致导致。 拷贝hive中的jline-2.12.jar到$HADOOP_HOME/share/hadoop/yarn/lib下,并重启hadoop即可。
9.启动hive
首先要启动hadoop集群,并且保证mysql已经启动。
命令行直接输入hive
10. 在HDFS上创建文件夹
hadoop/bin 目录下
./hadoop fs -mkdir -p /user/hive/warehouse
11. 测试
在hive命令行下创建数据库和表(database为数据库,student为表)