Hive是一个工具,原理是mapreduce,可以让用户以sql的方式去做数据分析汇总。
$ tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/module/
$ mv hive-env.sh.template hive-env.sh
$ vi hive-env.sh
export HADOOP_HOME=/opt/module/hadoop-3.1.2
根据自己机器上的hadoop安装目录,自行配置。
export HIVE_CONF_DIR=/opt/module/hive/conf
生产环境hive的元数据推荐配置到mysql中,所以mysql必须安装。这里略。
解压mysql驱动,驱动下载链接:mysql-jdbc-connector-java-5.1.44.zip
$ unzip mysql-connector-java-5.1.44.zip -d /opt/module/apache-hive-3.1.2-bin/lib/
拷贝mysql驱动jar包到hive的lib目录下
$ cp ./mysql-connect-java-5.1.27-bin.jar /opt/module/hive/lib/
Hive中conf目录下新建hive-site.xml文件
$ touch hive-site.xml
添加配置信息,内容参考hive-default.template
javax.jdo.option.ConnectionURL
jdbc:mysql://webapp200:3306/metastore?createDatabaseIfNotExist=true
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.
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
password
password to use against metastore database
hive.metastore.warehouse.dir
/user/hive/warehouse
location of default database for the warehouse
hive.metastore.schema.verification
true
hive.metastore.warehouse.dir注意权限
$ bin/hdfs dfs -chmod g+w /user/hive/warehouse
conf目录下修改hive-log4j.properties
$ mv hive-log4j.properties.template hive-log4j.properties
$ vi hive-log4j.properties
修改内容
property.hive.log.dir = /opt/module/apache-hive-3.1.2-bin/logs
注:hiveserver和metastore进程名都叫RunJar
将hive文件分发到各集群节点
Metastore服务多节点启动,hive-site.xml配置按3.2配置即可。
在你的Hive client节点hive-site.xml中添加如下配置。
hive.metastore.uris
thrift://hadoop100:9083,thrift://hadoop101:9083
笔者这里还未用到HiveServer2,所以这里略过。
hive是执行mapreduce任务,计算hdfs上存储的数据,所以必须先启动hdfs和yarn
$ bin/hive --service metastore &
后台启动
$ nohup bin/hive --service metastore 2>&1 >> /opt/module/apache-hive-3.1.2-bin/logs/metastore.log &
运行进程:
7370 RunJar
$ bin/hive
到此,Hive已经安装配置好了,进入hive client后就可以执行SQL语句进行数据计算分析了,生产环境一般通过定时任务去执行Hive SQL脚本,笔者会在后续文章中进行介绍。