From ce5e095fb1a32eef90edaa1c73634bcc642a8a3e Mon Sep 17 00:00:00 2001 From: louzin <294098546@qq.com> Date: Mon, 17 Apr 2023 13:47:16 +0800 Subject: [PATCH] =?UTF-8?q?metastore=E5=92=8Chiveserver2=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/hive.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 script/hive.sh diff --git a/script/hive.sh b/script/hive.sh new file mode 100755 index 0000000..e1db074 --- /dev/null +++ b/script/hive.sh @@ -0,0 +1,43 @@ +#!/bin/bash +HIVE_LOG_DIR=$HIVE_HOME/logs + +mkdir -p $HIVE_LOG_DIR + +#检查进程是否运行正常,参数1为进程名,参数2为进程端口 +function check_process() +{ + pid=$(ps -ef 2>/dev/null | grep -v grep | grep -i $1 | awk '{print $2}') + ppid=$(netstat -nltp 2>/dev/null | grep $2 | awk '{print $7}' | cut -d '/' -f 1) + echo $pid + [[ "$pid" =~ "$ppid" ]] && [ "$ppid" ] && return 0 || return 1 +} + +function hive_start() +{ + metapid=$(check_process HiveMetastore 9083) + cmd="nohup hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &" + cmd=$cmd" sleep 4; hdfs dfsadmin -safemode wait >/dev/null 2>&1" + [ -z "$metapid" ] && eval $cmd || echo "Metastroe服务已启动" + server2pid=$(check_process HiveServer2 10000) + cmd="nohup hive --service hiveserver2 >$HIVE_LOG_DIR/hiveServer2.log 2>&1 &" + [ -z "$server2pid" ] && eval $cmd || echo "HiveServer2服务已启动" +} + +function hive_stop() +{ + metapid=$(check_process HiveMetastore 9083) + [ "$metapid" ] && kill $metapid || echo "Metastore服务未启动" + server2pid=$(check_process HiveServer2 10000) + [ "$server2pid" ] && kill $server2pid || echo "HiveServer2服务未启动" +} + +case $1 in +"start") + hive_start + ;; +"stop") + hive_stop + ;; +"restart") + hive_stop +esac \ No newline at end of file