<返回更多

hive systemctl启停hiveserver2和metastore服务

2021-07-28    攻橙狮牛哥
加入收藏

1)、编辑hive启停shell脚本,脚本如下(说明:脚本别忘记了用户需要执行权限)

#!/bin/sh

if [ $# -ne 2 ] ;then
	echo "please input two params,first is (metastore|hiveserver2),second is (start|stop)"
	exit 0
fi
if [ "$1" == "metastore" ] ; then
	if [ "$2" == "start" ] ; then
		cd /var/log/hive
		echo "now is start metastore"
		nohup /usr/local/hive/bin/hive --service metastore &
		exit 0
	elif [ "$2" == "stop" ] ; then
		metastore_pid=`ps -ef|grep "HiveMetaStore"|grep "JAVA"|awk '{print $2}'`
		kill ${metastore_pid}
		echo "-------metastore has stop"
		exit 0
	else
		echo "second param please input 'start' or 'stop'"
		exit 0
	fi
elif [ "$1" == "hiveserver2" ] ; then
	if [ "$2" == "start" ] ; then
		cd /var/log/hive
        	echo "now is start hiveserver2"
		nohup /usr/local/hive/bin/hive --service hiveserver2 &
		exit 0
        elif [ "$2" == "stop" ] ; then
		hiveserver2_pid=`ps -ef|grep "HiveServer2"|grep "java"|awk '{print $2}'`
		kill ${hiveserver2_pid}
		echo "-------hiveserver has stop"
		exit 0
        else
                echo "second param please input 'start' or 'stop'"
		exit 0
        fi
else
	echo "first param please input 'metastore' or 'hiveserver2'"
fi

2)、在/usr/lib/systemd/system创建对应的metastore和hiveserver启停服务hive-hivesver2和hive-metastore是systemctl的启停名称

hive systemctl启停hiveserver2和metastore服务

 

hive-hiveserver2.service脚本内容:

[Unit]
Description=metastore
Wants.NETwork-online.target
After=network-online.target

[Service]
Type=forking 
User=hive
Group=hadoop
Environment="HADOOP_HOME=/usr/local/hadoop3" #说明:这个环境变量得加上,否则会报找不到这个环境变量,虽然/usr/local/hive/conf/hive_service.sh hiveserver2 start能正常启动,但是使用systemctl启动就会找不到这个环境变量
ExecStart=/usr/local/hive/conf/hive_service.sh hiveserver2 start
ExecStop=/usr/local/hive/conf/hive_service.sh hiveserver2 stop
Restart=no

[Install]
WantedBy=multi-user.target

hive-metastore.service脚本内容:

[Unit]
Description=metastore
Wants=network-online.target
After=network-online.target

[Service]
Type=forking 
User=hive
Group=hadoop
Environment="HADOOP_HOME=/usr/local/hadoop3"
ExecStart=/usr/local/hive/conf/hive_service.sh metastore start
ExecStop=/usr/local/hive/conf/hive_service.sh metastore stop
Restart=no

[Install]
WantedBy=multi-user.target

说明:每次修改service脚本之后要执行systemctl daemon-reload,否则修改的脚本不会被加载

3)、启动服务 systemctl start hive-metastore

hive systemctl启停hiveserver2和metastore服务

 

4)、停止服务systemctl stop hive-metastore

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>