之前已经在CentOS 6.7上安装部署Hadoop 2.7.2(http://blog.csdn.net/noob_f/article/details/53366756),并正常启动Hadoop集群。
机器名 | 作用 |
---|---|
master | NameNode |
slave | DataNode |
master
[root@master ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/stable/apache-hive-1.2.1-bin.tar.gz
[root@master ~]# tar zxvf apache-hive-1.2.1-bin.tar.gz
[root@master ~]# mv apache-hive-1.2.1-bin /usr/local/
Hive环境变量
[root@master ~]# vi /etc/profile.d/hive.sh
添加
export HIVE_HOME=/usr/local/apache-hive-1.2.1-bin
export PATH=$PATH:$HIVE_HOME/bin
保存退出
[root@master ~]# source /etc/profile.d/hive.sh
[root@master ~]# hive
Logging initialized using configuration in jar:file:/usr/local/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive> quit;
[root@master ~]#
安装MySQL
[root@master ~]# rpm -qa |grep mysql
mysql-libs-5.1.73-5.el6_6.x86_64
[root@master ~]# yum -y remove mysql-lib*
[root@master ~]# yum list |grep mysql
apr-util-mysql.x86_64 1.3.9-3.el6_0.1 base
bacula-director-mysql.x86_64 5.0.0-13.el6 base
bacula-storage-mysql.x86_64 5.0.0-13.el6 base
dovecot-mysql.x86_64 1:2.0.9-22.el6 base
freeradius-mysql.x86_64 2.2.6-6.el6_7 base
libdbi-dbd-mysql.x86_64 0.8.3-5.1.el6 base
mod_auth_mysql.x86_64 1:3.0.0-11.el6_0.1 base
mysql.x86_64 5.1.73-7.el6 base
mysql-bench.x86_64 5.1.73-7.el6 base
mysql-connector-java.noarch 1:5.1.17-6.el6 base
mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 base
mysql-devel.i686 5.1.73-7.el6 base
mysql-devel.x86_64 5.1.73-7.el6 base
mysql-embedded.i686 5.1.73-7.el6 base
mysql-embedded.x86_64 5.1.73-7.el6 base
mysql-embedded-devel.i686 5.1.73-7.el6 base
mysql-embedded-devel.x86_64 5.1.73-7.el6 base
mysql-libs.i686 5.1.73-7.el6 base
mysql-libs.x86_64 5.1.73-7.el6 base
mysql-server.x86_64 5.1.73-7.el6 base
mysql-test.x86_64 5.1.73-7.el6 base
pcp-pmda-mysql.x86_64 3.10.9-6.el6 base
php-mysql.x86_64 5.3.3-48.el6_8 updates
qt-mysql.i686 1:4.6.2-28.el6_5 base
qt-mysql.x86_64 1:4.6.2-28.el6_5 base
rsyslog-mysql.x86_64 5.8.10-10.el6_6 base
rsyslog7-mysql.x86_64 7.4.10-5.el6 base
[root@master ~]# yum install mysql-server.x86_64
[root@master ~]# rpm -qa |grep -i mysql
mysql-5.1.73-7.el6.x86_64
mysql-libs-5.1.73-7.el6.x86_64
mysql-server-5.1.73-7.el6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
将MySQL的JDBC驱动文件mysql-connector-java-5.1.40-bin.jar(该文件可在安装MySQL的lib目录下找到,我是在mysql官网下载的)复制到Hive的依赖库中
[root@master ~]# wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz
[root@master ~]# tar zxvf mysql-connector-java-5.1.40.tar.gz
[root@master ~]# cp mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar /usr/local/apache-hive-1.2.1-bin/lib/
设置MySQL
[root@master ~]# /etc/init.d/mysqld start
[root@master ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
mysql> create database hiveDB;
修改root密码
mysql> use mysql;
mysql> update user set password=password('root') where user='root';
刷新系统权限表
mysql> FLUSH PRIVILEGES;
mysql> quit;
重新登录mysql
[root@master ~]# mysql -u root –p
mysql> grant all privileges on hiveDB.* to 'root'@'%' identified by 'root';
mysql> flush privileges;
mysql> quit;
配置Hive
[root@master ~]# vi /usr/local/apache-hive-1.2.1-bin/conf/hive-env.sh.template
修改
# HADOOP_HOME=${bin}/../../hadoop
为
HADOOP_HOME=/usr/local/hadoop-2.7.2
保存退出
[root@master ~]# mv /usr/local/apache-hive-1.2.1-bin/conf/hive-env.sh.template /usr/local/apache-hive-1.2.1-bin/conf/hive-env.sh
[root@master ~]# /usr/local/hadoop-2.7.2/bin/hdfs dfs -ls /
16/11/25 19:08:51 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 2 items
drwx------ - root supergroup 0 2016-11-25 16:36 /tmp
drwxr-xr-x - root supergroup 0 2016-11-25 01:16 /user
- 创建数据仓库操作过程中临时数据在HDFS上的转存目录
[root@master ~]# /usr/local/hadoop-2.7.2/bin/hdfs dfs -mkdir /tmp/hive
- 创建数据仓库操作过程中数据文件在HDFS上的存储目录
[root@master ~]# /usr/local/hadoop-2.7.2/bin/hdfs dfs -mkdir /user/hive
[root@master ~]# /usr/local/hadoop-2.7.2/bin/hdfs dfs -mkdir /user/hive/warehouse
文件hive-site.xml
内保存Hive运行时所需要的相关配置信息
[root@master ~]# vi /usr/local/apache-hive-1.2.1-bin/conf/hive-site.xml
添加
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configuration>
<!-- Hive Execution Parameters -->
<property>
<name>hive.exec.scratchdir</name>
<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>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>hdfs://master:9000/hive/warehouse</value>
<description>location of default database for the warehouse</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.ConnectionUserName</name>
<value>root</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.Multithreaded</name>
<value>true</value>
<description>Set this to true if multiple threads access metastore through JDO concurrently.</description>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/hiveDB?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
</configuration>
保存退出
- 属性
hive.exec.scratchdir
:执行Hive操作访问HDFS时用于存储临时数据的目录,默认为/tmp/目录,通常设置为/tmp/hive/
。 - 属性
hive.metastore.warehouse.dir
:执行Hive数据仓库操作的数据存储目录,设置为HDFS存储路径hdfs://master_hostname:port/hive/warehouse
,这里设为hdfs://master:9000/hive/warehouse
。 - 属性
javax.jdo.option.ConnectionDriverName
:设置Hive连接MySQL的驱动名称,属性值为com.mysql.jdbc.Driver
。 - 属性
javax.jdo.option.ConnectionUserName
:Hive连接存储metastore内容的数据库的用户名。 - 属性
javax.jdo.option.ConnectionPassword
:Hive连接存储metastore内容的数据库的密码。 - 属性
javax.jdo.option.Multithreaded
:是否允许Hive与MySQL之间存在多条连接,设置为true,表示允许。 - 属性
javax.jdo.option.ConnectionURL
:设置Hive通过JDBC模式连接MySQL数据库存储metastore内容,属性值为jdbc:mysql://host/database_name?createDatabaseIfNotExist=true
,这里设为jdbc:mysql://master:3306/hiveDB?createDatabaseIfNotExist=true
。
[root@master ~]# hive
Logging initialized using configuration in jar:file:/usr/local/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive> SHOW TABLES;
OK
Time taken: 1.637 seconds
hive> quit;
[root@master ~]#