Hive 服务管理脚本

shell 复制代码
#!/bin/bash
HIVE_HOME='/opt/software/hive-3.1.3'
HIVE_LOG_HOME='/opt/software/hive-3.1.3/log'

function checkLogDir {
	if [[ ! -e ${HIVE_LOG_HOME} ]]; then
		echo "${HIVE_LOG_HOME} 目录不存在,正在创建。"
		mkdir -p ${HIVE_LOG_HOME}
	fi
}

function checkHiveMetaStoreProgess {
	metastore=`ps -ef | grep -n HiveMetaStore | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${metastore} ]]; then
		return 1
	else
		return 0
	fi
}

function checkHiveServer2Progess {
	hiveserver2=`ps -ef | grep -n HiveServer2 | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${hiveserver2} ]]; then
		return 1
	else
		return 0
	fi
}

function stopProgess {
	checkHiveMetaStoreProgess
	metastore=`ps -ef | grep -n HiveMetaStore | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${metastore} ]]; then
		echo "HIVE HiveMetaStore 正在停止..."
		kill ${metastore}
	else
		echo "HIVE HiveMetaStore 服务未正常运行"
	fi

	checkHiveServer2Progess
	hiveserver2=`ps -ef | grep -n HiveServer2 | grep -v grep | awk '{print $2}'`
	if [[ ! -z ${hiveserver2} ]]; then
		echo "HIVE HiveServer2 正在停止..."
		kill ${hiveserver2}
	else
		echo "HIVE HiveServer2 服务未正常运行"
	fi
}

function startProgess {
	checkLogDir
		if [[ $? -eq 0 ]]; then
			checkHiveMetaStoreProgess
			if [[ $? -eq 0 ]]; then
				echo "正在启动 HIVE MetaStore..."
				`nohup hive --service metastore > ${HIVE_LOG_HOME}/metastore_log 2>&1 &`
			else
				echo "HIVE MetaStore 已经启动"
			fi

			checkHiveServer2Progess
			if [[ $? -eq 0 ]]; then
				echo "正在启动 HIVE HiveServer2..."
				`nohup hive --service hiveserver2 > ${HIVE_LOG_HOME}/hiveserver2_log 2>&1 &`
			else
				echo "HIVE HiveServer2 已经启动"
			fi
		fi
}

case ${1} in
	start )
		startProgess
		;;
	stop )
		stopProgess
		;;
	status )
		checkHiveMetaStoreProgess
		if [[ $? -eq 0 ]]; then
			echo "HIVE MetaStore 未启动"
		else
			echo "HIVE MetaStore 已经启动"
		fi

		checkHiveServer2Progess
		if [[ $? -eq 0 ]]; then
			echo "HIVE HiveServer2 未启动"
		else
			echo "HIVE HiveServer2 已经启动"
		fi
		;;
	* )
		echo "参数异常 hive-service.sh start|stop|status"
		;;
esac
相关推荐
wheeldown2 天前
【Linux】【实战向】Linux 进程替换避坑指南:从理解 bash 阻塞等待,到亲手实现能执行 ls/cd 的 Shell
linux·运维·bash
core5123 天前
Hive实战(三)
数据仓库·hive·hadoop
程序员小羊!3 天前
大数据电商流量分析项目实战:Hive 数据仓库(三)
大数据·数据仓库·hive
core5123 天前
Hive实战(一)
数据仓库·hive·hadoop·架构·实战·配置·场景
智海观潮3 天前
Spark SQL解析查询parquet格式Hive表获取分区字段和查询条件
hive·sql·spark
蜀中廖化4 天前
bash:trtexec:command not found
开发语言·bash
我有火的意志4 天前
Liunx执行source /etc/profile 报错, -bash: HISTTIMEFORMAT: readonly variable
开发语言·bash·histtimeformat·readonly
cxr8284 天前
基于Claude Code的 规范驱动开发(SDD)指南
人工智能·hive·驱动开发·敏捷流程·智能体
core5125 天前
Hive实战(二)
数据仓库·hive·hadoop
Agatha方艺璇6 天前
Hive基础简介
数据仓库·hive·hadoop