Reference: Dragon Fruit College http://www.roncoo.com/share.html?hamc=hLPG8QsaaWVOl2Z76wpJHp3JBbZZF%2Bywm5vEfPp9LbLkAjAnB% 2bnhpf8rhqmasz9u%2ff1cck%2fi%2bowuj8pvcwcq6a%3d%3d
Dubbo recommends using Zookeeper as the registry for services
As long as more than half of the nodes in the Zookeeper cluster are normal, then the entire cluster is available externally. It is based on this feature that the number of nodes in the ZK cluster should be odd (2n+1:3, 5, 7 nodes) is more appropriate.
ZooKeeper and Dubbo Service Cluster architecture diagram
Server 1:192.168.1.81 port: 2181, 2881, 3881
Server 2:192.168.1.82 port: 2182, 2882, 3882
Server 3:192.168.1.83 port: 2183, 2883, 3883
1, modify the operating system/etc/hosts file, add IP and host name Mapping:
# Zookeeper Cluster servers
192.168.1.81 edu-zk-01
192.168.1.82 edu-zk-02
192.168.1.83 edu-zk-03
[Root@edu-zk-01 root]# cat/etc/hosts | grep edu
192.168.1.81 edu-zk-01
[Root@edu-zk-01 root]#
[Root@edu-zk-02 ~]# cat/etc/hosts | grep edu
192.168.1.82 edu-zk-02
[Root@edu-zk-02 ~]#
2. Download or upload zookeeper-3.4.6.tar.gz to/home/yxq/zookeeper directory
[Root@edu-zk-01 root]# Clear
[Root@edu-zk-01 root]# Cd/home/yxq/zookeeper
[Root@edu-zk-01 zookeeper]# wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
[Root@edu-zk-02 ~]# Mkdir/home/yxq/zookeeper
[Root@edu-zk-02 ~]# cd/home/yxq/zookeeper/
[Root@edu-zk-02 zookeeper]# wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
3. Unzip the zookeeper installation package and rename the Zookeeper directory by node number:
server 1 [root@edu-zk-01 zookeeper]# tar-zxvf zookeeper-3.4.6.tar.gz
[root@edu-zk-01 zookeeper]# MV zookeeper-3.4.6 node-01
Server 2:
[Root@edu-zk-02 zookeeper]# TAR-ZXVF zookeeper-3.4.6.tar.gz
[root@edu-zk-02 zookeeper]# MV zookeeper-3.4.6 node-02
Server 3:
[Root@edu-zk-03 ~]# Cd/home/yxq/zookeeper
[Root@edu-zk-03 zookeeper]# wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
[Root@edu-zk-03 zookeeper]# TAR-ZXVF zookeeper-3.4.6.tar.gz
[root@edu-zk-03 zookeeper]# MV zookeeper-3.4.6 node-03
4. Create the following directory under each zookeeper node directory: [root@edu-zk-01 zookeeper]# CD node-01/
[Root@edu-zk-01 node-01]# mkdir data
[Root@edu-zk-01 node-01]# mkdir logs
[Root@edu-zk-02 zookeeper]# CD node-02/
[Root@edu-zk-02 node-02]# mkdir data
[Root@edu-zk-02 node-02]# mkdir logs
[root@edu-zk-03 zookeeper]# CD node-03/
[root@edu-zk-03 node-03]# mkdir data
[Root@edu-zk-03 node-03]# mkdir logs
Copy the Zoo_sample.cfg file under the zookeeper/node-0x/conf directory, named Zoo.cfg [root@edu-zk-01 node-01]# CD conf
[root@edu-zk-01 conf]# CP zoo_sample.cfg zoo.cfg
[root@edu-zk-02 node-02]# CD conf
[root@edu-zk-02 conf]# CP zoo_sample.cfg zoo.cfg
[root@edu-zk-03 node-03]# CD conf
[root@edu-zk-03 conf]# CP zoo_sample.cfg zoo.cfg
6. Modify the Zoo.cfg configuration file:
The configuration of the zookeeper/node-01 (/HOME/YXQ/ZOOKEEPER/NODE-01/CONF/ZOO.CFG) is as follows:
The configuration of the zookeeper/node-02 (/HOME/YXQ/ZOOKEEPER/NODE-02/CONF/ZOO.CFG) is as follows:
The configuration of the zookeeper/node-03 (/HOME/YXQ/ZOOKEEPER/NODE-03/CONF/ZOO.CFG) is as follows:
Parameter description:
ticktime=2000
Ticktime this time is the time interval between the Zookeeper server or between the client and the server to maintain the heartbeat, i.e. every
A ticktime time will send a heartbeat.
initlimit=10
Initlimit This configuration item is used to configure the Zookeeper accept client (which is referred to as the client is not a user connection Zookeeper
The server's client, but the Follower server that is connected to Leader in the Zookeeper server cluster, initializes the connection with the longest
The number of heartbeat intervals that can be tolerated. When the length of time (i.e. Ticktime) has exceeded 10 heartbeats, the Zookeeper
Service has not received the return information from the client, the client connection failed. The total length of time is 10*2000=20 seconds.
Synclimit=5
Synclimit This configuration item identifies the message that is sent between Leader and Follower, the length of the request and response, and the maximum amount of time
A ticktime length of time, the total length of time is 5*2000=10 seconds.
Datadir=/home/yxq/zookeeper/node-01/data
DataDir as the name implies is Zookeeper to save the data directory, by default Zookeeper will write the data log file is also stored in this directory.
clientport=2181
ClientPort This port is the port that the client (application) connects to the Zookeeper server, Zookeeper will listen to this end
Server. A=b:c:d
server.1=192.168.1.81:2881:3881
server.2=192.168.1.82:2882:3882
server.3=192.168.1.83:2883:3883
A is a number that indicates this is the first server;
B is the IP address of the server (or the host name mapped with the IP address);
C the first port is used for the information exchange of the cluster members, indicating that the server and the Leader server in the cluster exchange information ports;
D is the port used exclusively for election leader when the leader is hung out.
Note: If you are configuring a pseudo-cluster, different Zookeeper instance communication port numbers cannot be the same, so assign them a different port number.
7. Create the myID file under Datadir=/home/yxq/zookeeper/node-0x/data
Edit the myID file and enter the corresponding number on the corresponding IP machine. As in node-01, myID file content is 1,node-02 on the 2,node-03 is 3:
[root@edu-zk-01 node-01]# CD data
[Root@edu-zk-01 data]# VI myID
[Root@edu-zk-01 data]# Cat myID
1
[Root@edu-zk-01 data]#
[Root@edu-zk-02 conf]# CD.
[root@edu-zk-02 node-02]# CD data
[Root@edu-zk-02 data]# VI myID
[Root@edu-zk-02 data]# Cat myID
2
[Root@edu-zk-03 conf]# CD.
[root@edu-zk-03 node-03]# CD data
[Root@edu-zk-03 data]# VI myID
[Root@edu-zk-03 data]# Cat myID
3
[Root@edu-zk-03 data]#
8, open in the firewall to use the port 218X, 288X, 388X
Switch to root user rights and execute the following command:
[Root@edu-zk-01 data]# Vi/etc/sysconfig/iptables
[root@edu-zk-01 data]# Service iptables restart
edu-zk-03,edu-zk-03
[Root@edu-zk-02 data]# Vi/etc/sysconfig/iptables
[root@edu-zk-02 data]# Service iptables restart
[Root@edu-zk-03 data]# Vi/etc/sysconfig/iptables
[root@edu-zk-03 data]# Service iptables restart
9, start and test zookeeper (to use YXQ users to start, do not use root): First enable edu-zk-01. Cluster environment, only half of the nodes are running normally without error, here the error is normal
[Root@edu-zk-01 root]# Clear
[Root@edu-zk-01 root]# who
YXQ pts/0 2016-04-15 00:48 (192.168.1.61)
[Root@edu-zk-01 root]#/home/yxq/zookeeper/node-01/bin/zkserver.sh start
JMX enabled by default
Using config:/home/yxq/zookeeper/node-01/bin/. /conf/zoo.cfg
Starting zookeeper ... STARTED
To see if it starts properly
Among them, Quorumpeermain is the zookeeper process, stating that startup is normal
[Root@edu-zk-01 root]# JPS
3293 Jps
3240 Quorumpeermain
[Root@edu-zk-01 root]# tail-500f Zookeeper.out
2016-04-15 01:11:57,970 [myID:]-INFO [main:quorumpeerconfig@103]-Reading configuration from:/home/yxq/zookeeper/nod e-01/bin/. /conf/zoo.cfg
2016-04-15 01:11:57,974 [myID:]-INFO [main:quorumpeerconfig@340]-defaulting to majority quorums
2016-04-15 01:11:57,976 [Myid:1]-INFO [main:datadircleanupmanager@78]-Autopurge.snapretaincount set to 3
2016-04-15 01:11:57,976 [Myid:1]-INFO [main:datadircleanupmanager@79]-Autopurge.purgeinterval set to 0
2016-04-15 01:11:57,977 [Myid:1]-INFO [main:datadircleanupmanager@101]-Purge task is not scheduled.
2016-04-15 01:11:57,985 [Myid:1]-INFO [main:quorumpeermain@127]-Starting quorum peer
2016-04-15 01:11:57,993 [Myid:1]-INFO [main:nioservercnxnfactory@94]-binding to port 0.0.0.0/0.0.0.0:2181
2016-04-15 01:11:58,015 [Myid:1]-INFO [main:quorumpeer@959]-Ticktime set to 2000
2016-04-15 01:11:58,015 [Myid:1]-INFO [main:quorumpeer@979]-Minsessiontimeout set to-1
2016-04-15 01:11:58,015 [Myid:1]-INFO [main:quorumpeer@990]-Maxsessiontimeout set to-1
2016-04-15 01:11:58,015 [Myid:1]-INFO [main:quorumpeer@1005]-Initlimit set to 10
2016-04-15 01:11:58,028 [Myid:1]-INFO [main:filesnap@83]-Reading snapshot/home/yxq/zookeeper/node-01/data/ version-2/snapshot.0
2016-04-15 01:11:58,037 [Myid:1]-INFO [thread-1:quorumcnxmanager$listener@504]-My election bind port:/192.168.1.81:3 881
2016-04-15 01:11:58,044 [Myid:1]-INFO [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumpeer@714]-LOOKING
2016-04-15 01:11:58,045 [Myid:1]-INFO [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:fastleaderelection@815]-New Election. My id = 1, proposed zxid=0x0
2016-04-15 01:11:58,047 [Myid:1]-INFO [workerreceiver[myid=1]:fastleaderelection@597]-notification:1 (message forma T version), 1 (n.leader), 0x0 (N.ZXID), 0x1 (N.round), looking (n.state), 1 (n.sid), 0x1 (N.peerepoch) looking (my state)
2016-04-15 01:11:58,050 [Myid:1]-WARN [workersender[myid=1]:quorumcnxmanager@382]-Cannot open channel to 2 at Electio N address/192.168.1.82:3882
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend (quorumcnxmanager.java:341)
At Org.apache.zookeeper.server.quorum.fastleaderelection$messenger$workersender.process (FastLeaderElection.java : 449)
At Org.apache.zookeeper.server.quorum.fastleaderelection$messenger$workersender.run (FastLeaderElection.java:430 )
At Java.lang.Thread.run (thread.java:744)
2016-04-15 01:11:58,053 [Myid:1]-WARN [workersender[myid=1]:quorumcnxmanager@382]-Cannot open channel to 3 at Electio N address/192.168.1.83:3883
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend (quorumcnxmanager.java:341)
At Org.apache.zookeeper.server.quorum.fastleaderelection$messenger$workersender.process (FastLeaderElection.java : 449)
At Org.apache.zookeeper.server.quorum.fastleaderelection$messenger$workersender.run (FastLeaderElection.java:430 )
At Java.lang.Thread.run (thread.java:744)
2016-04-15 01:11:58,256 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 2 at election address/192.168.1.82:3882
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:402)
At Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:840)
At Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:762)
2016-04-15 01:11:58,259 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 3 at election address/192.168.1.83:3883
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:402)
At Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:840)
At Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:762)
2016-04-15 01:11:58,260 [Myid:1]-INFO [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:fastleaderelection@849]- Notification Time out:400
2016-04-15 01:11:58,663 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 2 at election address/192.168.1.82:3882
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:402)
At Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:840)
At Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:762)
2016-04-15 01:11:58,666 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 3 at election address/192.168.1.83:3883
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:402)
At Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:840)
At Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:762)
2016-04-15 01:11:58,667 [Myid:1]-INFO [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:fastleaderelection@849]- Notification Time out:800
2016-04-15 01:11:59,470 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 2 at election address/192.168.1.82:3882
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:402)
At Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:840)
At Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:762)
2016-04-15 01:11:59,472 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 3 at election address/192.168.1.83:3883
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:402)
At Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:840)
At Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:762)
2016-04-15 01:11:59,478 [Myid:1]-INFO [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:fastleaderelection@849]- Notification Time out:1600
2016-04-15 01:12:01,080 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 2 at election address/192.168.1.82:3882
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (quorumcnxmanager.java:402)
At Org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader (fastleaderelection.java:840)
At Org.apache.zookeeper.server.quorum.QuorumPeer.run (quorumpeer.java:762)
2016-04-15 01:12:01,084 [Myid:1]-WARN [quorumpeer[myid=1]/0:0:0:0:0:0:0:0:2181:quorumcnxmanager@382]-Cannot Open Channel to 3 at election address/192.168.1.83:3883
Java.net.ConnectException:Connection refused
At Java.net.PlainSocketImpl.socketConnect (Native Method)
At Java.net.AbstractPlainSocketImpl.doConnect (abstractplainsocketimpl.java:339)
At Java.net.AbstractPlainSocketImpl.connectToAddress (abstractplainsocketimpl.java:200)
At Java.net.AbstractPlainSocketImpl.connect (abstractplainsocketimpl.java:182)
At Java.net.SocksSocketImpl.connect (sockssocketimpl.java:392)
At Java.net.Socket.connect (socket.java:579)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne (quorumcnxmanager.java:368)
At Org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll (QUORUMCNX