1.依赖(需要提前安装hadoop)
2.下载Hive
hive和hadoop版本:hadoop,hbase,hive版本整合兼容问题
https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.7/
3.安装
(1)修改环境变量 vi /etc/profile
export JAVA_HOME=/opt/jdk1.8.0_251
export HADOOP_HOME=/opt/hadoop-2.9.2
export HIVE_HOME=/opt/apache-hive-2.3.7-bin
export CLASSPATH=.:JAVAHOME/lib/dt.jar:JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
export PATH=PATH:PATH:JAVA_HOME/bin:HADOOPHOME/bin:HADOOP_HOME/bin:HADOOP_HOME/sbin:$HIVE_HOME/bin
(2)配置hive cd /opt/apache-hive-2.3.7-bin/conf
cp hive-env.sh.template hive-env.sh cp hive-default.xml.template hive-default.xml cp hive-log4j2.properties.template hive-log4j2.properties cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
(3) 创建hdfs目录 开启hadoop:start-all.sh
hdfs dfs -mkdir -p /usr/hive/warehouse (此处的-p指直接创建多级目录,一次创建成功) hdfs dfs -mkdir -p /usr/hive/tmp hdfs dfs -mkdir -p /usr/hive/log hdfs dfs -chmod g+w /usr/hive/warehouse (设置权限) hdfs dfs -chmod g+w /usr/hive/tmp hdfs dfs -chmod g+w /usr/hive/log
(4)修改hive-env.sh(conf 目录下)
export JAVA_HOME=/opt/jdk1.8.0_251
export HIVE_HOME=/opt/apache-hive-2.3.7-bin
export HADOOP_HOME=/opt/hadoop-2.9.2
export HIVE_CONF_DIR=/opt/apache-hive-2.3.7-bin/conf
(5)修改hive-site.xml
javax.jdo.option.ConnectionURL jdbc:mysql://localhost:3306/hive JDBC connect string for a JDBC metastore javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver Driver class name for a JDBC metastore javax.jdo.option.ConnectionUserName root Username to use against metastore database javax.jdo.option.ConnectionPassword 123 password to use against metastore database hive.exec.local.scratchdir /usr/local/hive Local scratch space for Hive jobs hive.downloaded.resources.dir /usr/local/hive/hive-downloaded-addDir/ Temporary local directory for added resources in the remote file system. hive.querylog.location /usr/local/hive/querylog-location-addDir/ Location of Hive run time structured log file hive.server2.logging.operation.log.location /usr/local/hive/hive-logging-operation-log-addDir/ Top level directory where operation logs are stored if logging functionality is enabled
(6)修改hive-log4j.properties
hive.log.dir=/usr/local/tmp
(7)mysql配置 安装参照:mysql安装_诸葛子房的博客-CSDN博客
mysql -u root -p
mysql> create database hive; mysql> show databases; mysql> grant all on hive.* to 'hive'@'%' identified by 'hive';(将所有数据库的所有表的所有权限赋给hive用户,后面的hive是配置hive-site.xml中配置的连接密码) mysql> flush privileges;(刷新mysql系统权限关系表) mysql> exit;
(8)下载连接 MySQL :: Download Connector/J
将 mysql-connector-java-8.0.20.jar 拷贝到lib目录下
Maven Repository: mysql » mysql-connector-java » 8.0.27 (mvnrepository.com)
(9)数据库初始化 hive bin 目录下
schematool -initSchema -dbType mysql
(10)启动
hive --service metastore hive
参考: