1 安装MySQL
以安装在master为例:
hadoop@master:~$ sudo apt-get install mysql-server mysql-client
设置root用户密码为123456
登陆MySQL创建Hive元数据库,并授权hive用户。
创建语句如下:
create database hivemeta;
alter database hivemeta character set latin1;
grant all privileges on *.* to hive@"master" identified by "123456" with grant option;
flush privileges;
MySQL安装在其他主机,创建语句如下:
create database hivemeta;
alter database hivemeta character set latin1;
grant all privileges on *.* to hive@"%" identified by "123456" with grant option;
flush privileges;
查看数据库及授权用户信息:
hadoop@master:~$ mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.62-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hivemeta |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.03 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user, password from user;
+-----------+------------------+-------------------------------------------+
| host | user | password |
+-----------+------------------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| master | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | debian-sys-maint | *54F95D9F05A61F97757EF9468057B658D8C5AB23 |
| % | hive | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| master | hive | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | hive | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------------------+-------------------------------------------+
8 rows in set (0.00 sec)
mysql>
如果后面步骤中Hive不能启动,则设置my.cnf
hadoop@master:~$ vi /etc/mysql/my.cnf
bind-address = 192.168.1.245 # 不能使用默认参数,修改为master的ip
2 安装Hive
下载hive:
hadoop@master:~$ wget https://archive.apache.org/dist/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz
安装hive:
hadoop@master:~$ tar zxvf apache-hive-1.2.1-bin.tar.gz -C bigdata/
hadoop@master:~$ cd bigdata/
hadoop@master:~/bigdata$ mv apache-hive-1.2.1-bin hive
环境变量:
hadoop@master:~/bigdata$ vi /home/hadoop/.bashrc
export HIVE_HOME=/home/hadoop/bigdata/hive
export PATH=$HIVE_HOME/bin:$PATH
使环境变量设置生效:
hadoop@master:~$ source /home/hadoop/.bashrc
验证:
hadoop@master:~$ env | grep HIVE
HIVE_HOME=/home/hadoop/bigdata/hive
修改配置参数文件:
hadoop@master:~$ cd /home/hadoop/bigdata/hive/conf/
hadoop@master:~/bigdata/hive/conf$ cp hive-default.xml.template hive-site.xml
hadoop@master:~/bigdata/hive/conf$ cp hive-env.sh.template hive-env.sh
hadoop@master:~/bigdata/hive/conf$ cp hive-log4j.properties.template hive-log4j.properties
hive-env.sh
hadoop@master:~/bigdata/hive/conf$ diff hive-env.sh.template hive-env.sh
54a55,57
>
> export HADOOP_HOME=/home/hadoop/bigdata/hadoop
> export HIVE_CONF_DIR=/home/hadoop/bigdata/hive/conf
hive-log4j.properties
hadoop@master:~/bigdata/hive/conf$ diff hive-log4j.properties.template hive-log4j.properties
20c20,21
< hive.log.dir=${java.io.tmpdir}/${user.name}
---
> # hive.log.dir=${java.io.tmpdir}/${user.name}
> hive.log.dir=/home/hadoop/bigdata/hive/log
hive-site.xml
hadoop@master:~/bigdata/hive/conf$ diff hive-default.xml.template hive-site.xml 47,48c47
< <value>/tmp/hive</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}/<username> is created, with ${hive.scratch.dir.permission}.</description>
---
> <value>hdfs://master:9000/hive/scratchdir</value>
52,53c51
< <value>${system:java.io.tmpdir}/${system:user.name}</value>
< <description>Local scratch space for Hive jobs</description>
---
> <value>/home/hadoop/bigdata/hive/iotmp</value>
57,58c55
< <value>${system:java.io.tmpdir}/${hive.session.id}_resources</value>
< <description>Temporary local directory for added resources in the remote file system.</description>
---
> <value>/home/hadoop/bigdata/hive/iotmp</value>
335,336c332
< <value>/user/hive/warehouse</value>
< <description>location of default database for the warehouse</description>
---
> <value>hdfs://master:9000/hive/warehouse</value>
340,341c336
< <value/>
< <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
---
> <value>thrift://master:9083</value>
381,382c376
< <value>mine</value>
< <description>password to use against metastore database</description>
---
> <value>123456</value>
396,397c390
< <value>jdbc:derby:;databaseName=metastore_db;create=true</value>
< <description>JDBC connect string for a JDBC metastore</description>
---
> <value>jdbc:mysql://master:3306/hivemeta?createDatabaseIfNotExist=true</value>
790,791c783
< <value>org.apache.derby.jdbc.EmbeddedDriver</value>
< <description>Driver class name for a JDBC metastore</description>
---
> <value>com.mysql.jdbc.Driver</value>
815,816c807
< <value>APP</value>
< <description>Username to use against metastore database</description>
---
> <value>hive</value>
1320,1321c1311
< <value>${system:java.io.tmpdir}/${system:user.name}</value>
< <description>Location of Hive run time structured log file</description>
---
> <value>/home/hadoop/bigdata/hive/iotmp</value>
官网下载mysql jdbc驱动,放在lib目录下。
hadoop@master:~$ ls -l /home/hadoop/bigdata/hive/lib/ | grep mysql
-rw-r--r-- 1 hadoop hadoop 1007505 4月 22 23:45 mysql-connector-java-5.1.47-bin.jar
3 启动
master启动 metastore 服务:
hadoop@master:~$ nohup hive --service metastore &
slave01启动hiveserver2服务:
hadoop@slave01:~$ nohup hive --service hiveserver2 &
4 验证
hadoop@master:~$ hive
hive> create table test01(id int, name string);
OK
Time taken: 3.734 seconds
hive> show tables;
OK
test01
Time taken: 0.471 seconds, Fetched: 1 row(s)
hive> show databases;
OK
default
test
Time taken: 0.014 seconds, Fetched: 2 row(s)
5 总结
安装包 百度网盘链接: https://pan.baidu.com/s/1Nxd82L800_JAWqTlZrDSOA 提取码: xwbu
配置参考代码 github: https://github.com/zhixingkad/bigdata