kafka-zookeeper-shell脚本样例
1.同步文件脚本 xsync
#!/bin/bash #1. 判断参数个数 if [ $# -lt 1 ] then echo Not Enough Arguement! exit; fi #2. 遍历集群所有机器 for host in hadoop01 hadoop02 hadoop03 do echo ==================== $host ==================== #3. 遍历所有目录,挨个发送 for file in $@ do #4. 判断文件是否存在 if [ -e $file ] then #5. 获取父目录 pdir=$(cd -P $(dirname $file); pwd) #6. 获取当前文件的名称 fname=$(basename $file) ssh $host "mkdir -p $pdir" rsync -av $pdir/$fname $host:$pdir else echo $file does not exists! fi done done
2.zookeeper启动脚本
#!/bin/bash case $1 in "start"){ for i in hadoop01 hadoop02 hadoop03 do echo ------------- zookeeper $i 启动 ------------ ssh $i "/home/hadoop/opt/zookeeper3.5.7/bin/zkServer.sh start" done } ;; "stop"){ for i in hadoop01 hadoop02 hadoop03 do echo ------------- zookeeper $i 停止 ------------ ssh $i "/home/hadoop/opt/zookeeper3.5.7/bin/zkServer.sh stop" done } ;; "status"){ for i in hadoop01 hadoop02 hadoop03 do echo ------------- zookeeper $i 状态 ------------ ssh $i "/home/hadoop/opt/zookeeper3.5.7/bin/zkServer.sh status" done } ;; esac
3.xcall 查看jps
#!/bin/bash for host in hadoop01 hadoop02 hadoop03 do echo =============== $host =============== ssh $host jps done
4.kafka启动脚本
#!/bin/bash case $1 in "start") for i in hadoop01 hadoop02 hadoop03 do echo "=============== 启动 $i kafka ===============" ssh $i "/home/hadoop/opt/kafka3.0.0/bin/kafka-server-start.sh -daemon /home/hadoop/opt/kafka3.0.0/config/server.properties" done ;; "stop") for i in hadoop01 hadoop02 hadoop03 do echo "=============== 停止 $i kafka ===============" ssh $i "/home/hadoop/opt/kafka3.0.0/bin/kafka-server-stop.sh -daemon /home/hadoop/opt/kafka3.0.0/config/server.properties" done ;; esac