将 hive-site.xml 文件中的 ${system:java.io.tmpdir} 替换为hive的本地临时目录,如果该目录不存在,需要先进行创建,并且赋予读写权限,我这边创建的临时目录是/opt/hive/tmp
[root@k8s-master ~]# mkdir -p /opt/hive/tmp [root@k8s-master ~]# chmod 755 /opt/hive/tmp [root@k8s-master ~]# cd /opt/hive/conf # 在vim命令模式下执行如下命令完成替换 :%s#${system:java.io.tmpdir}#/opt/hive/tmp#g 3.4.2 配置Hive用户名 [root@k8s-master ~]# cd /opt/hive/conf [root@k8s-master conf]# vim hive-site.xml :%s#${system:user.name}#root#g 3.4.3 修改Hive数据库配置hive-site.xml中与mysql相关的配置,如下所示:
属性名称 描述javax.jdo.option.ConnectionDriverName 数据库的驱动类名称
javax.jdo.option.ConnectionURL 数据库的JDBC连接地址
javax.jdo.option.ConnectionUserName 连接数据库所使用的用户名
javax.jdo.option.ConnectionPassword 连接数据库所使用的密码
在hive-site.xm配置文件中修改以上4项配置:
<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.ConnectionURL</name> <value>jdbc:mysql://k8s-master:3306/hive?createDatabaseIfNotExist=true</value> <description> JDBC connect string for a JDBC metastore. To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL. For example, jdbc:postgresql://myhost/db?ssl=true for postgres database. </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>123456</value> <description>password to use against metastore database</description> </property>随后,将下载的mysql的jdbc驱动jar包,放到hive的lib目录下
[root@k8s-master opt]# tar -zxf mysql-connector-java-5.1.47.tar.gz [root@k8s-master opt]# cd mysql-connector-java-5.1.47 [root@k8s-master mysql-connector-java-5.1.47]# cp mysql-connector-java-5.1.47.jar /opt/hive/lib 4. Hive启动与测试 4.1 Hive数据库初始化 [root@k8s-master ~]# cd /opt/hive/bin [root@k8s-master ~]# schematool -initSchema -dbType mysql 随后会生成一些连接mysql的初始化信息 4.2 启动Hive [root@k8s-master ~]# cd /opt/hive/bin # 使用 hive 命令启动Hive [root@k8s-master bin]# ./hive which: no hbase in (/opt/hive/bin:/opt/jdk1.8.0_161/bin:/opt/jdk1.8.0_161/bin:/usr/lib64/qt-3.7/bin:/opt/hive/bin:/opt/bin:/usr/bin:/opt/sbin:/usr/sbin:/opt/zookeeper-3.4.12/bin:/home/hadoop/.local/bin:/home/hadoop/bin:/opt/hadoop-2.7.5/bin:/opt/hadoop-2.7.5/sbin:/home/hadoop/.local/bin:/home/hadoop/bin:/home/hadoop/.local/bin:/home/hadoop/bin:/opt/hadoop-2.7.5/bin:/opt/hadoop-2.7.5/sbin:/opt/zookeeper-3.4.12/bin:/home/hadoop/.local/bin:/home/hadoop/bin:/opt/hadoop-2.7.5/bin:/opt/hadoop-2.7.5/sbin) SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See #multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Logging initialized using configuration in file:/opt/hive-2.3.7/conf/hive-log4j2.properties Async: true Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases. # 测试下hive能否正常使用 hive> show databases; OK default Time taken: 3.451 seconds, Fetched: 2 row(s) 5. 遇到的问题 5.1 Hive客户端提示which: no hbase in xxxx的信息问题定位: hive的启动脚本默认寻找了hbase的Path,我这边没装该模块,可以注释掉。