赞
踩
脚本内容以我搭建的hadoop集群为例,你们自用的时候自行根据你们的情况进行修改即可
hadoop-cluster-manager.sh
#!/bin/bash # 1. 调用此脚本前,请使用ssh-keygen -t rsa、ssh-copy-id -f 目标机器这两个命令使得目标机器是免密登录的 # 2. ssh远程执行的命令,不会加载/etc/profile里面的全局变量,故需要手动执行 if [ $# -lt 1 ]; then echo "入参为空 == 请输入参数:start/stop/restart/jps中的一个"; exit 1; fi case $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 "由【hadoop107】启动日志聚集组件" echo "集群启动完成" ;; "stop") echo "集群停止中....." ssh root@hadoop107 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/stop-dfs.sh' echo -e "由【hadoop107】关闭dfs集群组件" ssh root@hadoop108 'source /etc/profile && bash /opt/module/hadoop-3.3.6/sbin/stop-yarn.sh' echo -e "由【hadoop108】关闭yarn集群组件" ssh root@hadoop107 'source /etc/profile && /opt/module/hadoop-3.3.6/bin/mapred --daemon stop historyserver' echo -e "由【hadoop107】关闭日志聚集组件" 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 "由【hadoop107】关闭日志聚集组件" 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 "由【hadoop107】启动日志聚集组件" echo "集群重启完成" ;; "jps") echo -e "查看集群Java进程中.....\n" ssh root@hadoop107 'source /etc/profile && jps' echo -e "查看【hadoop107】进程结束\n\n" ssh root@hadoop108 'source /etc/profile && jps' echo -e "查看【hadoop108】进程结束\n\n" ssh root@hadoop109 'source /etc/profile && jps' echo -e "查看【hadoop109】进程结束\n\n" echo "查看集群Java进程结束" ;; *) echo "无效参数 == 请输入参数:start/stop/restart/jps中的一个"; ;; esac
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。