Hive 安装
依赖环境
- HDFS和MapReduce就绪
- 需要安装MySQL数据库服务
[root@CentOS ~]# yum install -y mysql-server
[root@CentOS ~]# service mysqld start
[root@CentOS ~]# mysqladmin -u root password 'root'
[root@CentOS ~]# mysql -u root -proot
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> delete from user where password='';
Query OK, 4 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> create database hive;
Query OK, 1 row affected (0.00 sec)
安装配置Hive
[root@CentOS ~]# tar -zxf apache-hive-1.2.1-bin.tar.gz -C /home/hive
[root@CentOS ~]# vi /home/hive/apache-hive-1.2.1-bin/conf/hive-site.xml
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.134.1:3306/hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
</property>
</configuration>
拷贝相关依赖
-
将连接MySQL驱动jar包拷贝到hive安装目录下的lib目录.
-
拷贝hive安装lib目录下jline-2.12.jar到hadoop的share/hadoop/yarn/lib目录下,将低版本jline-0.9.94.jar删除
配置环境变量
export HBASE_MANAGES_ZK=false
export HBASE_HOME=/usr/hbase-1.2.4
export HADOOP_HOME=/usr/hadoop-2.6.0
export HADOOP_CLASSPATH=/root/mysql-connector-java-5.1.44.jar
export JAVA_HOME=/usr/java/latest
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin
export CLASSPATH=.
启动hive
单机
[root@CentOS apache-hive-1.2.1-bin]# ./bin/hive
>select current_database();
> show databases;
> show tables;
[root@CentOS apache-hive-1.2.1-bin]# ./bin/hive -e 'select * from t_user'
服务启动-JDBC
[root@CentOS apache-hive-1.2.1-bin]# ./bin/hiveserver2 #启动hive服务,挂起
[root@CentOS apache-hive-1.2.1-bin]# ./bin/beeline -u jdbc:hive2://$HOSTNAME:10000 -n root
Connecting to jdbc:hive2://CentOS:10000
Connected to: Apache Hive (version 1.2.1)
Driver: Hive JDBC (version 1.2.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.2.1 by Apache Hive
0: jdbc:hive2://CentOS:10000> show databases;
+----------------+--+
| database_name |
+----------------+--+
| default |
+----------------+--+
0: jdbc:hive2://CentOS:10000> select current_database();
+----------+--+
| _c0 |
+----------+--+
| default |
+----------+--+
0: jdbc:hive2://CentOS:10000> desc t_user;
+-----------+--------------+----------+--+
| col_name | data_type | comment |
+-----------+--------------+----------+--+
| id | int | |
| name | varchar(32) | |
+-----------+--------------+----------+--+