shell
#!/bin/bash
process=("NameNode" "SecondaryNameNode" "DataNode" "NodeManager" "ResourceManager")
JAVA_HOME="/opt/software/jdk1.8.0_371"
HADOOP_HOME="/opt/software/hadoop-3.3.6"
# 定义颜色的ANSI转义序列
red='\033[31m'
green='\033[32m'
yellow='\033[33m'
reset='\033[0m'
function checkProcess {
# 拿到进程号
processID=`${JAVA_HOME}/bin/jps | grep -w ${1} | grep -v grep | awk '{print $1}'`
if [[ -z $processID ]]; then
echo -e "${red}${1} 运行异常${reset}"
else
echo -e "${green}${1} 正在运行,进程 ${processID}${reset}"
fi
}
case $1 in
start )
echo "正在启动 HDFS..."
`$HADOOP_HOME/sbin/start-dfs.sh > /dev/null 2>&1`
echo "正在启动 YARN..."
`$HADOOP_HOME/sbin/start-yarn.sh > /dev/null 2>&1`
;;
stop )
echo "正在停止 HDFS..."
`$HADOOP_HOME/sbin/stop-dfs.sh > /dev/null 2>&1`
echo "正在停止 YARN..."
`$HADOOP_HOME/sbin/stop-yarn.sh > /dev/null 2>&1`
;;
status )
for i in ${process[@]}; do
#statements
checkProcess ${i}
done
;;
* )
echo "参数不正确 hadoop-service.sh start|stop|status"
;;
esac