由于我现在使用的是普通用户,如果要用nohup指令后台启动metastore服务,则需要su root切换到root用户,所以我写了一个能够免密执行后台启动metastore的shell脚本,就可以不用每次都进行su root
#!/bin/bash
RES=$(jps | grep RunJar | tr -cd [0-9])
echo ''
if [ -z $RES ]
then
nohup /opt/module/hive-3.1.2/bin/hive --service metastore &
nohup /opt/module/hive-3.1.2/bin/hive --service hiveserver2 --hiveconf hive.root.logger=DEBUG,console &
# /opt/module/hive-3.1.2/bin/hive
else
echo 'hive2 has already run'
fi
echo''
以下是结束后台进程的脚本
#!/bin/bash
ROOT_PASSWORD="123456"
SRC=$(jps | grep RunJar)
ARR=($SRC)
INDEX=0
while [[ $INDEX<=${#ARR} ]]; do
if [[ -n ${ARR[$INDEX]} && `expr $INDEX % 2` == 0 ]]
then
kill -9 ${ARR[$INDEX]}
fi
let "INDEX++"
done
echo ''
以下是查看metastore后台服务是否启动的脚本
#!/bin/bash
SRC=$(jps | grep RunJar)
JPS_NUM=($SRC)
if [ ${#JPS_NUM} == 4 ]
then
echo 'hive2 is running'
else
echo 'hive2 is dead'
fi