ZK集群启动脚本(start-zk)
cd /usr/local/bin
sudo vi start-zk
脚本内容如下:
#!/bin/bash
ZOOKEEPER_HOME=/home/vagrant/modules/zookeeper-3.4.10
# 启动Zookeeper
echo "start zkServer-------------------------------------------------"
for i in bigdata-node1 bigdata-node2 bigdata-node3
do
ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh start"
done
sleep 3s
echo "start done..."
# 检查Zookeeper状态
echo "zkServer status------------------------------------------------"
for i in bigdata-node1 bigdata-node2 bigdata-node3
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh status"
done
exit 0
设置脚本执行权限:
sudo chmod +x start-zk
sudo chown vagrant:vagrant start-zk
ZK集群停止脚本(stop-zk)
cd /usr/local/bin
sudo vi stop-zk
脚本内容如下:
#!/bin/bash
ZOOKEEPER_HOME=/home/vagrant/modules/zookeeper-3.4.10
echo "stop zkServer"
for i in bigdata-node1 bigdata-node2 bigdata-node3
do
ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh stop"
done
sleep 3s
echo "cluster jps status------------------------------------------------"
jpsx
exit 0
设置脚本执行权限:
sudo chmod +x stop-zk
sudo chown vagrant:vagrant stop-zk
ZK集群状态查看脚本(status-zk)
cd /usr/local/bin
sudo vi status-zk
脚本内容如下:
#!/bin/bash
ZOOKEEPER_HOME=/home/vagrant/modules/zookeeper-3.4.10
# 检查Zookeeper状态
echo "zkServer status------------------------------------------------"
for i in bigdata-node1 bigdata-node2 bigdata-node3
do
echo ------------------- $i --------------
ssh $i "source /etc/profile;${ZOOKEEPER_HOME}/bin/zkServer.sh status"
done
exit 0
设置脚本执行权限:
sudo chmod +x status-zk
sudo chown vagrant:vagrant status-zk
分发(选做):
# 使用root账户分发至其他节点
sudo scp -r /usr/local/bin/*-zk root@bigdata-node2:/usr/local/bin/
sudo scp -r /usr/local/bin/*-zk root@bigdata-node3:/usr/local/bin/