Zookeeper Cluster Setup with 3 Zookeeper Node Cluster on Local machine in Apache Kafka

 1) Make a zookeeper_cluster folder with 3 subfolder inside zkNode1 ,  zkNode2 , zkNode3 . And place 

apache-zookeeper-3.5.7-bin.tar file into them.

2) Extract first folder file.

3)Go to conf folder in  extracted file and make copy of zoo_sample.cfg

 and rename it zoo.cfg and delete commented line and make this.

zoo.cfg


tickTime=2000

initLimit=10

syncLimit=5

dataDir=/tmp/zookeeper

clientPort=2181

maxClientCnxns=60

4lw.commands.whitelist=*

server.1=localhost:2788:3788
server.2=localhost:2888:3888
server.3=localhost:2988:3988


tickTime and initLimit
When any zookeeper node want to connect with zookeeper cluster then maximum time limit is 10 unit which is the initLimit . And 1 unit equal to tickTime which is 2000 milisecond. So total maximum time it will take to connect zookeeper node to zookeeper cluster is initLimit*tickTime=2000*10=20000 mili second=20 second.


syncLimit
When any zookeeper node is out  of sync in zookeeper cluster . Then it have maximum 5 unit time  in the sync otherwise zookeeper cluster out from zookeeper cluster. 

dataDir=It store information regarding cluster and  client data which are connected to it.

clientPort= from which port client connected to the zookeeper cluster 

server.1=localhost:2788:3788
server.2=localhost:2888:3888
server.3=localhost:2988:3988
It is the number of zookeeper node running in the system.
1 , 2 , 3 are the unique identifier of first , second and third zookeeper node.
2788, 2888, 2988 these port are used to connect between server to server(zookeeper).
3788, 3888, 3988 these port are used to leader election in server(zookeeper).

tmp/zookeeper= temp is a volatile directory if you restart your system then it data inside tmp directory will be deleted.


4) config file with these -
for first folder=
zoo.cfg


tickTime=2000

initLimit=10

syncLimit=5

dataDir=/tmp/zookeeper-3

clientPort=2181

maxClientCnxns=60

4lw.commands.whitelist=*

server.1=localhost:2788:3788
server.2=localhost:2888:3888
server.3=localhost:2988:3988


for 2nd folder=
zoo.cfg


tickTime=2000

initLimit=10

syncLimit=5

dataDir=/tmp/zookeeper-2

clientPort=2182

maxClientCnxns=60

4lw.commands.whitelist=*

server.1=localhost:2788:3788
server.2=localhost:2888:3888
server.3=localhost:2988:3988

for 3rd folder=
zoo.cfg


tickTime=2000

initLimit=10

syncLimit=5

dataDir=/tmp/zookeeper-3

clientPort=2183

maxClientCnxns=60

4lw.commands.whitelist=*

server.1=localhost:2788:3788
server.2=localhost:2888:3888
server.3=localhost:2988:3988

5) make 3 directory
maneesh@maneesh:~$ cd Downloads
maneesh@maneesh:~/Downloads$ cd zookeeper_cluster
maneesh@maneesh:~/Downloads/zookeeper_cluster$ cd zkNode1
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ mkdir /tmp/zookeeper-1
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ mkdir /tmp/zookeeper-2
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ mkdir /tmp/zookeeper-3
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ 


6) Assign unique id to each zookeeper node
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ echo 1 >> /tmp/zookeeper-1/myid
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ echo 2 >> /tmp/zookeeper-2/myid
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ echo 3 >> /tmp/zookeeper-3/myid
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ 


7) Check directory are created or not
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ cat /tmp/zookeeper-1/myid
1
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ cat /tmp/zookeeper-2/myid
2
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ cat /tmp/zookeeper-3/myid
3
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ 


(8) start 3 terminals
1st terminal 
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ pwd
/home/maneesh/Downloads/zookeeper_cluster/zkNode1
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ 

2nd terminal
maneesh@maneesh:~$ cd /home/maneesh/Downloads/zookeeper_cluster/zkNode2
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode2$ 

3 rd terminal
maneesh@maneesh:~$ cd /home/maneesh/Downloads/zookeeper_cluster/zkNode3
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode3$ 

aneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ cd apache-zookeeper-3.5.7-bin/
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1/apache-zookeeper-3.5.7-bin$ ls
bin  conf  docs  lib  LICENSE.txt  NOTICE.txt  README.md  README_packaging.txt

(9) In 1st terminal
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1$ cd apache-zookeeper-3.5.7-bin/
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1/apache-zookeeper-3.5.7-bin$ ls
bin  conf  docs  lib  LICENSE.txt  NOTICE.txt  README.md  README_packaging.txt

 maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode1/apache-zookeeper-3.5.7-bin$ bin/zkServer.sh start-foreground
ZooKeeper JMX enabled by default
Using config: /home/maneesh/Downloads/zookeeper_cluster/zkNode1/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg
2021-02-09 13:09:22,168 [myid:] - INFO  [main:QuorumPeerConfig@135] - Reading configuration from: /home/maneesh/Downloads/zookeeper_cluster/zkNode1/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg
2021-02-09 13:09:22,238 [myid:] - INFO  [main:QuorumPeerConfig@387] - clientPortAddress is 0.0.0.0:2181
2021-02-09 13:09:22,239 [myid:] - INFO  [main:QuorumPeerConfig@391] - secureClientPort is not set
2021-02-09 13:09:22,278 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2021-02-09 13:09:22,280 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2021-02-09 13:09:22,280 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2021-02-09 13:09:22,282 [myid:1] - INFO  [main:ManagedUtil@46] - Log4j found with jmx enabled.
2021-02-09 13:09:22,318 [myid:1] - INFO  [main:QuorumPeerMain@141] - Starting quorum peer
2021-02-09 13:09:22,389 [myid:1] - INFO  [main:ServerCnxnFactory@135] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2021-02-09 13:09:22,398 [myid:1] - INFO  [main:NIOServerCnxnFactory@673] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 4 worker threads, and 64 kB direct buffers.
2021-02-09 13:09:22,425 [myid:1] - INFO  [main:NIOServerCnxnFactory@686] - binding to port 0.0.0.0/0.0.0.0:2181
2021-02-09 13:09:22,533 [myid:1] - INFO  [main:Log@169] - Logging initialized @1782ms to org.eclipse.jetty.util.log.Slf4jLog
2021-02-09 13:09:22,779 [myid:1] - WARN  [main:ContextHandler@1520] - o.e.j.s.ServletContextHandler@294425a7{/,null,UNAVAILABLE} contextPath ends with /*
2021-02-09 13:09:22,781 [myid:1] - WARN  [main:ContextHandler@1531] - Empty contextPath
2021-02-09 13:09:22,868 [myid:1] - INFO  [main:X509Util@79] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2021-02-09 13:09:22,901 [myid:1] - INFO  [main:FileTxnSnapLog@115] - zookeeper.snapshot.trust.empty : false
2021-02-09 13:09:22,939 [myid:1] - INFO  [main:QuorumPeer@1470] - Local sessions disabled
2021-02-09 13:09:22,940 [myid:1] - INFO  [main:QuorumPeer@1481] - Local session upgrading disabled
2021-02-09 13:09:22,942 [myid:1] - INFO  [main:QuorumPeer@1448] - tickTime set to 2000
2021-02-09 13:09:22,943 [myid:1] - INFO  [main:QuorumPeer@1492] - minSessionTimeout set to 4000
2021-02-09 13:09:22,944 [myid:1] - INFO  [main:QuorumPeer@1503] - maxSessionTimeout set to 40000
2021-02-09 13:09:22,948 [myid:1] - INFO  [main:QuorumPeer@1518] - initLimit set to 10
2021-02-09 13:09:22,982 [myid:1] - INFO  [main:ZKDatabase@117] - zookeeper.snapshotSizeFactor = 0.33
2021-02-09 13:09:22,987 [myid:1] - INFO  [main:QuorumPeer@1763] - Using insecure (non-TLS) quorum communication
2021-02-09 13:09:22,987 [myid:1] - INFO  [main:QuorumPeer@1769] - Port unification disabled
2021-02-09 13:09:22,987 [myid:1] - INFO  [main:QuorumPeer@2136] - QuorumPeer communication is not secured! (SASL auth disabled)
2021-02-09 13:09:22,987 [myid:1] - INFO  [main:QuorumPeer@2165] - quorum.cnxn.threads.size set to 20
2021-02-09 13:09:22,992 [myid:1] - INFO  [main:FileSnap@83] - Reading snapshot /tmp/zookeeper-1/version-2/snapshot.100000000
2021-02-09 13:09:23,053 [myid:1] - INFO  [main:Server@359] - jetty-9.4.24.v20191120; built: 2019-11-20T21:37:49.771Z; git: 363d5f2df3a8a28de40604320230664b9c793c16; jvm 15.0.2+7-27
2021-02-09 13:09:23,215 [myid:1] - INFO  [main:DefaultSessionIdManager@333] - DefaultSessionIdManager workerName=node0
2021-02-09 13:09:23,216 [myid:1] - INFO  [main:DefaultSessionIdManager@338] - No SessionScavenger set, using defaults
2021-02-09 13:09:23,230 [myid:1] - INFO  [main:HouseKeeper@140] - node0 Scavenging every 600000ms
2021-02-09 13:09:23,266 [myid:1] - INFO  [main:ContextHandler@825] - Started o.e.j.s.ServletContextHandler@294425a7{/,null,AVAILABLE}
2021-02-09 13:09:23,296 [myid:1] - INFO  [main:AbstractConnector@330] - Started ServerConnector@3ba9ad43{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2021-02-09 13:09:23,303 [myid:1] - INFO  [main:Server@399] - Started @2546ms
2021-02-09 13:09:23,304 [myid:1] - INFO  [main:JettyAdminServer@112] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
2021-02-09 13:09:23,338 [myid:1] - INFO  [main:QuorumCnxManager$Listener@867] - Election port bind maximum retries is 3
2021-02-09 13:09:23,350 [myid:1] - INFO  [QuorumPeerListener:QuorumCnxManager$Listener@917] - My election bind port: localhost/127.0.0.1:3788
2021-02-09 13:09:23,406 [myid:1] - INFO  [QuorumPeer[myid=1](plain=[0:0:0:0:0:0:0:0]:2181)(secure=disabled):QuorumPeer@1175] - LOOKING
2021-02-09 13:09:23,415 [myid:1] - INFO  [QuorumPeer[myid=1](plain=[0:0:0:0:0:0:0:0]:2181)(secure=disabled):FastLeaderElection@885] - New election. My id =  1, proposed zxid=0x100000000
2021-02-09 13:09:23,428 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@679] - Notification: 2 (message format version), 1 (n.leader), 0x100000000 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x1 (n.peerEPoch), LOOKING (my state)0 (n.config version)
2021-02-09 13:09:23,454 [myid:1] - WARN  [WorkerSender[myid=1]:QuorumCnxManager@685] - Cannot open channel to 2 at election address localhost/127.0.0.1:3888
java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:660)
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
at java.base/java.net.Socket.co


10) 2nd terminal
aneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode2$ ls
apache-zookeeper-3.5.7-bin  apache-zookeeper-3.5.7-bin.tar.gz
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode2$ cd apache-zookeeper-3.5.7-bin/
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode2/apache-zookeeper-3.5.7-bin$ bin/zkServer.sh start-foreground
ZooKeeper JMX enabled by default
Using config: /home/maneesh/Downloads/zookeeper_cluster/zkNode2/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg
2021-02-09 12:57:05,709 [myid:] - INFO  [main:QuorumPeerConfig@135] - Reading configuration from: /home/maneesh/Downloads/zookeeper_cluster/zkNode2/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg
2021-02-09 12:57:05,790 [myid:] - INFO  [main:QuorumPeerConfig@387] - clientPortAddress is 0.0.0.0:2182
2021-02-09 12:57:05,792 [myid:] - INFO  [main:QuorumPeerConfig@391] - secureClientPort is not set
2021-02-09 12:57:05,892 [myid:2] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2021-02-09 12:57:05,894 [myid:2] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2021-02-09 12:57:05,894 [myid:2] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2021-02-09 12:57:05,896 [myid:2] - INFO  [main:ManagedUtil@46] - Log4j found with jmx enabled.
2021-02-09 12:57:05,954 [myid:2] -


11) 3 rd terminal
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode3$ ls
apache-zookeeper-3.5.7-bin  apache-zookeeper-3.5.7-bin.tar.gz
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode3$ cd apache-zookeeper-3.5.7-bin/
maneesh@maneesh:~/Downloads/zookeeper_cluster/zkNode3/apache-zookeeper-3.5.7-bin$ bin/zkServer.sh start-foreground
ZooKeeper JMX enabled by default
Using config: /home/maneesh/Downloads/zookeeper_cluster/zkNode3/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg
2021-02-09 12:57:58,073 [myid:] - INFO  [main:QuorumPeerConfig@135] - Reading configuration from: /home/maneesh/Downloads/zookeeper_cluster/zkNode3/apache-zookeeper-3.5.7-bin/bin/../conf/zoo.cfg
2021-02-09 12:57:58,167 [myid:] - INFO  [main:QuorumPeerConfig@387] - clientPortAddress is 0.0.0.0:2183
2021-02-09 12:57:58,168 [myid:] - INFO  [main:QuorumPeerConfig@391] - secureClientPort is not set
2021-02-09 12:57:58,247 [myid:3] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2021-02-09 12:

(12) Check status of zookeeper
maneesh@maneesh:~$ echo stat | nc localhost 2181
Zookeeper version: 3.5.7-f0fdd52973d373ffd9c86b81d99842dc2c7f660e, built on 02/10/2020 11:30 GMT
Clients:
 /127.0.0.1:55582[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x200000000
Mode: leader
Node count: 5
Proposal sizes last/min/max: -1/-1/-1
maneesh@maneesh:~$ echo stat | nc localhost 2182
Zookeeper version: 3.5.7-f0fdd52973d373ffd9c86b81d99842dc2c7f660e, built on 02/10/2020 11:30 GMT
Clients:
 /127.0.0.1:37640[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x100000000
Mode: follower
Node count: 5
maneesh@maneesh:~$ echo stat | nc localhost 2183
Zookeeper version: 3.5.7-f0fdd52973d373ffd9c86b81d99842dc2c7f660e, built on 02/10/2020 11:30 GMT
Clients:
 /127.0.0.1:52434[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x200000000
Mode: follower
Node count: 5
maneesh@maneesh:~$ 







































Comments