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
相关推荐
笑稀了的野生俊1 天前
在服务器中下载 HuggingFace 模型:终极指南
linux·服务器·python·bash·gpu算力
无级程序员1 天前
hive2服务启动报错:/tmp/hive on HDFS should be writable(不是chmod 777能解决的)
hive·hadoop·hdfs
rui锐rui1 天前
大数据学习2:HIve
大数据·hive·学习
凌辰揽月2 天前
Servlet学习
hive·学习·servlet
weixin_307779132 天前
Hive集群之间迁移的Linux Shell脚本
大数据·linux·hive·bash·迁移学习
shimly1234562 天前
bash 脚本比较 100 个程序运行时间,精确到毫秒,脚本
开发语言·chrome·bash
王小王-1232 天前
基于Hadoop的公共自行车数据分布式存储和计算平台的设计与实现
大数据·hive·hadoop·分布式·hadoop公共自行车·共享单车大数据分析·hadoop共享单车
小哈龙3 天前
裸仓库 + Git Bash 搭建 本地 Git 服务端与客户端
开发语言·git·bash
桂成林3 天前
Hive UDF 开发实战:MD5 哈希函数实现
hive·hadoop·哈希算法
阿巴~阿巴~4 天前
Linux基本命令篇 —— alias命令
linux·服务器·bash