准备环境
创建用户
useradd hive -g hadoop
环境变量
export HDFS_NAMENODE_USER="hdfs"
export HDFS_DATANODE_USER="hdfs"
export HDFS_SECONDARYNAMENODE_USER="hdfs"
export YARN_RESOURCEMANAGER_USER="yarn"
export YARN_NODEMANAGER_USER="yarn"
export HADOOP_CONF_DIR=/data/hadoop-install/etc/hadoop
export JAVA_HOME=/usr/java/jdk1.8.0_45
export HBASE_HOME=/usr/local/hbase/
export HADOOP_HOME=/data/hadoop-install
export HIVE_HOME=/data/hive-install
export PATH=$PATH:$JAVA_HOME/bin
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export PATH=$PATH:$HIVE_HOME/bin
安装与配置
安装Hive-Server2
修改hive-site.xml
vim hive-site.xml
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://mysqlip:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>
<property>
<name>hive.server2.enable.doAs</name>
<value>false</value>
</property>
</configuration>
javax.jdo.option 配置元数据数据库连接信息 hive.server2.enable.doAs 需要设置为false
初始化
需要把mysql-connector-java-x.y.z.jar包放入$HIVE_HOME/lib/目录中
cp /tmp/mysql-connector-java-5.1.26.jar $HIVE_HOME/lib/
$HIVE_HOME/bin/schematool -dbType mysql -initSchema
正确结果返回如下
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Initialization script completed
schemaTool completed
启动
$HIVE_HOME/bin/hive --service hiveserver2
调用
$HIVE_HOME/bin/beeline -u jdbc:hive2://$HS2_HOST:$HS2_PORT