# output array to one line string: echo ${servers[@]}
# get length of array
len=${#servers[*]}
i=0
while [ $i -lt $len ]
do
let sid=i+1
destip=${ipaddrs[$i]}
destlogin=root@$destip
echo -e "<INFO> configuring server.$sid: $destip ...\c"
ret=`ssh $destlogin "yum install -y zookeeper zookeeper-server && service zookeeper-server init --myid=$sid"`
ret=`ssh $destlogin "echo '#!{{install_zookeeper@hgdb.net==>' >> $ZOO_CFG"`
for s in ${servers[*]}
do
ret=`ssh $destlogin "echo '$s' >> $ZOO_CFG"`
done
ret=`ssh $destlogin "echo '#!<==install_zookeeper@hgdb.net}}' >> $ZOO_CFG"`
echo -e "OK."
let i++
done
echo "<INFO> zookeeper cluster installation completed successfully!"
}
#=======================================================================
install_zookeeper "2181" "192.168.122.201" "192.168.122.202" "192.168.122.203"
根据配置修改最后一行:
install_zookeeper "2181" "192.168.122.201" "192.168.122.202" "192.168.122.203"
注意:需要把zk-cluster的每台机器上的防火墙停掉,再启动zookeeper:
$ /usr/lib/zookeeper/bin/zkServer.sh start-foreground
--------------------------------------分割线 --------------------------------------
分布式服务框架 ZooKeeper -- 管理分布式环境中的数据
--------------------------------------分割线 --------------------------------------