From the ZooKeeper multi-server config docs they show the following configs that can be placed inside of zoo.cfg
(ZK's config file) on each server:
tickTime=2000
dataDir=/var/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
Furthermore, they state that you need a myid
file on each ZK node whose content matches one of the server.id
values above. So for example, in a 3-node "ensemble" (ZK cluster), the first node's myid
file would simply contain the value 1
. The second node's myid
file would contain 2
, and so forth.
I have a few practical questions about what this looks like in the real world:
1. Can localhost
be used? If zoo.cfg
has to be repeated on each node in the ensemble, is it OK to define the current server as localhost
? For example, in a 3-node ensemble, would it be OK for Server #2's zoo.cfg
to look like:
tickTime=2000
dataDir=/var/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=localhost:2888:3888 # Afterall, we're on server #2!
server.3=zoo3:2888:3888
Or is this not advised/not possible?
2. Do they server ids have to be numerical? For instance, could I have a 5-node ensemble where each server's zoo.cfg
looks like:
tickTime=2000
dataDir=/var/zookeeper/
clientPort=2181
initLimit=5
syncLimit=2
server.red=zoo1:2888:3888
server.green=zoo2:2888:3888
server.blue=zoo3:2888:3888
server.orange=zoo1:2888:3888
server.purple=zoo2:2888:3888
And, say, Server 1's myid
would contain the value red
inside of it (etc.)?