集群分发脚本:xsync
#!/bin/bash #1 获取输入参数个数,如果没有参数,直接退出 pcount=$# if((pcount==0)); then echo no args; exit; fi #2 获取文件名称 p1=$1 fname=`basename $p1` echo fname=$fname #3 获取上级目录到绝对路径 pdir=`cd -P $(dirname $p1); pwd` echo pdir=$pdir #4 获取当前用户名称 user=`whoami` #5 循环 for((host=103; host<105; host++)); do echo ------------------- hadoop$host -------------- rsync -rvl $pdir/$fname $user@hadoop$host:$pdir done
jps: util.sh
#!/bin/bash for i in lxl@hadoop102 lxl@hadoop103 lxl@hadoop104 do echo "================ $i ================" ssh $i '/opt/module/jdk1.8.0_144/bin/jps' done
群起ZK脚本:
#!/bin/bash for i in lxl@hadoop102 lxl@hadoop103 lxl@hadoop104 do echo "================ $i ================" ssh $i '/opt/module/zookeeper-3.4.10/bin/zkServer.sh start' done
Kafka群起脚本:
#!/bin/bash for((i=102;i<105;i++)) do echo ----------hadoop$i---------- ssh lxl@hadoop$i 'source /etc/profile && /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties' done
Kafka群关脚本:
#!/bin/bash for((i=102;i<105;i++)) do echo ----------hadoop$i---------- ssh lxl@hadoop$i 'source /etc/profile && /opt/module/kafka/bin/kafka-server-stop.sh' done
群起hadoop相关进程脚本:
#!/bin/bash echo "================ 开始启动所有节点服务 ===========" echo "================ 正在启动Zookeeper ===========" for i in lxl@hadoop102 lxl@hadoop103 lxl@hadoop104 do ssh $i '/opt/module/zookeeper-3.4.10/bin/zkServer.sh start' done echo "================ 正在启动HDFS ===========" ssh lxl@hadoop102 '/opt/module/hadoop-2.7.2/sbin/start-dfs.sh' echo "================ 正在启动YARN ===========" ssh lxl@hadoop103 '/opt/module/hadoop-2.7.2/sbin/start-yarn.sh' echo "================ 正在开启JobHistoryServer ===========" ssh lxl@hadoop102 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh start historyserver'
群关ZK以及hadoop相关进程脚本:
#!/bin/bash echo "================ 开始关闭所有节点服务 ===========" echo "================ 正在关闭Zookeeper ===========" for i in lxl@hadoop102 lxl@hadoop103 lxl@hadoop104 do ssh $i '/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop' done echo "================ 正在关闭HDFS ===========" ssh lxl@hadoop102 '/opt/module/hadoop-2.7.2/sbin/stop-dfs.sh' echo "================ 正在关闭YARN ===========" ssh lxl@hadoop103 '/opt/module/hadoop-2.7.2/sbin/stop-yarn.sh' echo "================ 正在关闭JobHistoryServer ===========" ssh lxl@hadoop102 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh stop historyserver'
HADOOP群起脚本
echo "=====================正在开启datanode节点========================" for i in root@hadoop101 root@hadoop102 root@hadoop103 do ssh $i '/opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh start datanode' done echo "=====================正在开启secondarynamenode节点========================" ssh root@hadoop103 '/opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh start secondarynamenode' echo "=====================正在开启ResourceManager节点========================" ssh root@hadoop102 '/opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh start resourcemanager' echo "=====================正在开启nodeManager节点========================" for i in root@hadoop101 root@hadoop102 root@hadoop103 do ssh $i '/opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh start datamanager' done echo "=============================正在启动Yarn===============================" ssh root@hadoop101 '/opt/module/hadoop-2.7.2/sbin/start-yarn.sh' echo "=====================正在开启jobhistoryServer节点========================" ssh root@hadoop101 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh start historyserver' echo "=====================正在启动zookeeper节点========================" for i in root@hadoop101 root@hadoop102 root@hadoop103 do ssh $i '/opt/module/zookeeper-3.4.10/bin/zkServer.sh start' done done done
群关闭脚本
#!/bin/bash echo "=====================正在关闭集群服务============================" echo "=====================正在关闭zookeeper节点========================" for i in root@hadoop101 root@hadoop102 root@hadoop103 do ssh $i '/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop' done echo "=====================正在关闭jobhistoryServer节点========================" ssh root@hadoop101 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh stop historyserver' echo "=====================正在关闭ResourceManager节点========================" ssh root@hadoop102 '/opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh stop resourcemanager' echo "=====================正在关闭nodeManager节点========================" for i in root@hadoop101 root@hadoop102 root@hadoop103 do ssh $i '/opt/module/hadoop-2.7.2/sbin/yarn-daemon.sh stop datamanager' done echo "=====================正在关闭secondarynamenode节点========================" ssh root@hadoop103 '/opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh stop secondarynamenode' echo "=====================正在关闭namenode节点========================" ssh root@hadoop101 '/opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh stop namenode' echo "=====================关闭datanode节点========================" for i in root@hadoop101 root@hadoop102 root@hadoop103 do ssh $i '/opt/module/hadoop-2.7.2/sbin/hadoop-daemon.sh stop datanode' done echo "=====================关闭Yarn节点========================" for i in root@hadoop101 root@hadoop102 root@hadoop103 do ssh $i '/opt/module/hadoop-2.7.2/sbin/stop-yarn.sh' done