1 如何配置hive
使用which hive查找到hive安装路径,hive/conf/路径下的hive-site.xml文件。
以下4项分别配置使用jdbc链接hive底层元数据库的链接字符串、驱动类名、登录元数据库的用户名、登录元数据库的密码
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.76.100:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</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>123</value>
<description>password to use against metastore database</description>
</property>
</configuration>
2 如何要使用java连接hive,需要启动hive的hiveserver2服务。并且进行相关配置,具体如下:
首先在hive-site.xml中找到
<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
</property>
其中value的值默认是NONE,即不需要认证,如果在连接时需要提供认证信息,则需要进行如下配置
首先将value值改为CUSTOM
<property>
<name>hive.server2.authentication</name>
<value>CUSTOM</value>
</property>
配置自定义验证类
<property>
<name>hive.server2.custom.authentication.class</name>
<value>自定义类名如:org.apache.hadoop.hive.contrib.auth.CustomPasswdAuthenticator</value>
<description>
Custom authentication class. Used when property
'hive.server2.authentication' is set to 'CUSTOM'. Provided class
must be a proper implementation of the interface
org.apache.hive.service.auth.PasswdAuthenticationProvider. HiveServer2
will call its Authenticate(user, passed) method to authenticate requests.
The implementation may optionally implement Hadoop's
org.apache.hadoop.conf.Configurable class to grab Hive's Configuration object.
</description> 说明信息,该类必须实现org.apache.hive.service.auth.PasswdAuthenticationProvider接口,hiveserver2利用它的Authenticate(user, passed) 方法进行请求认证
</property>