HIVE2.3.3安装(on Hadoop 2.8.5)
/root/apache-hive-2.3.3-bin
拷贝mysql-connector-java-5.1.26.jar到/root/apache-hive-2.3.3-bin/lib/
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/root/hadoop-2.8.5 # Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/root/apache-hive-2.3.3-bin/conf
[root@hadoop-master1 conf]# vi hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--Hive作业的HDFS根目录位置 -->
<property>
<name>hive.exec.scratchdir</name>
<value>/user/hive/tmp</value>
</property>
<!--Hive作业的HDFS根目录创建写权限 -->
<property>
<name>hive.scratch.dir.permission</name>
<value>755</value>
</property>
<!--hdfs上hive元数据存放位置 -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<!--连接数据库地址,名称 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop-master1:3306/hive_metastore?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>root</value>
</property>
<!--连接数据库用户密码 -->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
</property>
<!--客户端显示当前查询表的头信息 -->
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<!--客户端显示当前数据库名称信息 -->
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
</configuration>
[root@hadoop-master1 conf]# vi hive-log4j2.properties
property.hive.log.level = INFO
property.hive.root.logger = DRFA
property.hive.log.dir = /root/apache-hive-2.3.3-bin/log
property.hive.log.file = hive.log
property.hive.perflogger.log.level = INFO
5:启动metastore服务
/root/apache-hive-2.3.3-bin/bin/schematool -dbType mysql -initSchema
/root/apache-hive-2.3.3-bin/bin/hive --service metastore
拷贝hadoop-master1:/root/apache-hive-2.3.3-bin到hadoop-slave1:/root/apache-hive-2.3.3-bin
修改/root/apache-hive-2.3.3-bin/conf/hive-site.xml
[root@hadoop-master1 conf]# vi hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.exec.scratchdir</name>
<value>/user/hive/tmp</value>
</property>
<name>hive.scratch.dir.permission</name>
<value>755</value>
</property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<name>hive.metastore.uris</name>
<value>thrift://hadoop-master1:9083</value>
</property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
</configuration>
7:启动hivesever2服务
/root/apache-hive-2.3.3-bin/bin/hiveserver2
添加/root/apache-hive-2.3.3-bin/jdbc/hive-jdbc-2.3.3-standalone.jar到build path
package com.lijiahong.hive.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class Test { private static String driverName = "org.apache.hive.jdbc.HiveDriver"; private static String connctUrl = "jdbc:hive2://192.168.20.130:10000/dw"; private static String userName = "root"; private static String password = "123456"; public static void main(String[] args) throws Exception { Class.forName(driverName); Connection con = DriverManager.getConnection(connctUrl, userName, password); Statement stmt = con.createStatement(); ResultSet res = stmt.executeQuery( "select * from dw.test01" ); while (res.next()) { System.out.println( res.getInt(1) +"," + res.getString(2) ); } stmt.close(); con.close(); } }
编写java账号密码验证代码
package com.lijiahong.hive.jdbc.auth; import javax.security.sasl.AuthenticationException; import org.apache.hive.service.auth.PasswdAuthenticationProvider; public class CustomPasswdAuthentication implements PasswdAuthenticationProvider { @Override public void Authenticate(String user, String password) throws AuthenticationException { if(user.equals("root") && password.equals("123456") ) { System.out.println("user [" + user + "] auth check ok .. "); } else { System.out.println("user [" + user + "] auth check fail .. "); throw new AuthenticationException("user [" + user + "] auth check fail .. "); } } }
上传到/root/apache-hive-2.3.3-bin/lib
<property>
<name>hive.server2.authentication</name>
<value>CUSTOM</value>
</property>
<property>
<name>hive.server2.custom.authentication.class</name>
<value>com.lijiahong.hive.jdbc.auth.CustomPasswdAuthentication</value>
</property>