Bharat Bharat - 1 month ago 9
Apache Configuration Question

Multiple zookeeper server start issue

I am able to run single zookeeper instance on my windows machine. but getting success to setup multiple zookeeper instances on single windows machine.

As per guideline I did following steps:


  1. Creating multiple zoo.conf file into conf folder. Structure as below

    zookeeper_home---|
    conf--|
    zoo.cfg
    zoo_2.cfg
    zoo_3.cfg

  2. zoo.cfg




tickTime=2000
initLimit=10
syncLimit=5
dataDir=c:/opt/zookeeper/data
clientPort=2181
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890




  1. zoo_2.cfg




tickTime=2000
initLimit=10
syncLimit=5
dataDir=c:/opt/zookeeper/data2
clientPort=2182
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890




  1. zoo_3.cfg




tickTime=2000
initLimit=10
syncLimit=5
dataDir=c:/opt/zookeeper/data3
clientPort=2183
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890




  1. As each file has dataDir, I have created folder as




c:/opt/zookeeper/data

c:/opt/zookeeper/data2

c:/opt/zookeeper/data3


Also created myid file in each of above folder with number 1,2,3 respectively.
now whenever I am trying to start server as
c:\opt\zookeeper\bin>zkServer.cmd

it is throwing an error as


Cannot open channel to 2 at election address localhost/127.0.0.1:3889

Cannot open channel to 3 at election address localhost/127.0.0.1:3890

java.net.ConnectException: Connection refused: connect


looks like server not started, but how I can start these server parallely? or is I have to user any other approach.

Answer

Because by default, zkEnv.cmd will use the zoo.cfg as the default configuration file. And if you execute your command c:\opt\zookeeper\bin>zkServer.cmd, then only one instance start up with configuration zoo.cfg

So if you want to start up three instances:

  1. either you copy three zookeeper package, and each has its own zoo.cfg, and execute following command for each c:\opt\zookeeper1\bin>zkServer.cmd, c:\opt\zookeeper2\bin>zkServer.cmd, c:\opt\zookeeper3\bin>zkServer.cmd
  2. Or you can modify zkEnv.cmd, and make it accept the parameter as the configuration file, the you can execute zkServer.cmd ../conf/zoo.cfg, zkServer.cmd ../conf/zoo2.cfg, zkServer.cmd ../conf/zoo3.cfg

For alternative #2, you also need to update log4j configuration, so you can have different log file for each instances, so simply, just copy 3 folders, and modify each zoo.cfg

Check the code:

zkEnv.cmd

set ZOOCFG=%ZOOCFGDIR%\zoo.cfg

Comments