#! /bin/bash
HADOOP_HOME=/root/software/hadoop-3.3.0
PROCESS=("namenode.NameNode" "namenode.SecondaryNameNode" "DataNode" "ResourceManager" "NodeManager" "historyserver")
function check_process()
{
pid=$(ps -ef 2>/dev/null | grep -v grep | grep -i $1 | awk '{print $2}')
if [ -z "$pid" ]
then
echo "$1服务未启动"
else
echo "$1服务已启动"
fi
}
function process_start()
{
echo "启动dfs..."
${HADOOP_HOME}/sbin/start-dfs.sh
echo "启动yran..."
${HADOOP_HOME}/sbin/start-yarn.sh
echo "启动historyserver..."
${HADOOP_HOME}/bin/mapred --daemon start historyserver
}
function process_stop()
{
echo "停止dfs..."
${HADOOP_HOME}/sbin/stop-dfs.sh
echo "停止yran..."
${HADOOP_HOME}/sbin/stop-yarn.sh
echo "停止historyserver"
${HADOOP_HOME}/bin/mapred --daemon stop historyserver
}
case $1 in
"start")
process_start
;;
"stop")
process_stop
;;
"restart")
process_stop
sleep 2
process_start
;;
"status")
for process in ${PROCESS[@]};do
check_process ${process}
done
;;
*)
echo 参数无效!
echo '提示: '$(basename $0)' start|stop|restart|status'
;;
esac
自定义 hadoop 服务管理脚本
最新推荐文章于 2024-09-08 15:48:29 发布
本文档介绍了如何使用bash脚本管理和监控Hadoop集群,包括启动DFS、YARN服务,停止服务,以及检查各组件状态。通过'start', 'stop', 'restart', 'status' 命令实现Hadoop集群的便捷操作。
摘要由CSDN通过智能技术生成