Hive有三种模式:
- 内嵌Derby方式
- Local方式
- Remote方式
在实际的开发中,我们经常用的是第三种,所以接下来我们就介绍一下Remote方式的Hive如何配置
由于Remote方式和Local方式都是使用的mysql数据库,所以在安装Hive之前,我们需要先安装mysql
-
首先从官网下载安装文件 http://mirror.bit.edu.cn/apache/hive/
-
然后把文件上传到Linux中,解压并重命名为hive-1.2.1,由于Remote方式中是多用户操作,所以分为服务器端的配置和客户端的配置。
-
我们先来配置服务器端,在hive-1.2.1下的conf目录,有一个hive-default.xml.template文件,把它重命名为hive-site.xml
-
接下来在hive-site.xml中配置hive
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive_remote/warehouse</value>
</property>
<property>
<name>hive.metastore.local</name>
<value>true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name> //此处是指定hive在mysql中的连接的是hive_meta数据库
<value>jdbc:mysql://localhost/hive_meta?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value> //此处是指定hive连接mysql时使用的用户名
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123</value> //此处是指定hive连接mysql时使用的密码
</property>
</configuration>
- 接下来是client端的配置,可以把Server端解压好的安装包直接拿过来,也可以重新解压,同样在hive-site.xml中添加如下配置:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://XXX.XXX.XX.XXX:9083</value> //此处配置的是Server的ip,端口号默认都是9083
</property>
</configuration>
-
到这里,Hive的配置基本就完成了,需要注意的是,在启动过程中如果Hadoop安装目录下的$HADOOP_HOME/share/hadoop/yarn/lib下的
jline-2.12.jar
的版本和Hive的lib目录下的jline版本不一致,所以启动的时候会报错,这时候需要将Hive中的jline-2.12.jar
拷贝到Hadoop的share/hadoop/yarn/lib目录下,再次启动正常。
-
接下来就是正常启动,由于在配置文件中我们配置了hive连接的数据库为hive_meta,用户为hive,密码为123,所以需要先在mysql数据库中创建hive_meta表,创建hive用户并授权hive用户相关权限
grant all privileges on hive_meta.* to hive@"%" identified by '123';
然后可以在Server端启动一下hive,直接输入hive
即可, -
如果Server端可以正常启动如果Server端可以正常启动,就可以输入
hive --service metastore
命令,启动远程连接进程。 -
在客户端直接使用
hive
命令即可连接正常使用。
Hive Beeline
- 修改服务器端hive-site.xml文件,配置用户名和密码。
<property>
<name>hive.server2.authentication</name>
<value>CUSTOM</value>
</property>
<property>
<name>hive.jdbc_passwd.auth.zhangsan</name>
<value>123456789</value>
</property>
<property>
<name>hive.server2.custom.authentication.class</name>
<value>com.hoe.hive.authoriz.UserPasswdAuth</value>
</property>
- 在服务器端使用hiveserver2(hive的bin目录下)启动thirftserver
- 通过Beeline输入用户名密码连接
- 通过JDBC连接
服务端启动hiveserver2后,在java代码中通过jdbc访问默认端口10000进行连接、访问