Apache ZooKeeper provides leadership election, consensus, distributed configuration service, synchronization service, and naming registry for large distributed systems.
docker run --name zookeeper \
-p 2181:2181 \
--restart always \
-e ENSEMBLE=zoo1,hostzoo2,zookeeper3 \
cloudurable/zookeeper-image:0.2 \
/opt/zookeeper/bin/run.sh
"changes": [
"ENV ZOO_CLIENT_PORT 2181",
"ENV ZOO_PEER_PORT 2888",
"ENV ZOO_LEADER_PORT 3888",
"ENV ZOO_MY_ID 1",
"ENV ZOO_TICK_TIME 5000",
"ENV ZOO_INIT_LIMIT 5",
"ENV ZOO_SYNC_LIMIT 2",
"ENV ZOO_MAX_CLIENT_CNXNS 60",
"ENV ZOO_MIN_SESSION_TIMEOUT 24000",
"ENV ZOO_MAX_SESSION_TIMEOUT 60000",
"ENV ZOO_STANDALONE_ENABLED true",
"ENV ZOO_CLIENT_PORT_ADDRESS ''",
"ENV ZOO_AUTO_PURGE_SNAP_RETAIN_COUNT=5",
"ENV ZOO_AUTO_PURGE_INTERVAL=12",
"ENV ZOO_DATA_DIR /opt/zookeeper/data/snapshots",
"ENV ZOO_DATA_LOG_DIR /opt/zookeeper/data/transactions",
"ENV ENSEMBLE ''",
"ENV JMXLOCALONLY true",
"ENV JMXDISABLE true",
"ENV JMXPORT ''",
"ENV JMXAUTH false",
"ENV JMXSSL false",
"ENV JMXLOG4J false",
"ENV SERVER_JVMFLAGS ''",
"ENV JVMFLAGS ''",
"ENV ZOOCFGDIR /opt/zookeeper/conf",
"ENV ZOOBINDIR /opt/zookeeper/bin",
"ENV ZOOCFG zoo.cfg",
"ENV EXPOSE 2181 2888 3888",
"ENTRYPOINT /opt/zookeeper/bin/run.sh"
]
version: '3'
services:
zookeeper0:
image: "cloudurable/zookeeper-image:0.2"
restart: always
ports:
- "2181:2181"
environment:
- ENSEMBLE=zookeeper0,zookeeper1,zookeeper2
- MY_ID=1
zookeeper1:
image: "cloudurable/zookeeper-image:0.2"
restart: always
environment:
- ENSEMBLE=zookeeper0,zookeeper1,zookeeper2
- MY_ID=2
zookeeper2:
image: "cloudurable/zookeeper-image:0.2"
restart: always
environment:
- ENSEMBLE=zookeeper0,zookeeper1,zookeeper2
- MY_ID=3
This above starts Zookeeper in replicated mode. Run docker-compose up\ and wait for it to initialize completely. Ports 2181, 2888 and 3888 will be exposed.
echo stat | nc localhost 2181
echo stat | nc localhost 2182
echo stat | nc localhost 2183
echo stat | nc localhost 2181
Zookeeper version: 3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
Clients:
/172.18.0.1:32952[0](queued=0,recved=1,sent=0)
Latency min/avg/max: 0/0/0
Received: 7
Sent: 6
Connections: 1
Outstanding: 0
Zxid: 0x0
Mode: follower
Node count: 4
netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:45651 0.0.0.0:* LISTEN 16/java
tcp 0 0 127.0.0.11:44925 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:2181 0.0.0.0:* LISTEN 16/java
tcp 0 0 172.18.0.2:2888 0.0.0.0:* LISTEN 16/java
tcp 0 0 172.18.0.2:3888 0.0.0.0:* LISTEN 16/java
tcp 0 0 172.18.0.2:2888 172.18.0.4:54354 ESTABLISHED 16/java leader
tcp 0 0 172.18.0.2:53370 172.18.0.3:3888 ESTABLISHED 16/java election
tcp 0 0 172.18.0.2:2888 172.18.0.3:39246 ESTABLISHED 16/java leader
tcp 0 0 172.18.0.2:3888 172.18.0.4:47114 ESTABLISHED 16/java election
udp 0 0 127.0.0.11:60998 0.0.0.0:*
netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.11:39409 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:40955 0.0.0.0:* LISTEN 16/java
tcp 0 0 0.0.0.0:2181 0.0.0.0:* LISTEN 16/java
tcp 0 0 172.18.0.3:3888 0.0.0.0:* LISTEN 16/java
tcp 0 0 172.18.0.3:3888 172.18.0.2:53370 ESTABLISHED 16/java election
tcp 0 0 172.18.0.3:39246 172.18.0.2:2888 ESTABLISHED 16/java follow leader
tcp 0 0 172.18.0.3:3888 172.18.0.4:60166 ESTABLISHED 16/java election
udp 0 0 127.0.0.11:33899 0.0.0.0:*
The ZooKeeper config gets generated based on the environment variables that you specify by
/opt/zookeeper/bin/run.sh using sed to edit the ZooKeeper config file.
Zookeeper configuration is located in /opt/zookeeper/conf.
To change the config, mount a new config file as a volume:
$ docker run --name node0-zookeeper --restart always \
-d -v $(pwd)/zoo.cfg:/opt/zookeeper/conf/zoo.cfg \
cloudurable/zookeeper-image
ZooKeeper defaults described above are used. They can be overridden using the following environment variables.
$ docker run -e "ZOO_INIT_LIMIT=10" --name node0-zookeeper --restart always -d cloudurable/zookeeper-image
ZOO_TICK_TIMEDefaults to 2000. ZooKeeper's tickTime
The length of a single tick, which is the basic time unit used by ZooKeeper, as measured in milliseconds. It is used to regulate heartbeats, and timeouts. For example, the minimum session timeout will be two ticks
ZOO_INIT_LIMITDefaults to 5. ZooKeeper's initLimit
Amount of time, in ticks (see tickTime), to allow followers to connect and sync to a leader. Increased this value as needed, if the amount of data managed by ZooKeeper is large.
ZOO_SYNC_LIMITDefaults to 2. ZooKeeper's syncLimit
Amount of time, in ticks (see tickTime), to allow followers to sync with ZooKeeper. If followers fall too far behind a leader, they will be dropped.
ZOO_MAX_CLIENT_CNXNSDefaults to 60. ZooKeeper's maxClientCnxns
Limits the number of concurrent connections (at the socket level) that a single client, identified by IP address, may make to a single member of the ZooKeeper ensemble.
ZOO_STANDALONE_ENABLEDDefaults to false. Zookeeper's standaloneEnabled
Prior to 3.5.0, one could run ZooKeeper in Standalone mode or in a Distributed mode. These are separate implementation stacks, and switching between them during run time is not possible. By default (for backward compatibility) standaloneEnabled is set to true. The consequence of using this default is that if started with a single server the ensemble will not be allowed to grow, and if started with more than one server it will not be allowed to shrink to contain fewer than two participants.
Environment variables below are mandatory if you want to run Zookeeper in replicated mode.
ZOO_MY_IDThe id must be unique within the ensemble and should have a value between 1 and 255. Do note that this variable will not have any effect if you start the container with a /data directory that already contains the myid file.
ENSEMBLEThis variable allows you to specify a comma delimited list of host names of the Zookeeper ensemble.
This image is configured with volumes at /opt/zookeeper/data/snapshots and
/opt/zookeeper/data/transactions to hold snapshots of the Zookeeper in-memory database
and the transaction log of updates to the database, respectively.
Be careful where you put the transaction log. A dedicated transaction log device is key to consistent good performance. Putting the log on a busy device will adversely affect performance.
packer build base-java-packer.json
We build a base image which installs Java, updates the OS, etc. This is time consuming. We try to do it once.
packer build packer.json
docker run -it cloudurable/zookeeper-image:latest
## We added an entrypoint so now you have to do this
docker run -it --entrypoint "/bin/bash" cloudurable/zookeeper-image
docker ps -a | grep cloudurable/zookeeper-image | awk '{ print $1}' \
| xargs docker rm
docker images | grep cloudurable/zookeeper-image | awk '{ print $3}' \
| xargs docker rmi -f
Content type
Image
Digest
Size
318.5 MB
Last updated
about 4 years ago
docker pull cloudurable/zookeeper-image