ZK集群启动脚本(start-zk)

  1. cd /usr/local/bin
  2. sudo vi start-zk

脚本内容如下:

  1. #!/bin/bash
  2. ZOOKEEPER_HOME=/home/vagrant/modules/zookeeper-3.4.10
  3. # 启动Zookeeper
  4. echo "start zkServer-------------------------------------------------"
  5. for i in bigdata-node1 bigdata-node2 bigdata-node3
  6. do
  7. ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh start"
  8. done
  9. sleep 3s
  10. echo "start done..."
  11. # 检查Zookeeper状态
  12. echo "zkServer status------------------------------------------------"
  13. for i in bigdata-node1 bigdata-node2 bigdata-node3
  14. do
  15. echo ------------------- $i --------------
  16. ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh status"
  17. done
  18. exit 0

设置脚本执行权限:

  1. sudo chmod +x start-zk
  2. sudo chown vagrant:vagrant start-zk

ZK集群停止脚本(stop-zk)

  1. cd /usr/local/bin
  2. sudo vi stop-zk

脚本内容如下:

  1. #!/bin/bash
  2. ZOOKEEPER_HOME=/home/vagrant/modules/zookeeper-3.4.10
  3. echo "stop zkServer"
  4. for i in bigdata-node1 bigdata-node2 bigdata-node3
  5. do
  6. ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh stop"
  7. done
  8. sleep 3s
  9. echo "cluster jps status------------------------------------------------"
  10. jpsx
  11. exit 0

设置脚本执行权限:

  1. sudo chmod +x stop-zk
  2. sudo chown vagrant:vagrant stop-zk

ZK集群状态查看脚本(status-zk)

  1. cd /usr/local/bin
  2. sudo vi status-zk

脚本内容如下:

  1. #!/bin/bash
  2. ZOOKEEPER_HOME=/home/vagrant/modules/zookeeper-3.4.10
  3. # 检查Zookeeper状态
  4. echo "zkServer status------------------------------------------------"
  5. for i in bigdata-node1 bigdata-node2 bigdata-node3
  6. do
  7. echo ------------------- $i --------------
  8. ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh status"
  9. done
  10. exit 0

设置脚本执行权限:

  1. sudo chmod +x status-zk
  2. sudo chown vagrant:vagrant status-zk

分发(选做):

  1. # 使用root账户分发至其他节点
  2. sudo scp -r /usr/local/bin/*-zk root@bigdata-node2:/usr/local/bin/
  3. sudo scp -r /usr/local/bin/*-zk root@bigdata-node3:/usr/local/bin/