创建工作目录
1 2 3
| mkdir ~/DockerDesktop mkdir ~/DockerDesktop/Zookeeper cd ~/DockerDesktop/Zookeeper
|
创建挂载目录
1 2 3 4 5 6 7
| mkdir node1 mkdir node1/data mkdir node1/datalog cp -r node1 node2 cp -r node1 node3 cp -r node1 node4 cp -r node1 node5
|
创建docker-compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| version: '3'
services: Zookeeper1: image: zookeeper hostname: Zookeeper1 volumes: - ~/DockerDesktop/Zookeeper/node1/data:/data - ~/DockerDesktop/Zookeeper/node1/datalog:/datalog environment: ZOO_MY_ID: 1 ZOO_SERVERS: server.1=Zookeeper1:2888:3888;2181 server.2=Zookeeper2:2888:3888;2181 server.3=Zookeeper3:2888:3888;2181 server.4=Zookeeper4:2888:3888;2181 server.5=Zookeeper5:2888:3888;2181 networks: default: ipv4_address: 172.17.1.1
Zookeeper2: image: zookeeper hostname: Zookeeper2 volumes: - ~/DockerDesktop/Zookeeper/node2/data:/data - ~/DockerDesktop/Zookeeper/node2/datalog:/datalog environment: ZOO_MY_ID: 2 ZOO_SERVERS: server.1=Zookeeper1:2888:3888;2181 server.2=Zookeeper2:2888:3888;2181 server.3=Zookeeper3:2888:3888;2181 server.4=Zookeeper4:2888:3888;2181 server.5=Zookeeper5:2888:3888;2181 networks: default: ipv4_address: 172.17.1.2
Zookeeper3: image: zookeeper hostname: Zookeeper3 volumes: - ~/DockerDesktop/Zookeeper/node3/data:/data - ~/DockerDesktop/Zookeeper/node3/datalog:/datalog environment: ZOO_MY_ID: 3 ZOO_SERVERS: server.1=Zookeeper1:2888:3888;2181 server.2=Zookeeper2:2888:3888;2181 server.3=Zookeeper3:2888:3888;2181 server.4=Zookeeper4:2888:3888;2181 server.5=Zookeeper5:2888:3888;2181 networks: default: ipv4_address: 172.17.1.3
Zookeeper4: image: zookeeper hostname: Zookeeper4 volumes: - ~/DockerDesktop/Zookeeper/node4/data:/data - ~/DockerDesktop/Zookeeper/node4/datalog:/datalog environment: ZOO_MY_ID: 4 ZOO_SERVERS: server.1=Zookeeper1:2888:3888;2181 server.2=Zookeeper2:2888:3888;2181 server.3=Zookeeper3:2888:3888;2181 server.4=Zookeeper4:2888:3888;2181 server.5=Zookeeper5:2888:3888;2181 networks: default: ipv4_address: 172.17.1.4
Zookeeper5: image: zookeeper hostname: Zookeeper5 volumes: - ~/DockerDesktop/Zookeeper/node5/data:/data - ~/DockerDesktop/Zookeeper/node5/datalog:/datalog environment: ZOO_MY_ID: 5 ZOO_SERVERS: server.1=Zookeeper1:2888:3888;2181 server.2=Zookeeper2:2888:3888;2181 server.3=Zookeeper3:2888:3888;2181 server.4=Zookeeper4:2888:3888;2181 server.5=Zookeeper5:2888:3888;2181 networks: default: ipv4_address: 172.17.1.5
networks: default: external: name: net17
|
运行
我们不难发现Zookeeper5成为了集群的leader,其他都都成为了follower
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Zookeeper5_1 | 2020-04-18 09:53:01,840 [myid:5] - INFO [QuorumPeer[myid=5](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: leading - broadcast Zookeeper3_1 | 2020-04-18 09:53:01,871 [myid:3] - INFO [QuorumPeer[myid=3](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@476] - Configuring CommitProcessor with readBatchSize -1 commitBatchSize 1 Zookeeper1_1 | 2020-04-18 09:53:01,874 [myid:1] - INFO [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@476] - Configuring CommitProcessor with readBatchSize -1 commitBatchSize 1 Zookeeper1_1 | 2020-04-18 09:53:01,876 [myid:1] - INFO [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@438] - Configuring CommitProcessor with 1 worker threads. Zookeeper3_1 | 2020-04-18 09:53:01,875 [myid:3] - INFO [QuorumPeer[myid=3](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@438] - Configuring CommitProcessor with 1 worker threads. Zookeeper4_1 | 2020-04-18 09:53:01,874 [myid:4] - INFO [QuorumPeer[myid=4](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@476] - Configuring CommitProcessor with readBatchSize -1 commitBatchSize 1 Zookeeper4_1 | 2020-04-18 09:53:01,882 [myid:4] - INFO [QuorumPeer[myid=4](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@438] - Configuring CommitProcessor with 1 worker threads. Zookeeper2_1 | 2020-04-18 09:53:01,890 [myid:2] - INFO [QuorumPeer[myid=2](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@476] - Configuring CommitProcessor with readBatchSize -1 commitBatchSize 1 Zookeeper2_1 | 2020-04-18 09:53:01,897 [myid:2] - INFO [QuorumPeer[myid=2](plain=0.0.0.0:2181)(secure=disabled):CommitProcessor@438] - Configuring CommitProcessor with 1 worker threads. Zookeeper1_1 | 2020-04-18 09:53:01,909 [myid:1] - INFO [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000 Zookeeper4_1 | 2020-04-18 09:53:01,915 [myid:4] - INFO [QuorumPeer[myid=4](plain=0.0.0.0:2181)(secure=disabled):RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000 Zookeeper3_1 | 2020-04-18 09:53:01,921 [myid:3] - INFO [QuorumPeer[myid=3](plain=0.0.0.0:2181)(secure=disabled):RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000 Zookeeper2_1 | 2020-04-18 09:53:01,928 [myid:2] - INFO [QuorumPeer[myid=2](plain=0.0.0.0:2181)(secure=disabled):RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000 Zookeeper1_1 | 2020-04-18 09:53:02,053 [myid:1] - INFO [QuorumPeer[myid=1](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: following - broadcast Zookeeper4_1 | 2020-04-18 09:53:02,056 [myid:4] - INFO [QuorumPeer[myid=4](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: following - broadcast Zookeeper3_1 | 2020-04-18 09:53:02,063 [myid:3] - INFO [QuorumPeer[myid=3](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: following - broadcast Zookeeper2_1 | 2020-04-18 09:53:02,068 [myid:2] - INFO [QuorumPeer[myid=2](plain=0.0.0.0:2181)(secure=disabled):QuorumPeer@863] - Peer state changed: following - broadcast
|