背景
由于zookeeper的服务启动和停止,需要一台一台地去启动和停止。当部署的zookeeper节点多时非常麻烦,所以编写下面的脚本,用于提升启动和停止的效率。
执行如下脚本需要确保:脚本存放的服务器与所有的zookeeper节点直接可以免密登录(服务器之间建立互信)。
1、编辑脚本
vi manage-zookeeper.sh
#!/bin/bash zookeeper_home=/usr/local/zookeeper zookeeper_array=(hadoop01 hadoop02 hadoop03) ## 启动和停止Zookeeper function zookeeper_operate(){ zookeeper_operate=$@ if [[ ${zookeeper_operate} == "status" ]] then echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "About to check zookeeper status ...." sleep 5 fi echo "****************************************Zookeeper ${zookeeper_operate}*******************************************" for zookeeper_node in ${zookeeper_array[@]} do echo "======================${zookeeper_node} ${zookeeper_operate}========================" ssh ${zookeeper_node} "source /etc/profile;${zookeeper_home}/bin/zkServer.sh ${zookeeper_operate}" if [[ ${zookeeper_node} == "stop" ]] then ssh ${zookeeper_node} "rm -rf ${zookeeper}/logs/* " fi done } echo "=======Start Zookeeper cluster,please intput : start or 1 ======" echo "=======Stop Zookeeper cluster,please intput : stop or 0 ======" read -p "please input : " inputStr case ${inputStr} in start|START|1) ## 启动zookeeper zookeeper_operate start ## 检查所有节点的状态 zookeeper_operate status ;; stop|STOP|0) zookeeper_operate stop zookeeper_operate status ;; *) echo "Input wrong,please check!" break esac
2、启动zookeeper
sh manage-zookeeper.sh
输入start或者1,即可启动zookeeper
3、停止zookeeper
sh manage-zookeeper.sh
输入stop或者0,即可停止zookeeper。
标签:zookeeper,Zookeeper,stop,echo,sh,operate,节点 From: https://www.cnblogs.com/yeyuzhuanjia/p/18025531