namenode: 192.168.0.160
datanode: 192.168.0.160,192.168.0.161
mysql-server: 192.168.0.170
hadoop版本: 2.6.5
hive版本:1.2.2
mysql版本:5.7
主机操作系统:ubuntu-16.04-x64
在安装hive前,需要了解hive部署的三种模式:
本文讲解第三种部署方式,数据库采用mysql。
hive是基于hadoop来进行数据分析,因此需要先安装hadoop,可以参考
https://blog.csdn.net/cl2010abc/article/details/80533789
sudo apt-get install mysql-server
sudo apt install mysql-client
sudo apt install libmysqlclient-dev
现在设置mysql允许远程访问
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address = 127.0.0.1中的ip部分修改为0.0.0.0。
bind-address = 0.0.0.0
重启mysql服务
sudo service mysql restart
查看mysql服务的运行状态
sudo netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN #mysql进程
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
下载hive,点击这里。
将下载后的二进制包上传到namenode上,并解压。
tar xf apache-hive-1.2.2-bin.tar.gz
mv apache-hive-1.2.2-bin hive
修改配置文件conf/hive-env.sh
cp conf/hive-env.sh.template conf/hive-env.sh
vim conf/hive-env.sh
#修改内容
HADOOP_HOME=/home/hadoop/software/hadoop-2.6.5
修改配置文件conf/hive-site.conf
cp conf/hive-default.xml.template conf/hive-site.xml
vim conf/hive-site.xml
#数据库URL
javax.jdo.option.ConnectionURL
jdbc:mysql://192.168.0.170:3306/hive?createDatabaseIfNoExist=true&characterEncoding=utf8&useSSL=true&useUnicode=true&serverTimezone=UTC
JDBC connect string for a JDBC metastore
#下面两项必须配置,不然启动会报错
system:user.name
hadoop
system:java.io.tmpdir
/home/hadoop/software/hive/tmp
#数据库用户名
javax.jdo.option.ConnectionUserName
root
Username to use against metastore database
#数据库连接驱动
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
#数据库连接密码
javax.jdo.option.ConnectionPassword
123456
password to use against metastore database
下载mysql jdbc驱动包,点击这里,并将驱动包拷贝到hive安装包lib路径下。
tar xf mysql-connector-java-5.1.46.tar.gz
cp mysql-connector-java-5.1.46/mysql-connector-java-5.1.46.jar lib/
# mysql server版本为5.7.x时,mysql-connector的版本选择5.x,否则可能出现不可预知错误。
启动hadoop
./sbin/start-all.sh
初始化hive
./bin/schematool -dbType mysql -initSchema
Metastore connection URL: jdbc:mysql://192.168.0.170:3306/hive?createDatabaseIfNoExist=true&characterEncoding=utf8&useSSL=true&useUnicode=true&serverTimezone=UTC
Metastore Connection Driver : com.mysql.cj.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 1.2.0
Initialization script hive-schema-1.2.0.mysql.sql
Initialization script completed
schemaTool completed
启动hive
./bin/hive
Logging initialized using configuration in jar:file:/home/hadoop/software/hive/lib/hive-common-1.2.2.jar!/hive-log4j.properties
hive> show databases;
OK
default
Time taken: 0.021 seconds, Fetched: 1 row(s)
hive>
至此hive安装完毕。