Generate configuration for ZooKeeper ensemble
This project will generate all of the configuration needed to run a ZooKeeper ensemble. I mainly use this tool for localhost based testing, but it can generate configurations for any list of servers (see the —server option).
What’s Apache ZooKeeper?
From the official site: “ZooKeeper is a high-performance coordination service for distributed applications.”
It exposes common services – such as naming, configuration management, synchronization, and group services – in a simple interface so you don’t have to write them from scratch. You can use it off-the-shelf to implement consensus, group management, leader election, and presence protocols. And you can build on it for your own, specific needs.
This project is licensed under the Apache License Version 2.0
Cheetah templating package are necessary to run this
- On ubuntu “sudo apt-get install python-cheetah”
before using the first time (or on update) run the following command
cheetah compile *.tmpl
Usage: zkconf.py [options] zookeeper_dir output_dir Options: -h, --help show this help message and exit -c COUNT, --count=COUNT ensemble size (default 3) --servers=SERVERS explicit list of comma separated server names (alternative to --count) --clientportstart=CLIENTPORTSTART first client port (default 2181) --quorumportstart=QUORUMPORTSTART first quorum port (default 3181) --electionportstart=ELECTIONPORTSTART first election port (default 4181) --weights=WEIGHTS comma separated list of weights for each server (flex quorum only, default off) --groups=GROUPS comma separated list of groups (flex quorum only, default off) --maxClientCnxns=MAXCLIENTCNXNS maxClientCnxns of server config (default unspecified, ZK default) --electionAlg=ELECTIONALG electionAlg of server config (default unspecified, ZK default - FLE)
Where zookeeper_dir is the location of your ZooKeeper trunk (zkconf copies the jars/confs from this directory into the output_dir to make your life easier). And output_dir is the directory to which we will output the generated files (assumption is that this is a non-existent directory – ie zkconf will create it)
example of typical use; 9 server quorum:
zkconf.py —count 9 ~/zookeeper_trunk test9servers
zkconf.py —servers “host1.com,host2.com,220.127.116.11” ~/zookeeper_trunk test3servers
example of using weights/groups (only for flex quorum, not typical); 9 servers with 3 groups
zkconf.py -c 9 —weights=“1,1,1,1,1,0,0,0,0” —groups=“1:2:3:4:5,6:7,8:9” ~/dev/workspace/gitzk testflexquroum
Running localhost (default) starts client:quorum:election ports as 2181:3181:4181 respectively. Running non-localhost (—servers) starts client:quorum:elections ports for all hosts as 2181:3181:4181.
- cli.sh “server:port,server:port,…” – open a client to the server list
- status.sh – status of each of the servers (prints leader | follower if active)
- start.sh – start the ensemble (logs are output to the respective server subdir, localhost only)
- stop.sh – stop the ensemble (localhost only)