啓動關閉zookeeper集羣的腳本

啓動hadoop Ha集羣是,每次都要手動啓動每一個zk節點,實在是太麻煩了。因而乎本身寫了個腳本startAllZK.sh:node

須要啓動的節點,先在 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
相關文章
相關標籤/搜索