zookeeper 集群搭建
vi ~/.bashrc
export ZOOKEEPER_HOME=/data/zookeeper-3.4.14
export PATH=$ZOOKEEPER_HOME/bin
source ~/.bashrc
root@node148:/data/zookeeper-3.4.14/conf# cp zoo_sample.cfg zoo.cfg
root@node148:/data/zookeeper-3.4.14/conf# vim zoo.cfg
修改:dataDir=/data/zookeeper-3.4.14/data
新增:
server.0=10.20.17.138:2888:3888
server.1=10.20.17.148:2888:3888
server.2=10.20.17.148:2888:3888
root@node148:/data/zookeeper-3.4.14/conf# cd ..
root@node148:/data/zookeeper-3.4.14/conf# mkdir data
root@node148:/data/zookeeper-3.4.14/data# vi myid
0
root@node148:/data/zookeeper-3.4.14/bin# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
root@node148:/data/zookeeper-3.4.14/bin# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: leader
root@node148:/data/zookeeper-3.4.14/bin# jps
27220 NodeAgentMain
5653 org.eclipse.equinox.launcher_1.3.0.v20161111-0305.jar
5402 Jps
5210 QuorumPeerMain
4154
日志查看:
root@node148:/data/zookeeper-3.4.14/bin# tail -1000f zookeeper.out
2021-08-09 19:47:53,715 [myid:] - INFO [main:QuorumPeerConfig@136] - Reading configuration from: /data/zookeeper-3.4.14/bin/../conf/zoo.cfg
2021-08-09 19:47:53,746 [myid:] - INFO [main:QuorumPeer$QuorumServer@185] - Resolved hostname: 10.173.203.148 to address: /10.173.203.148
2021-08-09 19:47:53,747 [myid:] - INFO [main:QuorumPeer$QuorumServer@185] - Resolved hostname: 10.173.203.14 to address: /10.173.203.14
2021-08-09 19:47:53,748 [myid:] - INFO [main:QuorumPeer$QuorumServer@185] - Resolved hostname: 10.173.203.158 to address: /10.173.203.158
2021-08-09 19:47:53,749 [myid:] - INFO [main:QuorumPeerConfig@398] - Defaulting to majority quorums
2021-08-09 19:47:53,758 [myid:0] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2021-08-09 19:47:53,758 [myid:0] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2021-08-09 19:47:53,758 [myid:0] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2021-08-09 19:47:53,780 [myid:0] - INFO [main:QuorumPeerMain@130] - Starting quorum peer
2021-08-09 19:47:53,796 [myid:0] - INFO [main:ServerCnxnFactory@117] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2021-08-09 19:47:53,807 [myid:0] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181
2021-08-09 19:47:53,828 [myid:0] - INFO [main:QuorumPeer@1159] - tickTime set to 2000
2021-08-09 19:47:53,828 [myid:0] - INFO [main:QuorumPeer@1205] - initLimit set to 10
2021-08-09 19:47:53,828 [myid:0] - INFO [main:QuorumPeer@1179] - minSessionTimeout set to -1
2021-08-09 19:47:53,829 [myid:0] - INFO [main:QuorumPeer@1190] - maxSessionTimeout set to -1
2021-08-09 19:47:53,846 [myid:0] - INFO [main:QuorumPeer@1470] - QuorumPeer communication is not secured!
2021-08-09 19:47:53,850 [myid:0] - INFO [main:QuorumPeer@1499] - quorum.cnxn.threads.size set to 20
2021-08-09 19:47:53,858 [myid:0] - INFO [main:QuorumPeer@669] - currentEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgr
ading your installation2021-08-09 19:47:53,864 [myid:0] - INFO [main:QuorumPeer@684] - acceptedEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upg
rading your installation2021-08-09 19:47:53,876 [myid:0] - INFO [ListenerThread:QuorumCnxManager$Listener@736] - My election bind port: /10.173.203.14:3888
2021-08-09 19:47:53,894 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:QuorumPeer@910] - LOOKING
2021-08-09 19:47:53,897 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@813] - New election. My id = 0, proposed zxid=0x0
2021-08-09 19:47:53,903 [myid:0] - INFO [WorkerReceiver[myid=0]:FastLeaderElection@595] - Notification: 1 (message format version), 0 (n.leader), 0x0 (n.zxid), 0x1 (n.rou
nd), LOOKING (n.state), 0 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)2021-08-09 19:47:53,908 [myid:0] - INFO [WorkerSender[myid=0]:QuorumCnxManager@347] - Have smaller server identifier, so dropping the connection: (1, 0)
2021-08-09 19:47:53,911 [myid:0] - WARN [WorkerSender[myid=0]:QuorumCnxManager@584] - Cannot open channel to 2 at election address /10.173.203.158:3888
java.net.ConnectException: 拒绝连接 (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:607)
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)
2021-08-09 19:47:53,912 [myid:0] - INFO [/10.173.203.14:3888:QuorumCnxManager$Listener@743] - Received connection request /10.173.203.148:60992
2021-08-09 19:47:53,915 [myid:0] - INFO [WorkerSender[myid=0]:QuorumPeer$QuorumServer@185] - Resolved hostname: 10.173.203.158 to address: /10.173.203.158
2021-08-09 19:47:53,925 [myid:0] - INFO [WorkerReceiver[myid=0]:FastLeaderElection@595] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.rou
nd), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)2021-08-09 19:47:53,927 [myid:0] - INFO [WorkerReceiver[myid=0]:FastLeaderElection@595] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.rou
nd), LOOKING (n.state), 0 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)2021-08-09 19:47:53,927 [myid:0] - WARN [WorkerSender[myid=0]:QuorumCnxManager@584] - Cannot open channel to 2 at election address /10.173.203.158:3888
java.net.ConnectException: 拒绝连接 (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:607)
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)
2021-08-09 19:47:53,928 [myid:0] - INFO [WorkerSender[myid=0]:QuorumPeer$QuorumServer@185] - Resolved hostname: 10.173.203.158 to address: /10.173.203.158
2021-08-09 19:47:54,128 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:QuorumPeer@980] - FOLLOWING
2021-08-09 19:47:54,137 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Learner@86] - TCP NoDelay set to: true
2021-08-09 19:47:54,152 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd
8da255ac140bcf, built on 03/06/2019 16:18 GMT2021-08-09 19:47:54,153 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:host.name=user-PC
2021-08-09 19:47:54,153 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.version=1.8.0_252
2021-08-09 19:47:54,153 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.vendor=Oracle Corporation
2021-08-09 19:47:54,153 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.home=/home/bes/jdk/jre
2021-08-09 19:47:54,153 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.class.path=/data/zookeeper-3.4.14/bin/../zooke
eper-server/target/classes:/data/zookeeper-3.4.14/bin/../build/classes:/data/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/data/zookeeper-3.4.14/bin/../build/lib/*.jar:/data/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/data/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/data/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/data/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/data/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/data/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/data/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/data/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/data/zookeeper-3.4.14/bin/../conf:2021-08-09 19:47:54,153 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.library.path=/unary/downloaderV2/ubackup/uagen
t/bin/Python27/lib/python2.7/lib-dynload::/usr/java/packages/lib/mips64el:/lib:/usr/lib2021-08-09 19:47:54,154 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.io.tmpdir=/tmp
2021-08-09 19:47:54,154 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:java.compiler=<NA>
2021-08-09 19:47:54,154 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.name=Linux
2021-08-09 19:47:54,154 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.arch=mips64el
2021-08-09 19:47:54,154 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:os.version=4.19.0-loongson-3-server
2021-08-09 19:47:54,154 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.name=root
2021-08-09 19:47:54,154 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.home=/root
2021-08-09 19:47:54,155 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Environment@100] - Server environment:user.dir=/data/zookeeper-3.4.14/bin
2021-08-09 19:47:54,159 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:ZooKeeperServer@174] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessio
nTimeout 40000 datadir /data/zookeeper-3.4.14/data/version-2 snapdir /data/zookeeper-3.4.14/data/version-22021-08-09 19:47:54,160 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Follower@65] - FOLLOWING - LEADER ELECTION TOOK - 264
2021-08-09 19:47:54,165 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:QuorumPeer$QuorumServer@185] - Resolved hostname: 10.173.203.148 to address: /10.173.203.
1482021-08-09 19:47:54,166 [myid:0] - WARN [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Learner@237] - Unexpected exception, tries=0, connecting to /10.173.203.148:2888
java.net.ConnectException: 拒绝连接 (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:607)
at org.apache.zookeeper.server.quorum.Learner.connectToLeader(Learner.java:229)
at org.apache.zookeeper.server.quorum.Follower.followLeader(Follower.java:72)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:982)
2021-08-09 19:47:55,203 [myid:0] - INFO [QuorumPeer[myid=0]/0:0:0:0:0:0:0:0:2181:Learner@332] - Getting a diff from the leader 0x0
2021-08-09 19:48:15,192 [myid:0] - INFO [/10.173.203.14:3888:QuorumCnxManager$Listener@743] - Received connection request /10.173.203.158:57360
2021-08-09 19:48:15,198 [myid:0] - INFO [WorkerReceiver[myid=0]:FastLeaderElection@595] - Notification: 1 (message format version), 2 (n.leader), 0x0 (n.zxid), 0x1 (n.rou
nd), LOOKING (n.state), 2 (n.sid), 0x0 (n.peerEpoch) FOLLOWING (my state)2021-08-09 19:48:42,249 [myid:0] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@222] - Accepted socket connection from /127.0.0.1:52500
2021-08-09 19:48:42,262 [myid:0] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ServerCnxn@324] - The list of known four letter word commands is : [{1936881266=srvr, 1
937006964=stat, 2003003491=wchc, 1685417328=dump, 1668445044=crst, 1936880500=srst, 1701738089=envi, 1668247142=conf, 2003003507=wchs, 2003003504=wchp, 1668247155=cons, 1835955314=mntr, 1769173615=isro, 1920298859=ruok, 1735683435=gtmk, 1937010027=stmk}]2021-08-09 19:48:42,262 [myid:0] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ServerCnxn@325] - The list of enabled four letter word commands is : [[wchs, stat, stmk
, conf, ruok, mntr, srvr, envi, srst, isro, dump, gtmk, crst, cons]]2021-08-09 19:48:42,262 [myid:0] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@908] - Processing srvr command from /127.0.0.1:52500
2021-08-09 19:48:42,268 [myid:0] - INFO [Thread-1:NIOServerCnxn@1056] - Closed socket connection for client /127.0.0.1:52500 (no session established for client)