Zookeeper is a distributed open source framework that provides basic services for coordinating distributed applications, exposing a common set of services to external applications-distributed synchronization (distributed synchronization), naming services (naming service), Cluster maintenance (Group maintenance) simplifies the coordination and management of distributed applications and provides high-performance distributed services. Zookeeper itself can be installed in standalone mode, but its advantage is that through a distributed zookeeper cluster (a leader, multiple follower), based on a certain policy to ensure the stability and availability of zookeeper cluster, Thus, the reliability of distributed applications is realized.
There are three main hosts:
Host name |
IP Address |
ZooKeeper |
myID |
Slave-01 |
10.73.150.4 |
Server.1 |
1 |
slave-02 |
10.73.150.54 |
Server.2 |
2 |
slave-03 |
10.73.150.197 |
Server.3 |
3 |
First, host name to IP address mapping configuration
There are two key roles in the Zookeeper cluster: leader and follower. All the nodes in the cluster serve the distributed application as a whole, and each node in the cluster is connected to each other, so when the zookeeper cluster is configured, the mapping of the host to IP address of each node is configured on the mapping information of the other nodes in the cluster.
For example, for the configuration of each node in my zookeeper cluster, take slave-01 as an example, the/etc/hosts content is as follows:
[root@slave-01 ~]# cat/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 Localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.73.150.4 slave-01
10.73.150.54 slave-02
10.73.150.197 slave-03
Zookeeper employs an election algorithm called leader election. In the whole cluster running process, there is only one leader, the other is follower, if the zookeeper cluster in the process of leader the problem, the system will use this algorithm to re-select a leader. Therefore, the above mappings must be configured to ensure that each node is connected to each other.
When the zookeeper cluster starts, a leader is selected first, and in the leader election process, a node that satisfies the election algorithm can become leader. The architecture of the entire cluster can refer to http://zookeeper.apache.org/doc/trunk/zookeeperOver.html#sc_designGoals. Second, modify the zookeeper configuration file
For installation of stand-alone zookeeper please refer to: Zookeeper series-linux Installation
On one of the machines (slave-01), install zookeeper, and modify the configuration file Conf/zoo.cfg, as shown in the following:
[root@slave-01 conf]# vim zoo.cfg
ticktime=2000
datadir=/usr/local/zookeeper-3.4.11/data
dataLogDir=/ Usr/local/zookeeper-3.4.11/log
clientport=2181
initlimit=5
synclimit=2
server.1=slave-01 : 2888:3888
server.2=slave-02:2888:3888
server.3=slave-03:2888:3888
Note : Create the appropriate directory.
The above configuration content description, can refer to Http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html#sc_RunningReplicatedZooKeeper. III. remote replication distribution installation files
The above has been configured on a machine slave-01 to complete the zookeeper, you can now remotely copy the configured installation files to each node in the cluster corresponding to the directory:
[root@slave-01 local]# pwd
/usr/local
[root@slave-01 local]# ll | grep "Zookeeper"
drwxr-xr-x 12< c17/>502 Games 4096 November 14:11 zookeeper-3.4.11
[root@slave-01 local]# scp-r zookeeper-3.4.11/root@slave-02:/usr /local/
iv. Setting myID
Under the directory specified by the DATADIR we configured, create a myID file with a number that identifies the current host, the conf/zoo.cfg in the server.x configured in the file, and the number in the myID file, for example:
[Root@slave-01 data]# echo "1" >/usr/local/zookeeper-3.4.11/data/myid
[root@slave-02 data]# echo "2" >/usr/ Local/zookeeper-3.4.11/data/myid
[root@slave-03 data]# echo "3" >/usr/local/zookeeper-3.4.11/data/myid
v. Start zookeeper cluster
On each node of the zookeeper cluster, execute the script that starts the Zookeeper service as follows:
[root@slave-01 ~]#/usr/local/zookeeper-3.4.11/bin/zkserver.sh start
[root@slave-02 ~]#/usr/local/ zookeeper-3.4.11/bin/zkserver.sh start
[root@slave-03 ~]#/usr/local/zookeeper-3.4.11/bin/zkserver.sh start
In the case of node slave-01, the log is as follows:
[root@slave-01 bin]# tail-f zookeeper.out 2017-11-30 14:44:44,812 [myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2 181:QUORUMCNXMANAGER@584]-Cannot open channel to 3 at election address slave-03/10.73.150.197:3888 Java.net.ConnectExce Ption: Reject connection (Connection refused) at Java.net.PlainSocketImpl.socketConnect (Native Method) at Java.net.Abst Ractplainsocketimpl.doconnect (abstractplainsocketimpl.java:350) at Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:206) at Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:188) at Java.net.SocksSocketImpl.connect ( sockssocketimpl.java:392) at Java.net.Socket.connect (socket.java:589) at Org.apache.zookeeper.server.quoru M.quorumcnxmanager.connectone (quorumcnxmanager.java:558) at Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:610) at Org.apache.zookeeper.server.quorum.fastleaderelection.lOokforleader (fastleaderelection.java:845) at Org.apache.zookeeper.server.quorum.QuorumPeer.run (Quorumpeer.java : 957) 2017-11-30 14:44:44,813 [myid:1]-INFO [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumpeer$quorumserver@184]- Resolved hostname:slave-03 to address:slave-03/10.73.150.197 2017-11-30 14:44:44,813 [myid:1]-INFO [QuorumPeer[myid=1 ]/0:0:0:0:0:0:0:0:2181:FASTLEADERELECTION@854]-Notification time out:12800 2017-11-30 14:44:57,620 [myid:1]-WARN [Qu ORUMPEER[MYID=1]/0:0:0:0:0:0:0:0:2181:QUORUMCNXMANAGER@584]-Cannot open channel to 2 at election address slave-02/ 10.73.150.54:3888 java.net.ConnectException: Deny connection (Connection refused) at Java.net.PlainSocketImpl.socketConnect (N Ative Method) at Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:350) at java.net. Abstractplainsocketimpl.connecttoaddress (abstractplainsocketimpl.java:206) at Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:188) at Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392) at Java.net.Socket.connect (socket.java:589 ) at Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:558) at Org.apac He.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:610) at Org.apache.zookeeper.server . Quorum. Fastleaderelection.lookforleader (fastleaderelection.java:845) at Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:957) 2017-11-30 14:44:57,622 [myid:1]-INFO [ QUORUMPEER[MYID=1]/0:0:0:0:0:0:0:0:2181:QUORUMPEER$QUORUMSERVER@184]-resolved hostname:slave-02 to address: slave-02/10.73.150.54 2017-11-30 14:44:57,627 [myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181: QUORUMCNXMANAGER@584]-Cannot open channel to 3 at election address slave-03/10.73.150.197:3888 Java.net.ConnectExceptio N: Reject connection (Connection refused) at Java.net.PlainSocketImpl.socketConnect (Native Method) at JAva.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:350) at Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:206) at Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:188) at Java.net.SocksSocketImpl.connect ( sockssocketimpl.java:392) at Java.net.Socket.connect (socket.java:589) at Org.apache.zookeeper.server.quoru M.quorumcnxmanager.connectone (quorumcnxmanager.java:558) at Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:610) at Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:845) at Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:957) 2017-11-30 14:44:57,634 [myid:1]-INFO [ QUORUMPEER[MYID=1]/0:0:0:0:0:0:0:0:2181:QUORUMPEER$QUORUMSERVER@184]-resolved hostname:slave-03 to address: slave-03/10.73.150.197 2017-11-30 14:44:57,635 [myid:1]-INFO [quorumpeer[MYID=1]/0:0:0:0:0:0:0:0:2181:FASTLEADERELECTION@854]-Notification time out:25600 2017-11-30 14:45:02,228 [Myid:1]-
INFO [slave-01/10.73.150.4:3888:quorumcnxmanager$listener@743]-Received connection request/10.73.150.54:34976 2017-11-30 14:45:02,237 [Myid:1]-INFO [workerreceiver[myid=1]:fastleaderelection@602]-notification:1 (message forma
T version), 2 (N.leader), 0x0 (N.ZXID), 0x1 (N.round), looking (n.state), 2 (N.SID), 0x1 (N.peerepoch) looking (my state) 2017-11-30 14:45:02,249 [Myid:1]-INFO [workerreceiver[myid=1]:fastleaderelection@602]-notification:1 (message forma
T version), 2 (N.leader), 0x0 (N.ZXID), 0x1 (N.round), looking (n.state), 1 (n.sid), 0x1 (N.peerepoch) looking (my state) 2017-11-30 14:45:02,260 [Myid:1]-WARN [workersender[myid=1]:quorumcnxmanager@584]-Cannot open channel to 3 at Electio N Address slave-03/10.73.150.197:3888 java.net.ConnectException: Deny connection (Connection refused) at Java.net.PlainSocket
Impl.socketconnect (Native Method) At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:350) at Java.net.AbstractPlainSock Etimpl.connecttoaddress (abstractplainsocketimpl.java:206) at Java.net.AbstractPlainSocketImpl.connect ( abstractplainsocketimpl.java:188) at Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392) at Java.ne T.socket.connect (socket.java:589) at Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne ( quorumcnxmanager.java:558) at Org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend (Quorumcnxmanager.java : 534) at Org.apache.zookeeper.server.quorum.fastleaderelection$messenger$workersender.process (FastLeaderElection . java:454) at Org.apache.zookeeper.server.quorum.fastleaderelection$messenger$workersender.run ( fastleaderelection.java:435) at Java.lang.Thread.run (thread.java:748) 2017-11-30 14:45:02,260 [myid:1]-INFO [Wo RKERSENDER[MYID=1]:QUORUMPEER$QUORUMSERVER@184]-Resolved hostname:slave-2017-11-30 to address:slave-03/10.73.150.197 14:45:02,462 [myid:1]-INFO [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181: QUORUMPEER@979]-Following 2017-11-30 14: