脚本内容以我搭建的hadoop集群为例,你们自用的时候自行根据你们的情况进行修改即可
hadoop-cluster-manager.sh
#!/bin/bash
# 1. 调用此脚本前,请使用ssh-keygen -t rsa、ssh-copy-id -f 目标机器这两个命令使得目标机器是免密登录的
# 2. ssh远程执行的命令,不会加载/etc/profile里面的全局变量,故需要手动执行if [ $# -lt 1 ]; thenecho "入参为空 == 请输入参数:start/stop/restart中的一个";
exit 1;
ficase $1 in"start")echo "集群启动中....."ssh root@hadoop107 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/start-dfs.sh'
echo "由【hadoop107】启动dfs集群组件"
ssh root@hadoop108 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/start-yarn.sh'
echo "由【hadoop108】启动yarn集群组件"
ssh root@hadoop107 'source /etc/profile && /opt/module/hadoop-3.3.6/bin/mapred --daemon start historyserver'
echo "由【hadoop108】启动日志聚集组件"echo "集群启动完成";;"stop")echo "集群停止中....."ssh root@hadoop107 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/stop-dfs.sh'
echo "由【hadoop107】关闭dfs集群组件"
ssh root@hadoop108 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/stop-yarn.sh'
echo "由【hadoop108】关闭yarn集群组件"
ssh root@hadoop107 'source /etc/profile && /opt/module/hadoop-3.3.6/bin/mapred --daemon stop historyserver'
echo "由【hadoop108】关闭日志聚集组件"echo "集群停止完成";;"restart")echo "集群重启中....."ssh root@hadoop107 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/stop-dfs.sh'
echo "由【hadoop107】关闭dfs集群组件"
ssh root@hadoop108 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/stop-yarn.sh'
echo "由【hadoop108】关闭yarn集群组件"
ssh root@hadoop107 'source /etc/profile && /opt/module/hadoop-3.3.6/bin/mapred --daemon stop historyserver'
echo "由【hadoop108】关闭日志聚集组件"ssh root@hadoop107 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/start-dfs.sh'
echo "由【hadoop107】启动dfs集群组件"
ssh root@hadoop108 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/start-yarn.sh'
echo "由【hadoop108】启动yarn集群组件"
ssh root@hadoop107 'source /etc/profile && /opt/module/hadoop-3.3.6/bin/mapred --daemon start historyserver'
echo "由【hadoop108】启动日志聚集组件"echo "集群重启完成";;*)echo "无效参数 == 请输入参数:start/stop/restart中的一个";;;esac