如何修改hive日志目录

  • 在hive的使用中,我们都知道可以通过修改hive-log4j2.properties.template中的属性来让hive打印日志到指定的地方,如打印到/var/log/hive/hive.log中,则可以配置如下的指定
property.hive.log.level = INFO
property.hive.root.logger = DRFA
property.hive.log.dir = /var/log/hive
property.hive.log.file = hive.log
property.hive.perflogger.log.level = INFO
  • 但是在实际中,我们不仅要设置hive日志的打印路径,还想再进一步的设置hms和hs2的日志路径,首先先从模板中拷贝对应进程的日志properties文件
cd /xxx/hive/hive-3.1.3/conf
cp  hive-log4j2.properties.template hive-hms-log4j2.properties
cp hive-log4j2.properties.template hive-hs2-log4j2.properties
  • 修改配置文件中日志的指定路径,接下思路就是如何让hms和hs2进程在启动时分别加载各自的log4j配置文件,可以通过修改hive脚本来实现
vim /xxx/hive/hive-3.1.3/bin/hive
#删除掉通用配置: 
export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS -Dlog4j.configurationFile=hive-log4j2.properties "
#新增如下判断添加:
if [ $SERVICE == "metastore" ]
then
   export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS -Dlog4j.configurationFile=hive-hms-log4j2.properties "
else
   export HADOOP_CLIENT_OPTS="$HADOOP_CLIENT_OPTS -Dlog4j.configurationFile=hive-hs2-log4j2.properties "
fi
  • 下面的hive命令启动hms和hs2,则会打印到正确的日志目录
 /xxx/hive/hive-3.1.3/bin/hive  --service    metastore >> /var/log/hive/metastore.out 2>&1 &
 /xxx/hive/hive-3.1.3/bin/hive  --service    hiveserver2 >> /var/log/hive/hiveserver2.out 2>&1 &

你可能感兴趣的:(如何修改hive日志目录)