在/root/bin的目录下创建 vim myhadoop.sh
并写入一下shell脚本
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit;
fi
case $1 in
"start")
echo " ==================== 启动 hadoop集群 ===================="
echo " ------------------- 启动 hdfs --------------------"
ssh hadoop102 "/opt/module/hadoop-3.1.3/sbin/start-dfs.sh"
echo " --------------------- 启动yarn -------------------"
ssh hadoop103 "/opt/module/hadoop-3.1.3/sbin/start-yarn.sh"
echo " --------------------- 启动 historyserver --------------------"
ssh hadoop102 "/opt/module/hadoop-3.1.3/bin/mapred --daemon start historyserver"
;;
"stop")
echo " ==================== 关闭 hadoop集群 ===================="
echo " -------------------- 关闭 hadoop集群 -------------------"
ssh hadoop102 "/opt/module/hadoop-3.1.3/bin/mapred --daemon stop historyserver"
echo " ------------------- 关闭 yarn --------------------"
ssh hadoop103 "/opt/module/hadoop-3.1.3/sbin/stop-yarn.sh"
echo " -------------------- 关闭 hdfs --------------------"
ssh hadoop102 "/opt/module/hadoop-3.1.3/sbin/stop-dfs.sh"
;;
*)
echo "Input Args Error..."
;;
esac
保存
之后只需要输入相应的 myhadoop.sh stop / myhadoop.sh start 即可完成停止和启动操作。