Hive中的日志与临时配置

2023-10-14 大数据Hive

在hive命令行中可以使用set命令临时设置一些参数的值, 其实就是临时修改hive-site.xml中参数的值,不过通过set命令设置的参数只在当前会话有效,退出重新打开就无效了,如果想要对当前机器上的当前用户有效的话可以把命令配置在~/.hiverc文件中。

  • 修改hive-site.xml对所有用户生效
  • 配置在~/.hiverc文件,对当前用户生效
  • 使用set命令,本次会话有效

# 使用set命令临时配置

观察下列命令,使用hive.cli.print.current.db = true可以显示当前操作的数据库,hive.cli.print.header = true可以显示表的字段名。

 





 








hive> set hive.cli.print.current.db = true;
hive (default)> select * from t1;
OK
1       zs
2       cvking
Time taken: 0.2 seconds, Fetched: 2 row(s)
hive (default)> set hive.cli.print.header = true;
hive (default)> select * from t1;
OK
t1.id   t1.name
1       zs
2       cvking
Time taken: 0.151 seconds, Fetched: 2 row(s)
hive (default)> 

# 配置对当前用户生效

[root@flume ~]# vi ~/.hiverc
[root@flume ~]# cat  ~/.hiverc 
set hive.cli.print.current.db = true;
set hive.cli.print.header = true;

# 日志配置

在hive的conf目录下有一些log4j的模板配置文件,修改模板配置文件,手动指定日志输出级别和地址。

# hive-log4j2.properties

修改日志级别为WARN,默认为INFO,以及日志输出地址。




 

 

[root@flume ~]# cd /usr/local/soft/hive/apache-hive-3.1.3-bin/conf/
[root@flume conf]# mv hive-log4j2.properties.template hive-log4j2.properties
[root@flume conf]# vi hive-log4j2.properties 
property.hive.log.level = WARN
property.hive.root.logger = DRFA
property.hive.log.dir = /data/hive_repo/log

# hive-exec-log4j2.properties




 


 

[root@flume conf]# mv hive-exec-log4j2.properties.template hive-exec-log4j2.properties
[root@flume conf]# vi hive-exec-log4j2.properties 
# list of properties
property.hive.log.level = WARN
property.hive.root.logger = FA
property.hive.query.id = hadoop
property.hive.log.dir = /data/hive_repo/log

# 查看hive历史执行的SQL语句

命令:tail -10 ~/.hivehistory

[root@flume ~]# tail -3 ~/.hivehistory 
insert into t1(id,name) values(2,"cvking");
set hive.cli.print.current.db = true;
select * from t1;
上次更新: 4 个月前