简单记一笔,docker下zookeeper集群搭建

镜像下载

 

执行如下命令

docker pull zookeeper  

默认会从官方镜像库拉取最新zk镜像

xxx>docker pull zookeeper
Using default tag: latest
latest: Pulling from library/zookeeper
6ec7b7d162b2: Downloading [============================> ] 15.34MB/27.1MB
177617b11d13: Downloading
10273812b9e3: Downloading
ac553cdb1df6: Downloading
ad2343433791: Download complete
b5eb0bf88a7c: Download complete
4650505930d7: Download complete
2dbba1d515b1: Download complete
latest: Pulling from library/zookeeper
6ec7b7d162b2: Pull complete
177617b11d13: Pull complete
10273812b9e3: Pull complete
ac553cdb1df6: Pull complete
ad2343433791: Pull complete
b5eb0bf88a7c: Pull complete
4650505930d7: Pull complete
2dbba1d515b1: Pull complete
Digest: sha256:68bbbba086e3812851555b322574c355335552832147a58145d77580ca2098b2
Status: Downloaded newer image for zookeeper:latest
docker.io/library/zookeeper:latest

  

 

 1.单节点启动

xxx>docker run --name my_zk -d zookeeper
c7267ee85687482ad764781bace45a95d666e32756212de36890087c5c761bc5

查看日志

C:\Users\xxx>docker logs -f my_zk
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
2020-12-29 04:02:10,313 [myid:] - INFO  [main:QuorumPeerConfig@174] - Reading configuration from: /conf/zoo.cfg
2020-12-29 04:02:10,316 [myid:] - INFO  [main:QuorumPeerConfig@451] - clientPort is not set
2020-12-29 04:02:10,316 [myid:] - INFO  [main:QuorumPeerConfig@464] - secureClientPort is not set
2020-12-29 04:02:10,316 [myid:] - INFO  [main:QuorumPeerConfig@480] - observerMasterPort is not set
2020-12-29 04:02:10,317 [myid:] - INFO  [main:QuorumPeerConfig@497] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
2020-12-29 04:02:10,320 [myid:] - ERROR [main:QuorumPeerConfig@722] - Invalid configuration, only one server specified (ignoring)
2020-12-29 04:02:10,323 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2020-12-29 04:02:10,323 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2020-12-29 04:02:10,323 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2020-12-29 04:02:10,323 [myid:1] - WARN  [main:QuorumPeerMain@138] - Either no config or no quorum defined in config, running in standalone mode
2020-12-29 04:02:10,326 [myid:1] - INFO  [main:ManagedUtil@44] - Log4j 1.2 jmx support found and enabled.
2020-12-29 04:02:10,331 [myid:1] - INFO  [main:QuorumPeerConfig@174] - Reading configuration from: /conf/zoo.cfg
2020-12-29 04:02:10,331 [myid:1] - INFO  [main:QuorumPeerConfig@451] - clientPort is not set
2020-12-29 04:02:10,331 [myid:1] - INFO  [main:QuorumPeerConfig@464] - secureClientPort is not set
2020-12-29 04:02:10,332 [myid:1] - INFO  [main:QuorumPeerConfig@480] - observerMasterPort is not set
2020-12-29 04:02:10,332 [myid:1] - INFO  [main:QuorumPeerConfig@497] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
2020-12-29 04:02:10,333 [myid:1] - ERROR [main:QuorumPeerConfig@722] - Invalid configuration, only one server specified (ignoring)
2020-12-29 04:02:10,333 [myid:1] - INFO  [main:ZooKeeperServerMain@122] - Starting server
2020-12-29 04:02:10,341 [myid:1] - INFO  [main:ServerMetrics@62] - ServerMetrics initialized with provider org.apache.zookeeper.metrics.impl.DefaultMetricsProvider@76ed1b7c
2020-12-29 04:02:10,343 [myid:1] - INFO  [main:FileTxnSnapLog@124] - zookeeper.snapshot.trust.empty : false
2020-12-29 04:02:10,349 [myid:1] - INFO  [main:ZookeeperBanner@42] -
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -   ______                  _                        
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -  |___  /                 | |                       
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -     / /    ___     ___   | | __   ___    ___   _ __     ___   _ __
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -    / /    / _ \   / _ \  | |/ /  / _ \  / _ \ | '_ \   / _ \ | '__|
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -   / /__  | (_) | | (_) | |   <  |  __/ |  __/ | |_) | |  __/ | |
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -  /_____|  \___/   \___/  |_|\_\  \___|  \___| | .__/   \___| |_|
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -                                               | |  
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -                                               |_|  
2020-12-29 04:02:10,350 [myid:1] - INFO  [main:ZookeeperBanner@42] -
2020-12-29 04:02:10,351 [myid:1] - INFO  [main:Environment@98] - Server environment:zookeeper.version=3.6.2--803c7f1a12f85978cb049af5e4ef23bd8b688715, built on 09/04/2020 12:44 GMT
2020-12-29 04:02:10,351 [myid:1] - INFO  [main:Environment@98] - Server environment:host.name=c7267ee85687
2020-12-29 04:02:10,351 [myid:1] - INFO  [main:Environment@98] - Server environment:java.version=11.0.9.1
2020-12-29 04:02:10,351 [myid:1] - INFO  [main:Environment@98] - Server environment:java.vendor=Oracle Corporation
2020-12-29 04:02:10,351 [myid:1] - INFO  [main:Environment@98] - Server environment:java.home=/usr/local/openjdk-11
2020-12-29 04:02:10,351 [myid:1] - INFO  [main:Environment@98] - Server environment:java.class.path=/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/target/classes:/apache-zookeeper-3.6.2-bin/bin/../build/classes:/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/target/lib/*.jar:/apache-zookeeper-3.6.2-bin/bin/../build/lib/*.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-prometheus-metrics-3.6.2.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-jute-3.6.2.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-3.6.2.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/snappy-java-1.1.7.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/slf4j-log4j12-1.7.25.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/slf4j-api-1.7.25.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_servlet-0.6.0.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_hotspot-0.6.0.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_common-0.6.0.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient-0.6.0.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-native-unix-common-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-native-epoll-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-resolver-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-handler-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-common-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-codec-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/netty-buffer-4.1.50.Final.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/metrics-core-3.2.5.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/log4j-1.2.17.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/json-simple-1.1.1.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jline-2.14.6.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-util-9.4.24.v20191120.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-server-9.4.24.v20191120.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-security-9.4.24.v20191120.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-io-9.4.24.v20191120.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-http-9.4.24.v20191120.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-databind-2.10.3.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-core-2.10.3.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-annotations-2.10.3.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/commons-lang-2.6.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/commons-cli-1.2.jar:/apache-zookeeper-3.6.2-bin/bin/../lib/audience-annotations-0.5.0.jar:/apache-zookeeper-3.6.2-bin/bin/../zookeeper-*.jar:/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/conf:
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:java.library.path=/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:java.io.tmpdir=/tmp
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:java.compiler=<NA>
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:os.name=Linux
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:os.arch=amd64
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:os.version=4.19.104-microsoft-standard
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:user.name=zookeeper
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:user.home=/home/zookeeper
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:user.dir=/apache-zookeeper-3.6.2-bin
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.free=183MB
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.max=1000MB
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.total=198MB
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:ZooKeeperServer@129] - zookeeper.enableEagerACLCheck = false
2020-12-29 04:02:10,352 [myid:1] - INFO  [main:ZooKeeperServer@137] - zookeeper.digest.enabled = true
2020-12-29 04:02:10,353 [myid:1] - INFO  [main:ZooKeeperServer@141] - zookeeper.closeSessionTxn.enabled = true
2020-12-29 04:02:10,353 [myid:1] - INFO  [main:ZooKeeperServer@1444] - zookeeper.flushDelay=0
2020-12-29 04:02:10,353 [myid:1] - INFO  [main:ZooKeeperServer@1453] - zookeeper.maxWriteQueuePollTime=0
2020-12-29 04:02:10,353 [myid:1] - INFO  [main:ZooKeeperServer@1462] - zookeeper.maxBatchSize=1000
2020-12-29 04:02:10,353 [myid:1] - INFO  [main:ZooKeeperServer@243] - zookeeper.intBufferStartingSizeBytes = 1024
2020-12-29 04:02:10,354 [myid:1] - INFO  [main:BlueThrottle@141] - Weighed connection throttling is disabled
2020-12-29 04:02:10,354 [myid:1] - INFO  [main:ZooKeeperServer@1256] - minSessionTimeout set to 4000
2020-12-29 04:02:10,355 [myid:1] - INFO  [main:ZooKeeperServer@1265] - maxSessionTimeout set to 40000
2020-12-29 04:02:10,355 [myid:1] - INFO  [main:ResponseCache@45] - Response cache size is initialized with value 400.
2020-12-29 04:02:10,355 [myid:1] - INFO  [main:ResponseCache@45] - Response cache size is initialized with value 400.
2020-12-29 04:02:10,356 [myid:1] - INFO  [main:RequestPathMetricsCollector@111] - zookeeper.pathStats.slotCapacity = 60
2020-12-29 04:02:10,356 [myid:1] - INFO  [main:RequestPathMetricsCollector@112] - zookeeper.pathStats.slotDuration = 15
2020-12-29 04:02:10,356 [myid:1] - INFO  [main:RequestPathMetricsCollector@113] - zookeeper.pathStats.maxDepth = 6
2020-12-29 04:02:10,356 [myid:1] - INFO  [main:RequestPathMetricsCollector@114] - zookeeper.pathStats.initialDelay = 5
2020-12-29 04:02:10,356 [myid:1] - INFO  [main:RequestPathMetricsCollector@115] - zookeeper.pathStats.delay = 5
2020-12-29 04:02:10,356 [myid:1] - INFO  [main:RequestPathMetricsCollector@116] - zookeeper.pathStats.enabled = false
2020-12-29 04:02:10,358 [myid:1] - INFO  [main:ZooKeeperServer@1481] - The max bytes for all large requests are set to 104857600
2020-12-29 04:02:10,358 [myid:1] - INFO  [main:ZooKeeperServer@1495] - The large request threshold is set to -1
2020-12-29 04:02:10,358 [myid:1] - INFO  [main:ZooKeeperServer@339] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 clientPortListenBacklog -1 datadir /datalog/version-2 snapdir /data/version-2
2020-12-29 04:02:10,379 [myid:1] - INFO  [main:Log@169] - Logging initialized @375ms to org.eclipse.jetty.util.log.Slf4jLog
2020-12-29 04:02:10,432 [myid:1] - WARN  [main:ContextHandler@1520] - o.e.j.s.ServletContextHandler@d554c5f{/,null,UNAVAILABLE} contextPath ends with /*
2020-12-29 04:02:10,432 [myid:1] - WARN  [main:ContextHandler@1531] - Empty contextPath
2020-12-29 04:02:10,446 [myid:1] - INFO  [main:Server@359] - jetty-9.4.24.v20191120; built: 2019-11-20T21:37:49.771Z; git: 363d5f2df3a8a28de40604320230664b9c793c16; jvm 11.0.9.1+1
2020-12-29 04:02:10,478 [myid:1] - INFO  [main:DefaultSessionIdManager@333] - DefaultSessionIdManager workerName=node0
2020-12-29 04:02:10,478 [myid:1] - INFO  [main:DefaultSessionIdManager@338] - No SessionScavenger set, using defaults
2020-12-29 04:02:10,479 [myid:1] - INFO  [main:HouseKeeper@140] - node0 Scavenging every 600000ms
2020-12-29 04:02:10,481 [myid:1] - WARN  [main:ConstraintSecurityHandler@757] - ServletContext@o.e.j.s.ServletContextHandler@d554c5f{/,null,STARTING} has uncovered http methods for path: /*
2020-12-29 04:02:10,485 [myid:1] - INFO  [main:ContextHandler@825] - Started o.e.j.s.ServletContextHandler@d554c5f{/,null,AVAILABLE}
2020-12-29 04:02:10,495 [myid:1] - INFO  [main:AbstractConnector@330] - Started ServerConnector@8519cb4{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2020-12-29 04:02:10,496 [myid:1] - INFO  [main:Server@399] - Started @497ms
2020-12-29 04:02:10,496 [myid:1] - INFO  [main:JettyAdminServer@182] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
2020-12-29 04:02:10,499 [myid:1] - INFO  [main:ServerCnxnFactory@169] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2020-12-29 04:02:10,500 [myid:1] - WARN  [main:ServerCnxnFactory@309] - maxCnxns is not configured, using default value 0.
2020-12-29 04:02:10,500 [myid:1] - INFO  [main:NIOServerCnxnFactory@666] - Configuring NIO connection handler with 10s sessionless connection timeout, 2 selector thread(s), 24 worker threads, and 64 kB direct buffers.
2020-12-29 04:02:10,501 [myid:1] - INFO  [main:NIOServerCnxnFactory@674] - binding to port /0.0.0.0:2181
2020-12-29 04:02:10,512 [myid:1] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-12-29 04:02:10,512 [myid:1] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
2020-12-29 04:02:10,513 [myid:1] - INFO  [main:ZKDatabase@132] - zookeeper.snapshotSizeFactor = 0.33
2020-12-29 04:02:10,513 [myid:1] - INFO  [main:ZKDatabase@152] - zookeeper.commitLogCount=500
2020-12-29 04:02:10,517 [myid:1] - INFO  [main:SnapStream@61] - zookeeper.snapshot.compression.method = CHECKED
2020-12-29 04:02:10,517 [myid:1] - INFO  [main:FileTxnSnapLog@470] - Snapshotting: 0x0 to /data/version-2/snapshot.0
2020-12-29 04:02:10,519 [myid:1] - INFO  [main:ZKDatabase@289] - Snapshot loaded in 6 ms, highest zxid is 0x0, digest is 1371985504
2020-12-29 04:02:10,519 [myid:1] - INFO  [main:FileTxnSnapLog@470] - Snapshotting: 0x0 to /data/version-2/snapshot.0
2020-12-29 04:02:10,519 [myid:1] - INFO  [main:ZooKeeperServer@529] - Snapshot taken in 0 ms
2020-12-29 04:02:10,526 [myid:1] - INFO  [ProcessThread(sid:0 cport:2181)::PrepRequestProcessor@136] - PrepRequestProcessor (sid:0) started, reconfigEnabled=false
2020-12-29 04:02:10,527 [myid:1] - INFO  [main:RequestThrottler@74] - zookeeper.request_throttler.shutdownTimeout = 10000
2020-12-29 04:02:10,536 [myid:1] - INFO  [main:ContainerManager@83] - Using checkIntervalMs=60000 maxPerMinute=10000 maxNeverUsedIntervalMs=0
2020-12-29 04:02:10,536 [myid:1] - INFO  [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.

2.集群搭建

使用docker-compose来启动多个zk容器

先编写一个docker-compose-zookeeper.yaml文件

version: '3'

services:
  zoo1:
    image: zookeeper
    restart: always
    hostname: zoo1
    ports:
      - 2181:2181
    networks:
      - zookeeper
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181

  zoo2:
    image: zookeeper
    restart: always
    hostname: zoo2
    ports:
      - 2182:2181
    networks:
      - zookeeper
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181

  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    ports:
      - 2183:2181
    networks:
      - zookeeper
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
networks:
  zookeeper:
    driver: bridge

  执行上边写好的文件 

# 启动所有Zookeeper服务
docker-compose -f docker-compose-zookeeper.yaml up -d

  使用客户端去连接测试,我这里使用的是ZooInspector

# 命令行中打开
D:\download\ZooInspector\build>java -jar zookeeper-dev-ZooInspector.jar

  效果:下边是创建好的节点

 

posted @ 2020-12-29 16:16  llCoding  阅读(969)  评论(0编辑  收藏  举报