shell 一键启动zookeeper集群

#!/bin/bash
if [ $# -lt 1 ];then
  echo "invalid param"
  exit
fi

hosts=(node1 node2 node3)

# 判断第二个参数是否在hosts数组中
contains(){
	n=1
	for i in ${hosts[*]}
	do
	  if [ "$1" = "$i" ];then
		n=0
	  fi
	done
	echo $n
}
case $1 in
	"start"){
		for i in ${hosts[*]}
		do
			echo ---------- zookeeper $i 启动 ------------
			ssh $i "/export/server/zookeeper-3.4.6/bin/zkServer.sh start"
		done
	};;
	"stop"){
		for i in ${hosts[*]}
		do
			echo ---------- zookeeper $i 停止 ------------ 
			ssh $i "/export/server/zookeeper-3.4.6/bin/zkServer.sh stop"
		done
	};;
	"status"){
		for i in ${hosts[*]}
		do
			echo ---------- zookeeper $i 状态 ------------ 
			ssh $i "/export/server/zookeeper-3.4.6/bin/zkServer.sh status"
		done
	};;
    "client")
		if [ $# -ne 2 ];then
		  echo "need two params, but given $#"
		  exit
		elif [ $(contains $2) -eq 1 ];then
		  echo "second param error: $2"
		  exit
		fi
		echo ---------- 连接客户端zookeeper $2  ------------
		/export/server/zookeeper-3.4.6/bin/zkCli.sh  -server $2:2181
		;;
	*)
		echo ---------- param $* invalid ------------
		;;
esac

上一篇:jar包在CentOS中启动时遭遇蜗牛般的速度


下一篇:域名解析文件地址