虚拟机中启动和关闭 Hive Server 2 的 Shell 脚本
#!/bin/bash
定义变量
HIVE_HOME='/usr/local/hive' HIVE_CONF_DIR='$HIVE_HOME/conf' HIVE_PID_DIR='$HIVE_HOME/pid' HIVE_LOG_DIR='$HIVE_HOME/log' HIVE_SERVER2_PID_FILE='$HIVE_PID_DIR/hive-server2.pid'
检查 Hive Server 2 是否已经启动
if [ -f '$HIVE_SERVER2_PID_FILE' ]; then PID=$(cat '$HIVE_SERVER2_PID_FILE') if ps -p $PID > /dev/null; then echo 'Hive Server 2 is already running with PID $PID' exit 1 else rm '$HIVE_SERVER2_PID_FILE' fi fi
启动 Hive Server 2
echo 'Starting Hive Server 2...' '$HIVE_HOME/bin/hive' --service hiveserver2 --hiveconf hive.server2.thrift.port=10000 --hiveconf hive.server2.thrift.bind.host=0.0.0.0 --hiveconf hive.server2.logging.operation.enabled=true --hiveconf hive.server2.logging.operation.level=VERBOSE > '$HIVE_LOG_DIR/hive-server2.out' 2>&1 & PID=$! echo $PID > '$HIVE_SERVER2_PID_FILE' echo 'Hive Server 2 started with PID $PID'
等待 Hive Server 2 启动完全
echo 'Waiting for Hive Server 2 to start...' while ! nc -z localhost 10000; do sleep 1 done echo 'Hive Server 2 started successfully'
关闭 Hive Server 2
echo 'Stopping Hive Server 2...' kill $PID rm '$HIVE_SERVER2_PID_FILE' echo 'Hive Server 2 stopped successfully'
原文地址: https://www.cveoy.top/t/topic/oAYh 著作权归作者所有。请勿转载和采集!