Docker Zookeeper 安装及简单使用

安装

1.拉取镜像

docker pull zookeeper

2.启动单实例

  • 执行命令
#--name 为容器指定名称
#-d 指定为后台运行
#--restart  容器的重启策略
# no - 默认值
# on-failure[:max-retries]  只在容器以非0状态码退出时重启
# always 一直直尝试 不管是什么状态码
docker run --name some-zookeeper --restart no -d zookeeper
  • 查看日志
e24-6:~ dailong$ docker run --name some-zookeeper --restart no -d zookeeper
ba8876734a156e1652aad1de156c50a69a71eecbf0df74f6788510130fe0bab7
e24-6:~ dailong$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                    NAMES
ba8876734a15        zookeeper           "/docker-entrypoint.…"   4 seconds ago       Up 3 seconds        2181/tcp, 2888/tcp, 3888/tcp, 8080/tcp   some-zookeeper
e24-6:~ dailong$ docker logs -f ba8876734a15
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
2020-01-20 05:47:50,696 [myid:] - INFO  [main:QuorumPeerConfig@133] - Reading configuration from: /conf/zoo.cfg
2020-01-20 05:47:50,702 [myid:] - INFO  [main:QuorumPeerConfig@375] - clientPort is not set
2020-01-20 05:47:50,702 [myid:] - INFO  [main:QuorumPeerConfig@389] - secureClientPort is not set
2020-01-20 05:47:50,709 [myid:] - ERROR [main:QuorumPeerConfig@645] - Invalid configuration, only one server specified (ignoring)
2020-01-20 05:47:50,716 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2020-01-20 05:47:50,716 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2020-01-20 05:47:50,716 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2020-01-20 05:47:50,717 [myid:1] - WARN  [main:QuorumPeerMain@125] - Either no config or no quorum defined in config, running  in standalone mode
2020-01-20 05:47:50,718 [myid:1] - INFO  [main:ManagedUtil@46] - Log4j found with jmx enabled.
2020-01-20 05:47:50,733 [myid:1] - INFO  [main:QuorumPeerConfig@133] - Reading configuration from: /conf/zoo.cfg
2020-01-20 05:47:50,733 [myid:1] - INFO  [main:QuorumPeerConfig@375] - clientPort is not set
2020-01-20 05:47:50,733 [myid:1] - INFO  [main:QuorumPeerConfig@389] - secureClientPort is not set
2020-01-20 05:47:50,734 [myid:1] - ERROR [main:QuorumPeerConfig@645] - Invalid configuration, only one server specified (ignoring)
2020-01-20 05:47:50,734 [myid:1] - INFO  [main:ZooKeeperServerMain@117] - Starting server
2020-01-20 05:47:50,738 [myid:1] - INFO  [main:FileTxnSnapLog@103] - zookeeper.snapshot.trust.empty : false
2020-01-20 05:47:50,753 [myid:1] - INFO  [main:Environment@109] - Server environment:zookeeper.version=3.5.6-c11b7e26bc554b8523dc929761dd28808913f091, built on 10/08/2019 20:18 GMT
2020-01-20 05:47:50,755 [myid:1] - INFO  [main:Environment@109] - Server environment:host.name=ba8876734a15
2020-01-20 05:47:50,755 [myid:1] - INFO  [main:Environment@109] - Server environment:java.version=1.8.0_232
2020-01-20 05:47:50,755 [myid:1] - INFO  [main:Environment@109] - Server environment:java.vendor=Oracle Corporation
2020-01-20 05:47:50,756 [myid:1] - INFO  [main:Environment@109] - Server environment:java.home=/usr/local/openjdk-8
2020-01-20 05:47:50,756 [myid:1] - INFO  [main:Environment@109] - Server environment:java.class.path=/apache-zookeeper-3.5.6-bin/bin/../zookeeper-server/target/classes:/apache-zookeeper-3.5.6-bin/bin/../build/classes:/apache-zookeeper-3.5.6-bin/bin/../zookeeper-server/target/lib/*.jar:/apache-zookeeper-3.5.6-bin/bin/../build/lib/*.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/zookeeper-jute-3.5.6.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/zookeeper-3.5.6.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/slf4j-log4j12-1.7.25.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/slf4j-api-1.7.25.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-transport-native-unix-common-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-transport-native-epoll-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-transport-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-resolver-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-handler-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-common-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-codec-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/netty-buffer-4.1.42.Final.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/log4j-1.2.17.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/json-simple-1.1.1.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jline-2.11.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jetty-util-9.4.17.v20190418.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jetty-servlet-9.4.17.v20190418.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jetty-server-9.4.17.v20190418.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jetty-security-9.4.17.v20190418.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jetty-io-9.4.17.v20190418.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jetty-http-9.4.17.v20190418.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jackson-databind-2.9.10.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jackson-core-2.9.10.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/jackson-annotations-2.9.10.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/commons-cli-1.2.jar:/apache-zookeeper-3.5.6-bin/bin/../lib/audience-annotations-0.5.0.jar:/apache-zookeeper-3.5.6-bin/bin/../zookeeper-*.jar:/apache-zookeeper-3.5.6-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/conf:
2020-01-20 05:47:50,757 [myid:1] - INFO  [main:Environment@109] - Server environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2020-01-20 05:47:50,757 [myid:1] - INFO  [main:Environment@109] - Server environment:java.io.tmpdir=/tmp
2020-01-20 05:47:50,757 [myid:1] - INFO  [main:Environment@109] - Server environment:java.compiler=<NA>
2020-01-20 05:47:50,757 [myid:1] - INFO  [main:Environment@109] - Server environment:os.name=Linux
2020-01-20 05:47:50,757 [myid:1] - INFO  [main:Environment@109] - Server environment:os.arch=amd64
2020-01-20 05:47:50,758 [myid:1] - INFO  [main:Environment@109] - Server environment:os.version=4.9.184-linuxkit
2020-01-20 05:47:50,758 [myid:1] - INFO  [main:Environment@109] - Server environment:user.name=zookeeper
2020-01-20 05:47:50,758 [myid:1] - INFO  [main:Environment@109] - Server environment:user.home=/home/zookeeper
2020-01-20 05:47:50,758 [myid:1] - INFO  [main:Environment@109] - Server environment:user.dir=/apache-zookeeper-3.5.6-bin
2020-01-20 05:47:50,758 [myid:1] - INFO  [main:Environment@109] - Server environment:os.memory.free=37MB
2020-01-20 05:47:50,758 [myid:1] - INFO  [main:Environment@109] - Server environment:os.memory.max=889MB
2020-01-20 05:47:50,759 [myid:1] - INFO  [main:Environment@109] - Server environment:os.memory.total=46MB
2020-01-20 05:47:50,762 [myid:1] - INFO  [main:ZooKeeperServer@938] - minSessionTimeout set to 4000
2020-01-20 05:47:50,762 [myid:1] - INFO  [main:ZooKeeperServer@947] - maxSessionTimeout set to 40000
2020-01-20 05:47:50,763 [myid:1] - INFO  [main:ZooKeeperServer@166] - Created server with tickTime 2000 minSessionTimeout 4000 maxSessionTimeout 40000 datadir /datalog/version-2 snapdir /data/version-2
2020-01-20 05:47:50,797 [myid:1] - INFO  [main:Log@193] - Logging initialized @518ms to org.eclipse.jetty.util.log.Slf4jLog
2020-01-20 05:47:50,938 [myid:1] - WARN  [main:ContextHandler@1588] - o.e.j.s.ServletContextHandler@5649fd9b{/,null,UNAVAILABLE} contextPath ends with /*
2020-01-20 05:47:50,938 [myid:1] - WARN  [main:ContextHandler@1599] - Empty contextPath
2020-01-20 05:47:50,963 [myid:1] - INFO  [main:Server@370] - jetty-9.4.17.v20190418; built: 2019-04-18T19:45:35.259Z; git: aa1c656c315c011c01e7b21aabb04066635b9f67; jvm 1.8.0_232-b09
2020-01-20 05:47:51,009 [myid:1] - INFO  [main:DefaultSessionIdManager@365] - DefaultSessionIdManager workerName=node0
2020-01-20 05:47:51,009 [myid:1] - INFO  [main:DefaultSessionIdManager@370] - No SessionScavenger set, using defaults
2020-01-20 05:47:51,012 [myid:1] - INFO  [main:HouseKeeper@149] - node0 Scavenging every 660000ms
2020-01-20 05:47:51,028 [myid:1] - INFO  [main:ContextHandler@855] - Started o.e.j.s.ServletContextHandler@5649fd9b{/,null,AVAILABLE}
2020-01-20 05:47:51,041 [myid:1] - INFO  [main:AbstractConnector@292] - Started ServerConnector@4520ebad{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2020-01-20 05:47:51,041 [myid:1] - INFO  [main:Server@410] - Started @770ms
2020-01-20 05:47:51,042 [myid:1] - INFO  [main:JettyAdminServer@112] - Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands
2020-01-20 05:47:51,046 [myid:1] - INFO  [main:ServerCnxnFactory@135] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2020-01-20 05:47:51,049 [myid:1] - INFO  [main:NIOServerCnxnFactory@673] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 4 worker threads, and 64 kB direct buffers.
2020-01-20 05:47:51,050 [myid:1] - INFO  [main:NIOServerCnxnFactory@686] - binding to port /0.0.0.0:2181
2020-01-20 05:47:51,064 [myid:1] - INFO  [main:ZKDatabase@117] - zookeeper.snapshotSizeFactor = 0.33
2020-01-20 05:47:51,067 [myid:1] - INFO  [main:FileTxnSnapLog@384] - Snapshotting: 0x0 to /data/version-2/snapshot.0
2020-01-20 05:47:51,069 [myid:1] - INFO  [main:FileTxnSnapLog@384] - Snapshotting: 0x0 to /data/version-2/snapshot.0
2020-01-20 05:47:51,086 [myid:1] - INFO  [main:ContainerManager@64] - Using checkIntervalMs=60000 maxPerMinute=10000

3.启动多实例集群,利用docker-compose

e24-6:docker dailong$ cat docker-compose.yml 
version: '3.1'

services:
  zoo1:
    image: zookeeper
    restart: always
    hostname: zoo1
    ports:
      - 2181:2181
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0: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
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181

  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    ports:
      - 2183:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
  • 到yml文件目录,运行命令即可:
e24-6:docker dailong$ ls
docker-compose.yml
e24-6:docker dailong$ docker-compose up -d
Creating docker_zoo1_1 ... done
Creating docker_zoo2_1 ... done
Creating docker_zoo3_1 ... done
e24-6:docker dailong$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                  NAMES
84ee34d1533c        zookeeper           "/docker-entrypoint.…"   20 seconds ago      Up 17 seconds       2888/tcp, 3888/tcp, 8080/tcp, 0.0.0.0:2183->2181/tcp   docker_zoo3_1
9e86f2fbd18a        zookeeper           "/docker-entrypoint.…"   20 seconds ago      Up 17 seconds       2888/tcp, 3888/tcp, 8080/tcp, 0.0.0.0:2182->2181/tcp   docker_zoo2_1
adffe1bfb865        zookeeper           "/docker-entrypoint.…"   20 seconds ago      Up 17 seconds       2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp   docker_zoo1_1
e24-6:docker dailong$ 
  1. WEB可视化页面
    https://blog.csdn.net/uisoul/article/details/78226324

我之前也没接触过,只听说过了解,使用后面补

参考链接

https://hub.docker.com/_/zookeeper 内有详细安装步骤
https://docs.docker.com/install/ docker文档

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,732评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,496评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,264评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,807评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,806评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,675评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,029评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,683评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,704评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,666评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,773评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,413评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,016评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,978评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,204评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,083评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,503评论 2 343

推荐阅读更多精彩内容