- 安装hive
基于hadoop-2.5.2完全分布式集群,兼容hive-1.2.2版本
https://www.jianshu.com/p/8a6a9a4fec4a
下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/hive/
解压到自己管理方便的目录下:
[root@master bigdatazips]# tar -zxvf apache-hive-1.2.2-bin.tar.gz -C /root/bigdata/
重命名
[root@master bigdata]# mv apache-hive-1.2.2-bin/ hive
配置环境变量,输入命令:
[root@master bigdata]# vim /etc/profile
在文件中输入:
export HIVE_HOME=/root/bigdata/hive
export HIVE_CONF_DIR=${HIVE_HOME}/conf
export PATH=$PATH:$HIVE_HOME/bin
路径按自己配置的目录来
输入命令:
[root@master bigdata]# source /etc/profile
使配置文件立刻生效
验证
[root@master ~]# hive --version
Hive 1.2.2
Subversion git://vgumashta.local/Users/vgumashta/Documents/workspace/hive-git -r 395368fc6478c7e2a1e84a5a2a8aac45e4399a9e
Compiled by vgumashta on Sun Apr 2 13:12:26 PDT 2017
From source with checksum bd47834e727562aab36c8282f8161030
centos7系统安装mysql8数据库
https://www.jianshu.com/p/8461a2fb9b44配置hive
[root@master ~]# cd /root/bigdata/hive
[root@master hive]# ls
bin examples lib NOTICE RELEASE_NOTES.txt
conf hcatalog LICENSE README.txt scripts
[root@master hive]# cd conf
[root@master conf]# ls
beeline-log4j.properties.template hive-exec-log4j.properties.template
hive-default.xml.template hive-log4j.properties.template
hive-env.sh hive-site.xml
hive-env.sh.template ivysettings.xml
[root@master conf]# cp hive-env.sh.template hive-env.sh
配置hive-env.sh,hadoop安装目录,hive配置文件目录
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/root/bigdata/hadoop
# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/root/bigdata/hive/conf
配置hive-site.xml
vim hive-site.xml
打开一个空文件,在其中输入如下内容
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/创建的数据库?createDatabaseIfNotExsit=true;chara
cterEncoding=UTF-8</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>数据库用户名</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>数据库密码</value>
</property>
<property>
<name>datanucleus.readOnlyDatastore</name>
<value>false</value>
</property>
<property>
<name>datanucleus.fixedDatastore</name>
<value>false</value>
</property>
<property>
<name>datanucleus.autoCreateSchema</name>
<value>true</value>
</property>
<property>
<name>datanucleus.autoCreateTables</name>
<value>true</value>
</property>
<property>
<name>datanucleus.autoCreateColumns</name>
<value>true</value>
</property>
</configuration>
上边配置的是hive连接mysql数据库的信息
- hive添加jdbc驱动
下载:
https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.48.tar.gz
[root@master 下载]# tar -zxvf mysql-connector-java-5.1.48.tar.gz
[root@master mysql-connector-java-5.1.48]# cp mysql-connector-java-5.1.48-bin.jar /root/bigdata/hive/lib
[root@master mysql-connector-java-5.1.48]# cp mysql-connector-java-5.1.48.jar /root/bigdata/hive/lib
- 启动hive
通过后台启动 metastore 和 hiveserver 实现服务,命令:
$ hive --service metastore &
$ hive --service hiveserver2&
启动用通过 jps 命令可以看到两个服务在后台运行
[root@master conf]# jps
10529 SecondaryNameNode
10341 DataNode
16917 Jps
7257 Master
15353 RunJar
10189 NameNode
15151 RunJar
可能会保错
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
原因是hadoop目录下存在老版本jline
解决:
将hive下的新版本jline的JAR包拷贝到hadoop下:
[root@master lib]# cp ./jline-2.12.jar /root/bigdata/hadoop/share/hadoop/yarn/lib
[root@master lib]# cd /root/bigdata/hadoop/share/hadoop/yarn/lib/
[root@master lib]# rm -f jline-0.9.94.jar
hive cli启动成功:
[root@master ~]# hive
- 测试使用
hive> create database hive;
OK
Time taken: 0.526 seconds
hive> show databases;
OK
default
hive
Time taken: 0.094 seconds, Fetched: 2 row(s)
hive> use hive;
OK
Time taken: 0.014 seconds
hive> show tables;
OK
Time taken: 0.017 seconds
hive>