【CentOS】Hive安装

【CentOS】Hive安装,第1张

【CentOS】Hive安装

文章目录
  • 一、安装Hive
    • 1、解压安装包
    • 2、重命名
    • 3、添加MySQL驱动包
  • 二、环境配置
    • 1、环境变量
    • 2、配置 hive-env.sh
    • 3、配置 hive-site.xml
  • 三、配置log日志文件
  • 四、MySQL远程连接配置
  • 五、初始化元数据库
  • 六、启动Hive


今天使用很久没用的虚拟机,进入Hive的时候各种报错,索性重新安装。本人对于运维这块不是很熟悉,所以参考了师弟的博文:三十六、centos安装hive3.1.2(精讲篇),按照教程安装后很是成功,收获也颇多,还得向大佬多多学习 
主要环境资源点击此处下载呦~ 

环境准备:

  • CentOS 7
  • Hadoop正常运行 :Hadoop完全分布式
  • MySQL正常运行 :有安装MySQL

目标

  • 安装Hive 3.1.2版
  • 搭建Hive环境
  • 配置MySQL jar包驱动 5.1.37版
  • 关联MySQL 和 Hive
一、安装Hive 1、解压安装包
[root@d ~]# cd /home/download/
[root@d download]# ll
总用量 1432020
-rw-r--r--. 1 root root       129 4月  12 2021 !
-rw-r--r--. 1 root root       129 4月  12 2021 1
-rw-r--r--. 1 root root  58688757 8月  16 2020 apache-flume-1.8.0-bin.tar.gz
-rw-r--r--. 1 root root 278813748 9月  23 2020 apache-hive-3.1.2-bin.tar.gz
-rw-r--r--. 1 root root 210606807 5月  12 2020 hadoop-2.7.1_64bit.tar.gz
-rw-r--r--. 1 root root 118311464 8月  14 2020 hbase-1.4.12-bin.tar.gz
-rw-r--r--. 1 root root 189756259 8月   3 2020 jdk-8u161-linux-x64.tar.gz
-rw-r--r--. 1 root root 376537503 9月  23 2020 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--. 1 root root    990927 9月  23 2020 mysql-connector-java-5.1.40-bin.jar
-rw-r--r--. 1 root root  28678231 12月 27 20:18 scala-2.11.8.tgz
-rw-r--r--. 1 root root 203728858 9月  23 2020 spark-2.2.0-bin-hadoop2.7.tgz
-rw-r--r--. 1 root root     65816 3月  22 2021 telnet-0.17-65.el7_8.x86_64.rpm
-rw-r--r--. 1 root root     41996 3月  22 2021 telnet-server-0.17-65.el7_8.x86_64.rpm
-rw-r--r--. 1 root root    131484 3月  22 2021 xinetd-2.3.15-14.el7.x86_64.rpm

[root@d ~]#tar -zxvf apache-hive-3.1.2-bin.tar.gz /home -C /home/
[root@d home]# ll
总用量 28
-rw-r--r--.  1 root root   872 12月 27 20:31 !
drwxr-xr-x. 10 root root   184 1月   4 18:29 apache-hive-3.1.2-bin
drwx------. 17 d    d     4096 12月 27 19:37 d
drwxrwxrwx.  7 root root  4096 12月 27 09:52 data
drwxr-xr-x.  2 root root  4096 12月 27 20:18 download
drwxr-xr-x.  3 root root    19 9月  14 2020 flume
drwxr-xr-x.  3 root root    20 9月  14 2020 hadoop
drwxr-xr-x.  8 root root   172 9月  23 2020 hbase
drwxr-xr-x.  3 root root    17 9月  14 2020 java
drwxr-xr-x.  3 root root    47 9月  17 2020 kafka
drwxr-xr-x.  9 7161 31415  129 6月   2 2020 mysql
drwxrwxr-x.  6 zyx  mysql   50 3月   4 2016 scala
drwxr-xr-x. 14  500   500  217 12月 25 2020 spark
drwxr-xr-x. 14 root root   217 12月 27 23:48 spark-standalone
drwxr-xr-x.  3 root root    63 9月  22 2020 sqoop
-rw-r--r--.  1 root root  1675 9月  17 2020 ssh
-rw-r--r--.  1 root root   388 9月  17 2020 ssh.pub
drwx------. 14 zyx  zyx   4096 3月  17 2021 zyx

2、重命名
[root@d home]# mv apache-hive-3.1.2-bin hive
[root@d home]# ll
总用量 28
-rw-r--r--.  1 root root   872 12月 27 20:31 !
drwx------. 17 d    d     4096 12月 27 19:37 d
drwxrwxrwx.  7 root root  4096 12月 27 09:52 data
drwxr-xr-x.  2 root root  4096 12月 27 20:18 download
drwxr-xr-x.  3 root root    19 9月  14 2020 flume
drwxr-xr-x.  3 root root    20 9月  14 2020 hadoop
drwxr-xr-x.  8 root root   172 9月  23 2020 hbase
drwxr-xr-x. 10 root root   184 1月   4 18:29 hive
drwxr-xr-x.  3 root root    17 9月  14 2020 java
drwxr-xr-x.  3 root root    47 9月  17 2020 kafka
drwxr-xr-x.  9 7161 31415  129 6月   2 2020 mysql
drwxrwxr-x.  6 zyx  mysql   50 3月   4 2016 scala
drwxr-xr-x. 14  500   500  217 12月 25 2020 spark
drwxr-xr-x. 14 root root   217 12月 27 23:48 spark-standalone
drwxr-xr-x.  3 root root    63 9月  22 2020 sqoop
-rw-r--r--.  1 root root  1675 9月  17 2020 ssh
-rw-r--r--.  1 root root   388 9月  17 2020 ssh.pub
drwx------. 14 zyx  zyx   4096 3月  17 2021 zyx

3、添加MySQL驱动包


返回顶部


二、环境配置 1、环境变量
[root@d download]# vim /etc/profile


使环境变量立即生效:

[root@d download]# source /etc/profile

2、配置 hive-env.sh

(1)拷贝hive-env.sh.template并命名为hive-env.sh:

[root@d conf]# mv hive-env.sh.template hive-env.sh
[root@d conf]# ll
总用量 632
-rw-r--r--. 1 root root   1596 8月  23 2019 beeline-log4j2.properties.template
-rw-r--r--. 1 root root 300482 8月  23 2019 hive-default.xml.template
-rw-r--r--. 1 root root   2363 1月   4 18:33 hive-env.sh
-rw-r--r--. 1 root root   2365 8月  23 2019 hive-env.sh.template
-rw-r--r--. 1 root root   2274 8月  23 2019 hive-exec-log4j2.properties.template
-rw-r--r--. 1 root root   3086 8月  23 2019 hive-log4j2.properties.template
-rw-r--r--. 1 root root 301008 1月   4 18:42 hive-site.xml
-rw-r--r--. 1 root root   2060 8月  23 2019 ivysettings.xml
-rw-r--r--. 1 root root   3558 8月  23 2019 llap-cli-log4j2.properties.template
-rw-r--r--. 1 root root   7163 8月  23 2019 llap-daemon-log4j2.properties.template
-rw-r--r--. 1 root root   2662 8月  23 2019 parquet-logging.properties

(2)修改hive-env.sh 文件

..........
# Larger heap size may be required when running queries over large number of files or partitions.
# By default hive shell scripts use a heap size of 256 (MB).  Larger heap size would also be
# appropriate for hive server.

# 修改如下:
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/home/hadoop/hadoop/

# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/home/hive/conf/

# Folder containing extra libraries required for hive compilation/execution can be controlled by:
export HIVE_AUX_JARS_PATH=/home/hive/lib/

注:第一个为Hadoop目录,第二个为Hive配置目录,最后一个为驱动jar包路径


3、配置 hive-site.xml

(1)新建hive-site.xml:

[root@d conf]# ll
总用量 336
-rw-r--r--. 1 root root   1596 8月  23 2019 beeline-log4j2.properties.template
-rw-r--r--. 1 root root 300482 8月  23 2019 hive-default.xml.template
-rw-r--r--. 1 root root   2391 1月   4 18:51 hive-env.sh
-rw-r--r--. 1 root root   2365 8月  23 2019 hive-env.sh.template
-rw-r--r--. 1 root root   2274 8月  23 2019 hive-exec-log4j2.properties.template
-rw-r--r--. 1 root root   3086 8月  23 2019 hive-log4j2.properties.template
-rw-r--r--. 1 root root   2060 8月  23 2019 ivysettings.xml
-rw-r--r--. 1 root root   3558 8月  23 2019 llap-cli-log4j2.properties.template
-rw-r--r--. 1 root root   7163 8月  23 2019 llap-daemon-log4j2.properties.template
-rw-r--r--. 1 root root   2662 8月  23 2019 parquet-logging.properties
[root@d conf]# vi hive-site.xml   // 直接新建

直接将此文件内容拷入hive-site.xml ,将如下hive-site.xml中对应的值替换为自己的真实数据值,其余标签无需修改


    
    
        javax.jdo.option.ConnectionURL
        jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8
    

     
        
        
    
        javax.jdo.option.ConnectionDriverName
        com.mysql.jdbc.Driver
    

    
    
        javax.jdo.option.ConnectionUserName
        root
    

    
    
        javax.jdo.option.ConnectionPassword
        123456
    

     
    
        hive.metastore.schema.verification
        false
    

   
    
        hive.metastore.warehouse.dir
        /user/hive/warehouse
    


(2)创建HDFS文件夹(必须要创建,hive-site.xml文件中有此路径,此路径很重要)

  • A、启动Hadoop各节点、MySQL:

  • B、离开安全模式,创建两个文件夹并赋予权限:

[root@d hadoop]# hadoop fs -mkdir -p /user/hive/warehouse

登陆50070端口查看hdfs文件系统:


(3)创建temp文件夹并赋予权限,路径为 /…/hive/temp

[root@d hive]# mkdir temp
[root@d hive]# chmod -R 777 temp/
[root@d hive]# pwd
/home/hive
[root@d hive]# ll
总用量 56
drwxr-xr-x. 3 root root   157 1月   4 18:29 bin
drwxr-xr-x. 2 root root  4096 1月   4 18:29 binary-package-licenses
drwxr-xr-x. 2 root root  4096 1月   4 18:56 conf
drwxr-xr-x. 4 root root    34 1月   4 18:29 examples
drwxr-xr-x. 7 root root    68 1月   4 18:29 hcatalog
drwxr-xr-x. 2 root root    44 1月   4 18:29 jdbc
drwxr-xr-x. 4 root root 12288 1月   4 18:46 lib
-rw-r--r--. 1 root root 20798 8月  23 2019 LICENSE
-rw-r--r--. 1 root root   230 8月  23 2019 NOTICE
-rw-r--r--. 1 root root  2469 8月  23 2019 RELEASE_NOTES.txt
drwxr-xr-x. 4 root root    35 1月   4 18:29 scripts
drwxrwxrwx. 2 root root     6 1月   4 19:00 temp

返回顶部


三、配置log日志文件

(1)拷贝并重命名hive-log4j2.properties.template为 hive-log4j2.properties文件

[root@d hive]# cd ./conf/
[root@d conf]# ll
总用量 340
-rw-r--r--. 1 root root   1596 8月  23 2019 beeline-log4j2.properties.template
-rw-r--r--. 1 root root 300482 8月  23 2019 hive-default.xml.template
-rw-r--r--. 1 root root   2391 1月   4 18:51 hive-env.sh
-rw-r--r--. 1 root root   2365 8月  23 2019 hive-env.sh.template
-rw-r--r--. 1 root root   2274 8月  23 2019 hive-exec-log4j2.properties.template
-rw-r--r--. 1 root root   3086 8月  23 2019 hive-log4j2.properties.template
-rw-r--r--. 1 root root   1591 1月   4 18:56 hive-site.xml
-rw-r--r--. 1 root root   2060 8月  23 2019 ivysettings.xml
-rw-r--r--. 1 root root   3558 8月  23 2019 llap-cli-log4j2.properties.template
-rw-r--r--. 1 root root   7163 8月  23 2019 llap-daemon-log4j2.properties.template
-rw-r--r--. 1 root root   2662 8月  23 2019 parquet-logging.properties
[root@d conf]#  cp hive-log4j2.properties.template hive-log4j2.properties
[root@d conf]# ll
总用量 344
-rw-r--r--. 1 root root   1596 8月  23 2019 beeline-log4j2.properties.template
-rw-r--r--. 1 root root 300482 8月  23 2019 hive-default.xml.template
-rw-r--r--. 1 root root   2391 1月   4 18:51 hive-env.sh
-rw-r--r--. 1 root root   2365 8月  23 2019 hive-env.sh.template
-rw-r--r--. 1 root root   2274 8月  23 2019 hive-exec-log4j2.properties.template
-rw-r--r--. 1 root root   3086 1月   4 19:02 hive-log4j2.properties
-rw-r--r--. 1 root root   3086 8月  23 2019 hive-log4j2.properties.template
-rw-r--r--. 1 root root   1591 1月   4 18:56 hive-site.xml
-rw-r--r--. 1 root root   2060 8月  23 2019 ivysettings.xml
-rw-r--r--. 1 root root   3558 8月  23 2019 llap-cli-log4j2.properties.template
-rw-r--r--. 1 root root   7163 8月  23 2019 llap-daemon-log4j2.properties.template
-rw-r--r--. 1 root root   2662 8月  23 2019 parquet-logging.properties

(2)修改日志文件:

[root@d conf]# vi hive-log4j2.properties

修改内容 property.hive.log.dir =/....../hive/temp/root 上面创建的目录/temp加一个root就可以了

返回顶部


四、MySQL远程连接配置

(1)登录MySQL

(2)使用mysql数据库:use mysql;

(3)执行: update user set host = '%' where user='root';

(4)退出MySQL:exit;

(5)重启MySQL服务:service mysql restart

返回顶部


五、初始化元数据库

Hive中的元数据,其默认存储在 Derby 中,由于MySQL性能有明显优势,此处以MySQL作为元数据库;

进入 /....../hive/bin 目录进行 mysql 初始化 *** 作:

[root@d ~]# cd /home/hive/bin
[root@d bin]# ll
总用量 44
-rwxr-xr-x. 1 root root   881 8月  23 2019 beeline
drwxr-xr-x. 3 root root  4096 1月   4 18:29 ext
-rwxr-xr-x. 1 root root 10158 8月  23 2019 hive
-rwxr-xr-x. 1 root root  1900 8月  23 2019 hive-config.sh
-rwxr-xr-x. 1 root root   885 8月  23 2019 hiveserver2
-rwxr-xr-x. 1 root root   880 8月  23 2019 hplsql
-rwxr-xr-x. 1 root root  3064 8月  23 2019 init-hive-dfs.sh
-rwxr-xr-x. 1 root root   832 8月  23 2019 metatool
-rwxr-xr-x. 1 root root   884 8月  23 2019 schematool
[root@d bin]# ./schematool -dbType mysql -initSchema

第一次的时候报错了:Error: Table 'CTLGS' already exists (state=42S01,code=1050)
org.apache.hadoop.hive.metastore.HivemetaException: Schema initialization FAILED! metastore state would be inconsistent !!

解决方案:

[root@d bin]# ./schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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?createDatabaseIfNotExist=true&characterEncoding=UTF-8
metastore Connection Driver :	 com.mysql.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/bin目录直接输入./hive

[root@d bin]# ./hive
which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/java/jdk/bin:/home/java/jdk/sbin:/home/hadoop/hadoop/bin:/home/sqoop/sqoop/bin:/home/scala/bin:/home/spark-standalone/bin:/root/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
Hive Session ID = 83efdd1a-ec25-4caa-9adc-07f85bd59222

Logging initialized using configuration in file:/home/hive/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 Session ID = 2edf5c07-6aa8-4c06-97c5-f262d5f761ac
[root@d bin]# ./hive
which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/java/jdk/bin:/home/java/jdk/sbin:/home/hadoop/hadoop/bin:/home/sqoop/sqoop/bin:/home/scala/bin:/home/spark-standalone/bin:/root/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
Hive Session ID = 83efdd1a-ec25-4caa-9adc-07f85bd59222

Logging initialized using configuration in file:/home/hive/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 Session ID = 2edf5c07-6aa8-4c06-97c5-f262d5f761ac
hive>

显示数据库:

hive> show tables;
OK
zyx
Time taken: 0.059 seconds, Fetched: 1 row(s)
hive> select * from zyx;
OK
Time taken: 1.986 seconds

返回顶部


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5700041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存