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
相关推荐
xuanloyer5 小时前
linux基础学习--学习bash
linux·学习·bash
howard20057 小时前
6.5 Hive查询优化:执行计划与性能初探
hive·性能优化·执行计划
大数据007 小时前
SCD缓慢变化维Type1-Type3
hive·scd
vortex51 天前
Windows 下 Git Bash 终端高效配置指南
windows·git·bash
張萠飛1 天前
hive date_format函数有性能瓶颈,有个获取时区的逻辑影响性能,具体原因分析
数据仓库·hive·hadoop
2509_940880221 天前
Spring Boot 从 2.7.x 升级到 3.3注意事项
数据库·hive·spring boot
vortex51 天前
Bash One-Liners 学习精要指南
开发语言·chrome·bash
chde2Wang1 天前
datagrip访问远程hive库
hive
蒋士峰DBA修行之路1 天前
红帽练习环境介绍
linux·开发语言·bash
howard20051 天前
7.2 Hive自定义函数实战
hive·自定义函数·udf