Hive-1.2.1安装配置

相关软件下载

hadoop2.7.2集群配置参考:从零开始搭建Hadoop-2.7.2完全分布式部署

安装mysql

这里用mysql做元数据库

# 安装简单粗暴yum
yum install mysql mysql-server  

创建对应数据库和用户

create database metastore_db;  
grant all on metastore_db.* to hive@'fy.hdp.master.loadata.com' identified by '123456';  
flush privileges  

解压到安装目录

#解压到对应目录
tar xvzf apache-hive-1.2.1-bin.tar.gz -C /usr/local  
#授权用户组
chown hadoop.hadoop /usr/local/apache-hive-1.2.1-bin -R  

添加环境变量

vim ~/.bashrc  
#添加如下内容
export JAVA_HOME=/usr/local/jdk/jdk1.7.0_79  
export HIVE_HOME=/usr/local/apache-hive-1.2.1-bin  
#使生效
source ~/.bashrc  

修改hive-env.sh

#修改这两个配置
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/usr/local/hadoop-2.7.2

# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/usr/local/apache-hive-1.2.1-bin/conf  

修改hive-site.xml

<!-- 修改下面配置 -->  
  <property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>hive</value>
    <description>Username to use against metastore database</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>123456</value>
    <description>password to use against metastore database</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    <description>Driver class name for a JDBC metastore</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://fy.hdp.master.loadata.com:3306/metastore_db?characterEncoding=UTF-8</value>
    <description>JDBC connect string for a JDBC metastore</description>
  </property>
  <property>
    <name>hive.exec.scratchdir</name>
    <value>hdfs://fy.hdp.master.loadata.com:9000/hive/warehouse</value>
    <description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/&lt;username&gt; is created, with ${hive.scratch.dir.permission}.</description>
  </property>
  <property>
    <name>hive.exec.local.scratchdir</name>
    <value>/data/hive/iotmp</value>
    <description>Local scratch space for Hive jobs</description>
  </property>
  <property>
    <name>hive.downloaded.resources.dir</name>
    <value>/data/hive/iotmp/${hive.session.id}_resources</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
  </property>
  <property>
    <name>hive.querylog.location</name>
    <value>/data/hive/hadoop</value>
    <description>Location of Hive run time structured log file</description>
  </property>
  <property>
    <name>hive.server2.logging.operation.log.location</name>
    <value>/data/hive/hadoop/operation_logs</value>
    <description>Top level directory where operation logs are stored if logging functionality is enabled</description>
  </property>

初始化元数据库

cd /usr/local/apache-hive-1.2.1-bin  
bin/schematool -dbType mysql -initSchema  

启动hiveserver2

nohup bin/hive --service metastore &  
nohup bin/hive --service hiveserver2 &  
#nohup bin/hive --service hwi &

测试

[hadoop@fy.hdp.master.loadata.com apache-hive-1.2.1-bin]$ bin/beeline 
Beeline version 1.2.1 by Apache Hive  
beeline> !connect jdbc:hive2://fy.hdp.master.loadata.com:10000  
Connecting to jdbc:hive2://fy.hdp.master.loadata.com:10000  
Enter username for jdbc:hive2://fy.hdp.master.loadata.com:10000:  
Enter password for jdbc:hive2://fy.hdp.master.loadata.com:10000:  
Connected to: Apache Hive (version 1.2.1)  
Driver: Hive JDBC (version 1.2.1)  
Transaction isolation: TRANSACTION_REPEATABLE_READ  
0: jdbc:hive2://fy.hdp.master.loadata.com:100> show databases;  
+----------------+--+
| database_name  |
+----------------+--+
| default        |
| demo           |
+----------------+--+
2 rows selected (1.561 seconds)  
0: jdbc:hive2://fy.hdp.master.loadata.com:100>