具体代码
用法
切换普通用户后在目录创建my_hadoop.sh,添加内容
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start")
echo " =================== 启动 hadoop集群 ==================="
echo " --------------- 启动 hdfs ---------------"
ssh hadoop21 "/opt/module/hadoop-3.1.3/sbin/start-dfs.sh"
echo " --------------- 启动 yarn ---------------"
ssh hadoop22 "/opt/module/hadoop-3.1.3/sbin/start-yarn.sh"
echo " --------------- 启动 历史服务器 ---------------"
ssh hadoop11 "mapred --daemon start historyserver"
;;
"stop")
echo " =================== 关闭 hadoop集群 ==================="
echo " --------------- 关闭 yarn ---------------"
ssh hadoop22 "/opt/module/hadoop-3.1.3/sbin/stop-yarn.sh"
echo " --------------- 关闭 hdfs ---------------"
ssh hadoop21 "/opt/module/hadoop-3.1.3/sbin/stop-dfs.sh"
echo " --------------- 停止 历史服务器 ---------------"
ssh hadoop11 "mapred --daemon stop historyserver"
;;
"restart")
echo " =================== 重启 hadoop集群 ==================="
echo " --------------- 关闭 yarn ---------------"
ssh hadoop22 "/opt/module/hadoop-3.1.3/sbin/stop-yarn.sh"
echo " --------------- 关闭 hdfs ---------------"
ssh hadoop21 "/opt/module/hadoop-3.1.3/sbin/stop-dfs.sh"
echo " --------------- 停止 历史服务器 ---------------"
ssh hadoop11 "mapred --daemon stop historyserver"
echo " --------------- 启动 hdfs ---------------"
ssh hadoop21 "/opt/module/hadoop-3.1.3/sbin/start-dfs.sh"
echo " --------------- 启动 yarn ---------------"
ssh hadoop22 "/opt/module/hadoop-3.1.3/sbin/start-yarn.sh"
echo " --------------- 启动 历史服务器 ---------------"
ssh hadoop21 "mapred --daemon start historyserver"
;;
*)
echo "Input Args Error..."
;;
esac
添加权限
sudo chmod +x ~/bin/my_hadoop.sh
创建软连接
sudo ln -s ~/bin/my_hadoop.sh /bin/my_hadoop