今天安裝配置三臺zookeeper服務集群,配置內容如下:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/var/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.249.97:2888:3888
server.2=192.168.249.157:2888:3888
server.1=192.168.249.187:2888:3888
安裝配置完畢后,逐一啟動三臺服務器
(1)master
(2)slave0
(3)slave1
集群中三個zookeeper服務顯示正常啟動。然后在master服務器使用的telnet 命令檢測集群工作狀態,
[root@master bin]# telnet 127.0.0.1 2181
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
stat
This ZooKeeper instance is not currently serving requests
Connection closed by foreign host.
[root@master bin]# This ZooKeeper instance is not currently serving requestsUnable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect。
顯示集群無法進行正常服務,后使用zkCli客戶端進行連接測試。
2018-06-08 23:05:37,441 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@1161] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
2018-06-08 23:05:38,673 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@1028] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
2018-06-08 23:05:38,674 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@878] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2018-06-08 23:05:38,677 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@1161] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
2018-06-08 23:05:39,571 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@1028] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2018-06-08 23:05:39,572 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@878] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2018-06-08 23:05:39,576 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@1161] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
2018-06-08 23:05:41,349 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@1028] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
2018-06-08 23:05:41,351 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@878] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2018-06-08 23:05:41,352 [myid:] - INFO? [main-SendThread(localhost:2181):ClientCnxn$SendThread@1161] - Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect
客戶端也顯示無法進行正常的服務。
這種情況原因是集群沒有能夠選舉出Leader,在啟動時正常已經啟動三個機器的zookeeper服務,因此,可能是防火墻導致zookeeper服務端口無法進行相互訪問。在集群中每臺機器中配置防火墻設置。
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=2888/tcp --permanent
firewall-cmd --zone=public --add-port=3888/tcp --permanent
firewall-cmd --reload
逐次重新啟動,zookeeper,OK。