|NO.Z.00005|——————————|^^ 部署 ^^|——|Hadoop&Hive.V05|——|Hive.v05|Hive部署配置.v02|

一、Hive安装
### --- 安装步骤:

~~~     下载、上传、解压缩
~~~     修改环境变量
~~~     修改hive配置
~~~     拷贝JDBC的驱动程序
~~~     初始化元数据库
### --- 下载Hive软件,并解压缩

[root@linux123 software]# pwd
/opt/yanqi/software
[root@linux123 software]# tar zxvf apache-hive-2.3.7-bin.tar.gz -C ../servers/
[root@linux123 software]# cd ../servers
[root@linux123 servers]# mv apache-hive-2.3.7-bin hive-2.3.7
### --- 修改环境变量

~~~     # 在 /etc/profile 文件中增加环境变量
[root@linux123 ~]# vim /etc/profile
## HIVE_HOME
export HIVE_HOME=/opt/yanqi/servers/hive-2.3.7
export PATH=$PATH:$HIVE_HOME/bin

~~~     # 执行并生效
[root@linux123 ~]# source /etc/profile
### --- 修改 Hive 配置cd $HIVE_HOME/conf vi hive-site.xml 增加以下内容:

[root@linux123 ~]# cd $HIVE_HOME/conf
[root@linux123 conf]# vim hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>
    <!-- hive元数据的存储位置 -->
        <property>
                <name>javax.jdo.option.ConnectionURL</name>
                <value>jdbc:mysql://linux123:3306/hivemetadata?createDatabaseIfNotExist=true&amp;useSSL=false</value>
                <description>JDBC connect string for a JDBC metastore</description>
        </property>

        <!-- 指定驱动程序 -->
    <property>
                <name>javax.jdo.option.ConnectionDriverName</name>
                <value>com.mysql.jdbc.Driver</value>
                <description>Driver class name for a JDBC metastore</description>
        </property>

    <!-- 连接数据库的用户名 -->
        <property>
                <name>javax.jdo.option.ConnectionUserName</name>
                <value>hive</value>
                <description>username to use against metastore database</description>
        </property>

    <!-- 连接数据库的口令 -->
        <property>
                <name>javax.jdo.option.ConnectionPassword</name>
                <value>12345678</value>
                <description>password to use against metastore database</description>
        </property>
</configuration>
### --- 备注:
~~~     注意jdbc的连接串,如果没有 useSSL=false 会有大量警告
~~~     在xml文件中 &amp; 表示 &
### --- 拷贝 MySQL JDBC 驱动程序
~~~     将 mysql-connector-java-5.1.46.jar 拷贝到 $HIVE_HOME/lib

[root@linux123 ~]# cp /opt/yanqi/software/mysql-connector-java-5.1.46.jar /opt/yanqi/servers/hive-2.3.7/lib/
### --- 初始化元数据库

[root@linux123 ~]# cd /opt/yanqi/servers/hive-2.3.7/bin
[root@linux123 bin]# schematool -dbType  mysql -initSchema

~~~     # 生成数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hivemetadata       |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
### --- 启动Hive,执行命令

~~~     # 启动hive服务之前,请先启动hdfs、yarn的服务
[root@linux123 ~]# hive
hive> show functions;
二、Hive 属性配置
### --- 可在 hive-site.xml 中增加以下常用配置,方便使用。
~~~     # 数据存储位置 

[root@linux123 ~]# vim /opt/yanqi/servers/hive-2.3.7/conf/hive-site.xml
     <!-- 数据默认的存储位置(HDFS) -->
                <name>hive.metastore.warehouse.dir</name>
                <value>/user/hive/warehouse</value>
                <description>location of default database for the warehouse</description>
        </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>
        </property>
~~~     # 本地模式
 
        <property>
     <!-- 操作小规模数据时,使用本地模式,提高效率 -->
                <name>hive.exec.mode.local.auto</name>
                <value>true</value>
                <description>Let Hive determine whether to run in local mode automatically</description>
        </property>
~~~     # 备注:
~~~     当 Hive 的输入数据量非常小时,Hive 通过本地模式在单台机器上处理所有的任务。
~~~     对于小数据集,执行时间会明显被缩短。当一个job满足如下条件才能真正使用本地模式:
~~~     job的输入数据量必须小于参数:hive.exec.mode.local.auto.inputbytes.max(默认128MB)
~~~     job的map数必须小于参数:hive.exec.mode.local.auto.tasks.max (默认4)
~~~     job的reduce数必须为0或者1
### --- Hive的日志文件
~~~     # Hive的log默认存放在 /tmp/root 目录下(root为当前用户名);这个位置可以修改。
~~~     可以不修改,但是要知道位置。
~~~     Hadoop 2.x 中 NameNode RPC缺省的端口号:8020
~~~     对端口号要敏感

[root@linux123 ~]# cd $HIVE_HOME/conf/hive-log4j2.properties
[root@linux123 conf]# cp hive-log4j2.properties.template hive-log4j2.properties
[root@linux123 conf]# vim hive-log4j2.properties
# 添加以下内容:
property.hive.log.dir = /opt/yanqi/servers/hive-2.3.7/logs
~~~     # hive默认日志地址

[root@linux123 ~]# cat /tmp/root/hive.log
### --- 附录:添加第三方用户(Hadoop)
~~~     -m:自动建立用户的登入目录
~~~     -g:指定用户所属的起始群组
~~~     -G<群组>:指定用户所属的附加群组
~~~     -s:指定用户登入后所使用的shell

[root@linux123 ~]# groupadd hadoop
[root@linux123 ~]# useradd -m hadoop -g hadoop -s /bin/bash
[root@linux123 ~]# passwd hadoop
Changing password for user hadoop.
New password: 
Retype new password: 

[root@linux123 ~]# visudo
# 在100行后添加。允许用户执行sudo,免密
hadoop ALL=(ALL) LL
#  建议:现阶段使用root用户
### --- 小结:

~~~     添加了配置,使用Hive更方便;
~~~     删除了有冲突的软件包(hive)
~~~     Hive的日志在哪里(/tmp/root)
~~~     第三方用户使用Hive。建议使用root用户
~~~     NameNode 缺省的RPC(远程过程调用)端口号8020,经常使用的端口号9000
三、参数配置方式
### --- 查看参数配置信息:

~~~     # 查看全部参数
hive (default)> set;

~~~     # 查看某个参数
hive (default)> set hive.exec.mode.local.auto;
hive.exec.mode.local.auto=true
### --- 参数配置的三种方式:
~~~     用户自定义配置文件(hive-site.xml)
~~~     启动hive时指定参数(-hiveconf)
~~~     hive命令行指定参数(set)

~~~     # 配置信息的优先级:
set > -hiveconf > hive-site.xml > hive-default.xml
### --- 配置文件方式

~~~     默认配置文件:hive-default.xml
~~~     用户自定义配置文件:hive-site.xml
~~~     配置优先级:hive-site.xml > hive-default.xml
~~~     配置文件的设定对本机启动的所有Hive进程有效;
~~~     配置文件的设定对本机所有启动的Hive进程有效;
### --- 启动时指定参数值
~~~     启动Hive时,可以在命令行添加 -hiveconf param=value 来设定参数,这些设定仅对本次启动有效。

~~~     # 启动时指定参数
[root@linux123 ~]# hive -hiveconf hive.exec.mode.local.auto=true

~~~     # 在命令行检查参数是否生效
hive (default)> set hive.exec.mode.local.auto;
hive.exec.mode.local.auto=true
### --- 命令行修改参数
~~~     可在 Hive 命令行中使用SET关键字设定参数,同样仅对本次启动有效

hive (default)> set hive.exec.mode.local.auto=false;
hive (default)> set hive.exec.mode.local.auto;
hive.exec.mode.local.auto=false

附录一:Hive命令
### --- Hive

[root@linux123 ~]# hive -help
usage: hive
 -d,--define <key=value>          Variable substitution to apply to Hive
                                  commands. e.g. -d A=B or --define A=B
    --database <databasename>     Specify the database to use
 -e <quoted-query-string>         SQL from command line
 -f <filename>                    SQL from files
 -H,--help                        Print help information
    --hiveconf <property=value>   Use value for given property
    --hivevar <key=value>         Variable substitution to apply to Hive
                                  commands. e.g. --hivevar A=B
 -i <filename>                    Initialization SQL file
 -S,--silent                      Silent mode in interactive shell
 -v,--verbose                     Verbose mode (echo executed SQL to the
                                  console)
~~~     # -e:不进入hive交互窗口,执行sql语句    
[root@linux123 ~]# hive -e "select * from users"
 
~~~     # -f:执行脚本中sql语句
~~~     # 创建文件hqlfile1.sql,内容:select * from users
[root@linux123 ~]# vim hqlfile1.sql
select * from users
~~~     # # 执行文件中的SQL语句
[root@linux123 ~]# hive -f hqlfile1.sql

~~~     # # 执行文件中的SQL语句,将结果写入文件
hive -f hqlfile1.sql >> result1.log
### --- 退出Hive命令行

exit; quit;
### --- 在命令行执行 shell 命令 / dfs 命令

hive (default)> !ls;
hqlfile1.sql
hive (default)> !clear;
hive (default)> dfs -ls /;
drwxr-xr-x   - Administrator supergroup          0 2021-08-12 23:53 /api_test3
drwxr-xr-x   - Administrator supergroup          0 2021-08-14 00:09 /collect_log
drwxrwxrwx   - root          supergroup          0 2021-08-12 21:28 /test
drwxrwxrwx   - root          supergroup          0 2021-08-20 22:08 /tmp
drwxrwxrwx   - root          supergroup          0 2021-08-15 21:26 /user
drwxrwxrwx   - root          supergroup          0 2021-08-12 21:30 /wcinput
drwxrwxrwx   - root          supergroup          0 2021-08-12 21:50 /yanqi

附录一:报错处理一:
### --- 报错现象:

which: no hbase in (:/opt/yanqi/servers/jdk1.8.0_231/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/yanqi/servers/hadoop-2.9.2/bin:/opt/yanqi/servers/hadoop-2.9.2/sbin:/opt/yanqi/servers/hive-2.3.7/bin:/root/bin)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/yanqi/servers/hive-2.3.7/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/yanqi/servers/hadoop-2.9.2/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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 file:/opt/yanqi/servers/hive-2.3.7/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.
### --- 报错分析:

~~~     hbase没有设置不用管
~~~     /opt/yanqi/servers/hive-2.3.7/lib/log4j-slf4j-impl-2.6.2.jar
~~~     /opt/yanqi/servers/hadoop-2.9.2/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar
~~~     这两个包冲突;删掉hive里面的包;它会调用hadoop中的包;但是删除了hadoop中的包,他不会调用hive中的包
### --- 解决方案:

[root@linux123 ~]# rm -rf /opt/yanqi/servers/hive-2.3.7/lib/log4j-slf4j-impl-2.6.2.jar

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(9)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示