该系列目录见链接:基于MapReduce进行项目实践的一系列环境配置
看前文
操作系统:Centos7,Windows10(可选)
工具:JDK11.0.7,MySQL8,Hadoop3.2.1
修改root权限,使得服务器可以远程连接:
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> update user set host = '%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>flush privileges;
mysql>exit;
本人选择安装位置在/data/目录下,http://ftp.twaren.net/Unix/Web/apache/hive/,官网下载hive-3.1.2,并解压:
# tar -zxvf apache-hive-3.1.1-bin.tar.gz
在/etc/profile中添加环境变量:
# vi /etc/profile
#添加以下内容
export HIVE_HOME=/data/apache-hive-3.1.2-bin
export PATH=$PATH:HIVE_HOME/bin
# source /etc/profile
在/data/apache-hive-3.1.2-bin/conf/ 下创建hive-site.xml 文件,复制hive-default.xml.template并更名为hive-site.xml:
# cp hive-default.xml.template hive-site.xml
注意,要修改hive-site.xml的部分内容,第3210行有个特殊字符,删除掉for,否则后续启动hive时会报expansion character错误,
<description>
Ensures commands with OVERWRITE (such as INSERT OVERWRITE) acquire Exclusive locks fortransactional tables. This ensures that inserts (w/o overwrite) running concurrently
are not hidden by the INSERT OVERWRITE.
</description>
创建HDFS文件夹。在HDFS中创建hive-site.xml对应的目录,并赋予读写权限:
# hadoop fs -mkdir -p /user/hive/warehouse
# hadoop fs -mkdir -p /tmp/hive
# hadoop fs -chmod -R 777 /user/hive/warehouse
# hadoop fs -chmod -R 777 /tmp/hive
# hadoop fs -ls /
Found 4 items
drwxr-xr-x - root supergroup 0 2020-05-09 23:35 /input
drwxr-xr-x - root supergroup 0 2020-05-25 02:16 /output
drwxr-xr-x - root supergroup 0 2020-05-27 00:58 /tmp
drwxr-xr-x - root supergroup 0 2020-05-27 00:58 /user
将 hive-site.xml 中的{system:java.io.tmpdir}改为hive的本地临时目录,将{system:user.name}改为自己的用户名,如果该目录不存在,需要先创建该目录:
# mkdir temp
# chmod -R 777 temp
# pwd
/data/apache-hive-3.1.2-bin/temp
修改hive-site.xml,在vim命令行状态下输入以下两个命令:
:%s#${system:java.io.tmpdir}#/data/apache-hive-3.1.2/temp#g
:%s#${system:user.name}#root#g
修改后内容如下:
hive.exec.local.scratchdir</name>
/usr/local/hive/apache-hive-3.1.1-bin/temp/root</value>
</property>
hive.downloaded.resources.dir</name>
/data/apache-hive-3.1.2-bin/temp/${hive.session.id}_resources</value>
</property>
hive.server2.logging.operation.log.location</name>
/data/apache-hive-3.1.2-bin/temp/root/operation_logs</value>
</property>
hive.querylog.location</name>
/data/apache-hive-3.1.2-bin/temp/root</value>
</property>
数据库相关配置。修改hive-site.xml相关内容如下:
# 数据库jdbc地址,value标签内修改为主机ip地址
javax.jdo.option.ConnectionURL</name>
jdbc:mysql://cit-server2-s2-120:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8</value>
</property>
# 数据库的驱动类名称
# 新版本8.0版本的驱动为com.mysql.cj.jdbc.Driver
javax.jdo.option.ConnectionDriverName</name>
com.mysql.cj.jdbc.Driver</value>
</property>
# 数据库用户名
javax.jdo.option.ConnectionUserName</name>
root</value>
</property>
# 数据库密码
javax.jdo.option.ConnectionPassword</name>
jiaojy</value> #修改为你自己的mysql密码
</property>
hive.metastore.schema.verification</name>
false</value>
</property>
复制并更名hive-log4j2.properties.template为 hive-log4j2.properties文件:
# cp hive-log4j2.properties.template hive-log4j2.properties
# vim hive-log4j2.properties
# 修改内容
property.hive.log.dir = /data/apache-hive-3.1.2-bin/temp/root
复制并更名hive-env.sh.template为 hive-env.sh文件:
cp hive-env.sh.template hive-env.sh
vim hive-env.sh
添加以下内容:
export HADOOP_HOME=/data/server/hadoop/3.2.1 #hadoop 安装目录
# Hive Configuration Directory can be controlled by:
# export HIVE_CONF_DIR=
export HIVE_CONF_DIR=/data/apache-hive-3.1.2-bin/conf #hive 配置文件目录
export HIVE_AUX_JARS_PATH=/data/apache-hive-3.1.2-bin/lib #hive 依赖jar包目录
官网下载,https://dev.mysql.com/downloads/connector/j/ ,System要选Platform Independent,选择后缀tar.gz的包进行下载并解压,然后将里面的jar上传到Hive/lib.(解压目录也要复制过去),进入hive的bin目录,进行初始化:
# ./schematool -dbType mysql –initSchema
Metastore connection URL: jdbc:mysql://cit-server2-s2-120:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8
Metastore Connection Driver : com.mysql.cj.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 3.1.0
Initialization script hive-schema-3.1.0.mysql.sql
Initialization script completed
schemaTool completed
出现如上结果证明hive安装和初始化成功,环境配置结束。
启动hive报错:
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
Metastore connection URL: jdbc:mysql://cit-server2-s2-120:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8
Metastore Connection Driver : com.mysql.jc.jdbc.Driver
Metastore connection User: root
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to load driver
Underlying cause: java.lang.ClassNotFoundException : com.mysql.jc.jdbc.Driver
记录一下本次项目环境配置磕磕绊绊的过程。
该系列目录见链接:基于MapReduce进行项目实践的一系列环境配置