zookeeper集群
源码安装至/usr/local/zookeeper
配置 /usr/local/zookeeper/conf/zoo.cfg
server.1=node1:2888:3888 server.2=node2:2888:3888 server.3=node3:2888:3888 server.4=nn01:2888:3888:observer
拷贝安装目录至所有集群主机
rsync -aSH --delete /usr/local/zookeeper node1:/usr/local/
...
创建myid文件,id必须与配置文件里主机名对应的server.(id)一致
[root@nn01 local]# echo 4 > /tmp/zookeeper/myid [root@nn01 local]# ssh node3 'echo 3 >/tmp/zookeeper/myid' [root@nn01 local]# ssh node2 'echo 2 >/tmp/zookeeper/myid' [root@nn01 local]# ssh node1 'echo 1 >/tmp/zookeeper/myid'
所有集群主机启动服务
/usr/local/zookeeper/bin/zkServer.sh start
/usr/local/zookeeper/bin/zkServer.sh status # 查看状态
确认主机状态
[root@nn01 local]# echo 'ruok' | socat - TCP:node3:2181 imok[root@nn01 local]#
[root@nn01 local]# echo 'stat' | socat - TCP:node3:2181
脚本
#!/bin/bash function get_zkstat(){ exec 2</dev/null 8<>/dev/tcp/$1/2181 echo "stat" >&8 _S=$(cat <&8|grep -Po "^Mode:.*") echo -e "$1\t${_S:-Mode: NULL}" exec 8<&- } if (( $# == 0 ));then echo "Usage: $0 host1 host2 host3 ... ..." else for i in $@;do get_zkstat ${i};done fi
[root@nn01 local]# sh /root/zkstatus.sh node{1..3} nn01 node1 Mode: follower node2 Mode: follower node3 Mode: leader nn01 Mode: observer