hive 启停脚本

1.启动mysql

2. 启动meatstore

3.启动hiveserver2

启停脚本如下:

my_hive.sh

#!/bin/bash
## 启动mysql服务

systemctl start mariadb
function start(){

ps -ef|grep $1|grep -v grep > /dev/null
if [ $? -eq 0 ];then
        echo "$1 is active"
else
        echo "start $1"
        eval $2
fi

}
function stop(){

ps -ef|grep $1|grep -v grep > /dev/null
if [ $? -eq 0 ];then
        ps -ef|grep $1|grep -v grep |awk '{print $2}'|xargs kill -9
fi

}

####启动mysql
cmd="systemctl start mariadb"
start mysql "$cmd"

case $1 in 

    start)
        cmd1="nohup /opt/module/hive/bin/hive  --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
        cmd2="nohup /opt/module/hive/bin/hive --service hiveserver2 >$HIVE_LOG_DIR/hiveserver2.log 2>&1 &"
        start "metastore" "$cmd1"
        start "HiveServer2" "$cmd2"
    
    ;;
    stop)
        stop "hive-metastore"
        stop "HiveServer2"

    ;;
    restart)
        stop "hive-metastore"
        stop "HiveServer2"
        cmd1="nohup /opt/module/hive/bin/hive  --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
        cmd2="nohup /opt/module/hive/bin/hive --service hiveserver2 >$HIVE_LOG_DIR/hiveserver2.log 2>&1 &"
        start "metastore" "$cmd1"
        start "HiveServer2" "$cmd2"

    ;;
esac

 

posted @ 2021-08-29 23:47  冰底熊  阅读(22)  评论(0)    收藏  举报