Docker下安装zookeeper(单机 & 集群)

Docker下安装zookeeper(单机 & 集群)

1.下载:

docker pull zookeeper

经常拉取镜像的时候很慢或者拉不下来,这里可以使用阿里云镜像加速器,然后试试看有没有效果
使用阿里云镜像加速器 .设置阿里云镜像(可在阿里云中找到自己的镜像加速服务)

[root@localhost ~]# sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

2.docker 查看镜像ID

docker images

3.启动镜像:

docker run -d -p 2181:2181 --name some-zookeeper --restart always 镜像ID

4.启动

[root@localhost admin]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                  NAMES
d5c6f857cd88        3487af26dee9        "/docker-entrypoin..."   4 seconds ago       Up 3 seconds        2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp   some-zookeeper
[root@localhost admin]# docker exec -it d5c6f857cd88 bash
root@d5c6f857cd88:/apache-zookeeper-3.5.5-bin# ./bin/zkCli.sh
Connecting to localhost:2181
2019-08-29 07:15:21,623 [myid:] - INFO  [main:Environment@109] - Client environment:zookeeper.version=3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT
2019-08-29 07:15:21,679 [myid:] - INFO  [main:Environment@109] - Client environment:host.name=d5c6f857cd88
2019-08-29 07:15:21,680 [myid:] - INFO  [main:Environment@109] - Client environment:java.version=1.8.0_222
2019-08-29 07:15:21,717 [myid:] - INFO  [main:Environment@109] - Client environment:java.vendor=Oracle Corporation
2019-08-29 07:15:21,718 [myid:] - INFO  [main:Environment@109] - Client environment:java.home=/usr/local/openjdk-8
2019-08-29 07:15:21,725 [myid:] - INFO  [main:Environment@109] - Client environment:java.class.path=/apache-zookeeper-3.5.5-bin/bin/../zookeeper-server/target/classes:/apache-zookeeper-3.5.5-bin/bin/../build/classes:/apache-zookeeper-3.5.5-bin/bin/../zookeeper-server/target/lib/*.jar:/apache-zookeeper-3.5.5-bin/bin/../build/lib/*.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/zookeeper-jute-3.5.5.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/zookeeper-3.5.5.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/slf4j-log4j12-1.7.25.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/slf4j-api-1.7.25.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/netty-all-4.1.29.Final.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/log4j-1.2.17.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/json-simple-1.1.1.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jline-2.11.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jetty-util-9.4.17.v20190418.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jetty-servlet-9.4.17.v20190418.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jetty-server-9.4.17.v20190418.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jetty-security-9.4.17.v20190418.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jetty-io-9.4.17.v20190418.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jetty-http-9.4.17.v20190418.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jackson-databind-2.9.8.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jackson-core-2.9.8.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/jackson-annotations-2.9.0.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/commons-cli-1.2.jar:/apache-zookeeper-3.5.5-bin/bin/../lib/audience-annotations-0.5.0.jar:/apache-zookeeper-3.5.5-bin/bin/../zookeeper-*.jar:/apache-zookeeper-3.5.5-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/conf:
2019-08-29 07:15:22,108 [myid:] - INFO  [main:Environment@109] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-08-29 07:15:22,109 [myid:] - INFO  [main:Environment@109] - Client environment:java.io.tmpdir=/tmp
2019-08-29 07:15:22,109 [myid:] - INFO  [main:Environment@109] - Client environment:java.compiler=<NA>
2019-08-29 07:15:22,109 [myid:] - INFO  [main:Environment@109] - Client environment:os.name=Linux
2019-08-29 07:15:22,109 [myid:] - INFO  [main:Environment@109] - Client environment:os.arch=amd64
2019-08-29 07:15:22,110 [myid:] - INFO  [main:Environment@109] - Client environment:os.version=3.10.0-862.9.1.el7.x86_64
2019-08-29 07:15:22,110 [myid:] - INFO  [main:Environment@109] - Client environment:user.name=root
2019-08-29 07:15:22,110 [myid:] - INFO  [main:Environment@109] - Client environment:user.home=/root
2019-08-29 07:15:22,110 [myid:] - INFO  [main:Environment@109] - Client environment:user.dir=/apache-zookeeper-3.5.5-bin
2019-08-29 07:15:22,118 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.free=11MB
2019-08-29 07:15:22,148 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.max=247MB
2019-08-29 07:15:22,148 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.total=15MB
2019-08-29 07:15:22,206 [myid:] - INFO  [main:ZooKeeper@868] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@3b95a09c
2019-08-29 07:15:22,239 [myid:] - INFO  [main:X509Util@79] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2019-08-29 07:15:22,285 [myid:] - INFO  [main:ClientCnxnSocket@237] - jute.maxbuffer value is 4194304 Bytes
2019-08-29 07:15:22,366 [myid:] - INFO  [main:ClientCnxn@1653] - zookeeper.request.timeout value is 0. feature enabled=
Welcome to ZooKeeper!
JLine support is enabled
2019-08-29 07:15:22,563 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1112] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
2019-08-29 07:15:23,443 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@959] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:37198, server: localhost/0:0:0:0:0:0:0:1:2181
2019-08-29 07:15:23,520 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1394] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x10001216d990000, negotiated timeout = 30000
 
WATCHER::
 
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] quit
 
WATCHER::
 
WatchedEvent state:Closed type:None path:null
2019-08-29 07:15:37,042 [myid:] - INFO  [main:ZooKeeper@1422] - Session: 0x10001216d990000 closed
2019-08-29 07:15:37,043 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@524] - EventThread shut down for session: 0x10001216d990000
root@d5c6f857cd88:/apache-zookeeper-3.5.5-bin# exit
exit
[root@localhost admin]#

Copyright: 采用 知识共享署名4.0 国际许可协议进行许可

Links: https://qingjiaqi.com/archives/docker下安装zookeeper单机集群

Buy me a cup of coffee ☕.