参考文档:

https://my.oschina.net/u/3754001/blog/1802140
此处省略安装搭建过程

一、 网络环境

Zookeeper 之  集群搭建

备注:

当前为三节点服务器,可允许损坏一个,群集状态正常,还可以提供正常服务,如损坏节点两个,只剩下一个节点,整个zookeeper服务中断,无法连接。

二、查看当前服务器所属状态

[root@ops-site zookeeper]# ./bin/zkServer.sh status
JMX enabled by default
Using config: /app/zookeeper/bin/../conf/zoo.cfg
Mode: follower         #当前状态为follwer

[root@nbutest zookeeper]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:50:56:AA:87:1A  
          inet addr:10.3.151.34  Bcast:10.3.151.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:feaa:871a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:296878910 errors:0 dropped:0 overruns:0 frame:0
          TX packets:101828532 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:113708004182 (105.8 GiB)  TX bytes:40542901999 (37.7 GiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:4575037 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4575037 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:442475408 (421.9 MiB)  TX bytes:442475408 (421.9 MiB)

[root@nbutest zookeeper]# ./bin/zkServer.sh status
JMX enabled by default
Using config: /app/zookeeper/bin/../conf/zoo.cfg
Mode: leader         #当前为leader状态

三、连接zookeeper服务器(群集状态下可连任意一台)

[root@nbutest zookeeper]# ./bin/zkCli.sh -server 10.3.151.34:2181      #连接方法
Connecting to 10.3.151.34:2181

四、创建一个znode节点

[zk: 10.3.151.34:2181(CONNECTED) 0] create /mingkang test   
Created /mingkang        #创建了一个/mingkang znode节点

五、查看当前所有节点情况

[zk: 10.3.151.34:2181(CONNECTED) 1] ls /          #查看所有情况
[bb, cc, path, test, zookeeper, mingkang, bear, hehe, kang]