启动关闭zookeeper集群的脚本
启动hadoop Ha集群是,每次都要手动启动每个zk节点,实在是太麻烦了。于是乎自己写了个脚本startAllZK.sh:
需要启动的节点,先在 NODENAME_ARR 数组中配置好,zkServer.sh的路径改一下
#!/bin/bash NODENAME_ARR=('node1' 'node2' 'node3') echo '' >zk.log if [ $# -eq 0 ]; then echo -e "请带参数执行脚本.如:\n sh startAllZK.sh start \n sh startAllZK.sh stop\n" exit 1 fi if [ $1 == 'start' ] ;then for nodename in ${NODENAME_ARR[@]} doecho -n "${nodename}正在启动..." echo ${nodename} >> zk.log ssh $nodename 'export BASH_ENV=/etc/profile;/opt/zookeeper/bin/zkServer.sh start' >>zk.log 2>&1 if [ $? == 0 ];then echo " ${nodename}启动成功" else echo " ${nodename}启动" fi # sleep 2s done elif [ $1 == 'stop' ] ;then for nodename in ${NODENAME_ARR[@]} do echo -n "${nodename}正在关闭..." echo ${nodename} >> zk.log ssh $nodename '/opt/zookeeper/bin/zkServer.sh stop' >>zk.log 2>&1 if [ $? == 0 ];then echo " ${nodename}关闭成功" else echo " ${nodename}关闭失败" fi done fi