使用脚本启动hivestore和hiveserver2

由于手动输入nohup太麻烦了,所以我写了个脚本来控制他们俩的启动和关闭

1、创建文件

metastore的

#!/bin/bash
if [ $# -lt 1 ]
	then
        echo "`date` [ERROR] No Args Input..."
        exit ;
fi

#记录pid的文件我都放到了/mydata/pid路径下
pid=0
if [ -f '/mydata/pid/metastore' ] #判断 记录pid的文件是否存在 来判断是否启动了metastore
	then
		pid=`cat /mydata/pid/metastore`
fi
echo ""

case $1 in
"start")
    echo "=================== Start Metastore ==================="
	if [ ${pid} -ne 0 ]
		then
			echo "`date` [ERROR] Metastore has already been started"
			echo ""
			exit ;
	fi
    #将pid输出到文件里
    nohup hive --service metastore & echo $! > /mydata/pid/metastore 
	echo "`date` [INFO] Metastore has been successfully started[${pid}]"
;;
"stop")
    echo "=================== Stop Metastore ==================="
	if [ ${pid} -ne 0 ]
		then
			echo "`date` [INFO] Closing Metastore[${pid}]..."
			kill -9 ${pid}
			rm -rf /mydata/pid/metastore
			echo "`date` [INFO] Metastore has been stopped"
		else
			echo "`date` [ERROR] Metastore is not running"
	fi
;;
*)
	echo "`date` [ERROR] Input Args Error..."
;;
esac
echo ""

同理,hiveserver的

#!/bin/bash
if [ $# -lt 1 ]
	then
        echo "`date` [ERROR] No Args Input..."
        exit ;
fi
pid=0
if [ -f '/mydata/pid/hiveserver' ]
	then
		pid=`cat /mydata/pid/hiveserver`
fi
echo ""
case $1 in
"start")
    echo "=================== Start Hiveserver ==================="
	if [ ${pid} -ne 0 ]
		then
			echo "`date` [ERROR] Hiveserver has already been started[pid:${pid}]"
			echo ""
			exit ;
	fi
    nohup hive --service hiveserver2 & echo $! > /mydata/pid/hiveserver
	echo "`date` [INFO] Hiveserver has been successfully started[pid:`cat /mydata/pid/hiveserver`]"
;;
"stop")
    echo "=================== Stop hiveserver ==================="
	if [ ${pid} -ne 0 ]
		then
			echo "`date` [INFO] Closing Hiveserver[pid:${pid}]..."
			kill -9 ${pid}
			rm -rf /mydata/pid/hiveserver
			echo "`date` [INFO] Hiveserver has been stopped"
		else
			echo "`date` [ERROR] Hiveserver is not running"
	fi
;;
*)
	echo "`date` [ERROR] Input Args Error..."
;;
esac
echo ""

2、chmod

chmod +x /root/bin/metastore

3、使用示范

另外附上根据metastore的端口9083获取其pid的方法

pid=`netstat -anp | grep 9083 | grep -oP "([0-9]+?)(?=/java)"`

netstat -anp | grep 9083
echo "PID: ${pid}"

kill -9 ${pid}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

欧内的手好汗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值