#2023 博客之星–城市之星领跑者活动开启#
安装Hive
准备
安装Java环境:Hive需要Java环境支持,所以需要先安装Java。安装文档:http://t.csdn.cn/deBJu
安装MySQL数据库。http://t.csdn.cn/d24pN
下载Hive
下载Hive的二进制文件。
链接:https://pan.baidu.com/s/1fdg76k9kvd896pMpfYEG5w
提取码:8888
解压Hive
将下载的Hive压缩包解压到指定目录。
[root@master ~]# cd /usr/local[root@master local]# ll
总用量 279464
-rw-r--r--. 1 root root 2861709586月 711:18 apache-hive-2.3.9-bin.tar.gz
drwxr-xr-x. 11100010002725月 25 08:49 hadoop-3.3.1
drwxr-xr-x. 810143101432734月 82021 jdk1.8.0_291
# 解压[root@master local]# tar -zxvf apache-hive-2.3.9-bin.tar.gz[root@master local]# ll
总用量 279464
drwxr-xr-x. 10 root root 1846月 711:22 apache-hive-2.3.9-bin
-rw-r--r--. 1 root root 2861709586月 711:18 apache-hive-2.3.9-bin.tar.gz
drwxr-xr-x. 11100010002725月 25 08:49 hadoop-3.3.1
drwxr-xr-x. 810143101432734月 82021 jdk1.8.0_291
配置Hive环境变量
将Hive的bin目录添加到系统环境变量中。
[root@master local]# vi /etc/profile# HiveexportHIVE_HOME=/usr/local/apache-hive-2.3.9-bin
exportPATH=$PATH:$HIVE_HOME/bin
[root@master local]# source /etc/profile
配置Hive配置文件
[root@master conf]# vi hive-env.sh.templateHADOOP_HOME=$HADOOP_HOMEexportHIVE_CONF_DIR=$HIVE_HOME/conf
配置hive-config.sh
[root@master ~]# cd /usr/local/apache-hive-2.3.9-bin/bin[root@master bin]# vi hive-config.sh# 配置hiveexportJAVA_HOME=/usr/local/jdk1.8.0_291
exportHIVE_HOME=/usr/local/apache-hive-2.3.9-bin
exportHADOOP_HOME=/usr/local/hadoop-3.3.1
exportHIVE_CONF_DIR=/usr/local/apache-hive-2.3.9-bin/conf
拷贝Hive配置文件
[root@master ~]# cd /usr/local/apache-hive-2.3.9-bin/conf/[root@master conf]# cp hive-default.xml.template hive-site.xml
配置hive-site.xml
[root@master conf]# vi hive-site.xml
修改Hive的配置文件hive-site.xml,设置Hive的元数据存储方式、Hadoop的配置文件路径等。
<property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://localhost:3306/hive?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC</value><description>MYSQL连接协议</description></property><property><name>javax.jdo.option.ConnectionDriverName</name><value>com.mysql.jdbc.Driver</value><description>JDBC连接驱动</description></property><property><name>javax.jdo.option.ConnectionUserName</name><value>root</value><description>用户名</description></property><property><name>javax.jdo.option.ConnectionPassword</name><value>123456</value><description>密码</description></property><property><name>datanucleus.schema.autoCreatAll</name><value>true</value><description>自动更新数据库</description></property><property><name>hive.metastore.schema.verification</name><value>false</value></property><property><name>hive.exec.local.scratchdir</name><value>/usr/local/apache-hive-2.3.9-bin/tmp/${user.name}</value><description>Local scratch space for Hive jobs</description></property><property><name>system:java.io.tmpdir</name><value>/usr/local/apache-hive-2.3.9-bin/iotmp</value></property><property><name>hive.downloaded.resources.dir</name><value>/usr/local/apache-hive-2.3.9-bin/tmp/${hive.session.id}_resources</value><description>Temporary local directory for added resources in the remote file system.</description></property><property><name>hive.querylog.location</name><value>/usr/local/apache-hive-2.3.9-bin/tmp/${system:user.name}</value><description>Location of Hive run time structured log file</description></property><property><name>hive.server2.logging.operation.log.location</name><value>/usr/local/apache-hive-2.3.9-bin/tmp/${system:user.name}/operation_logs</value><description>Top level directory where operation logs are stored if logging functionality is enabled</description></property><property><name>hive.metastore.db.type</name><value>mysql</value></property><property><name>hive.cli.print.current.db</name><value>true</value><description>Whether to include the current database in the Hive prompt.</description></property><property><name>hive.cli.print.header</name><value>true</value><description>Whether to print the names of the columns in query output.</description></property>
将mysq-comnector-java-5.1.32.jar驱动包上传至bin目录下
初始化元数据库
[root@master ~]# schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in[jar:file:/usr/local/apache-hive-2.3.9-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in[jar:file:/usr/local/hadoop-3.3.1/share/hadoop/common/lib/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type[org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL: jdbc:mysql://localhost:3306/hive?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 2.3.0
Initialization script hive-schema-2.3.0.mysql.sql
Initialization script completed
schemaTool completed
启动Hive
在命令行中输入hive命令,启动Hive。
[root@master conf]# hdfs namenode -format[root@master conf]# start-dfs.sh[root@master conf]# start-yarn.sh[root@master conf]# hive
which: no hbase in(/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk1.8.0_291/bin:/usr/local/jdk1.8.0_291/jre/bin:/usr/local/hadoop-3.3.1/bin:/usr/local/hadoop-3.3.1/sbin:/root/bin:/usr/local/jdk1.8.0_291/bin:/usr/local/jdk1.8.0_291/jre/bin:/usr/local/hadoop-3.3.1/bin:/usr/local/hadoop-3.3.1/sbin:/usr/local/apache-hive-2.3.9-bin/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in[jar:file:/usr/local/apache-hive-2.3.9-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in[jar:file:/usr/local/hadoop-3.3.1/share/hadoop/common/lib/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type[org.apache.logging.slf4j.Log4jLoggerFactory]
Logging initialized using configuration in jar:file:/usr/local/apache-hive-2.3.9-bin/lib/hive-common-2.3.9.jar!/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:
在Hive命令行中输入一些Hive查询语句,测试Hive是否正常工作。
# 查看数据库
hive (default)> show databases;
OK
database_name
default
Time taken: 6.772 seconds, Fetched: 1 row(s)# 创建数据表
hive (default)> create table student(>id int
>);
OK
Time taken: 1.294 seconds
# 查看数据表
hive (default)> show tables;
OK
tab_name
student
Time taken: 0.06 seconds, Fetched: 1 row(s)
版权归原作者 陆卿之 所有, 如有侵权,请联系我们删除。