BufBills
BufBills

Reputation: 8103

Zookeeper cfg file - Why are there multiple ports?

nano conf/zoo.cfg  

tickTime=2000  
dataDir=/var/lib/zookeeper  
clientPort=2181  
initLimit=5  
syncLimit=2  
server.1=10.0.0.2:2888:3888  
server.2=10.0.0.3:2888:3888  
server.3=10.0.0.4:2888:3888  

I'm trying to understand this cfg file. clientPort is for incoming communication, right? But why are there two more ports like this: server.1=10.0.0.2:2888:3888?

Upvotes: 3

Views: 1882

Answers (1)

Jack Daniel's
Jack Daniel's

Reputation: 2613

The entries of the form server.X list the servers that make up the ZooKeeper service. When the server starts up, it knows which server it is by looking for the file myid in the data directory. That file has the contains the server number, in ASCII.

Finally, note the two port numbers after each server name: " 2888" and "3888". Peers use the former port to connect to other peers. Such a connection is necessary so that peers can communicate, for example, to agree upon the order of updates. More specifically, a ZooKeeper server uses this port to connect followers to the leader. When a new leader arises, a follower opens a TCP connection to the leader using this port. Because the default leader election also uses TCP, we currently require another port for leader election. This is the second port in the server entry.

Ref:- http://zookeeper.apache.org/doc/r3.1.2/zookeeperStarted.html

Upvotes: 1

Related Questions