Docker 安装Zookeeper

比眉伴天荒 2023-10-10 14:41 160阅读 0赞

第一步:查看本地镜像和检索拉取Zookeeper 镜像

# 查看本地镜像

docker images

# 检索ZooKeeper 镜像

docker search zookeeper

# 拉取ZooKeeper镜像最新版本

docker pull zookeeper:latest

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. nginx latest 0e901e68141f 2 months ago 142MB
  4. mysql 5.7 2a0961b7de03 2 months ago 462MB
  5. minio/minio latest e31e0721a96b 7 months ago 406MB
  6. rabbitmq management 6c3c2a225947 7 months ago 253MB
  7. elasticsearch 7.6.2 f29a1ee41030 2 years ago 791MB
  8. delron/fastdfs latest 8487e86fc6ee 4 years ago 464MB
  9. [root@localhost ~]# docker search zookeeper
  10. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  11. zookeeper Apache ZooKeeper is an open-source server wh 1258 [OK]
  12. wurstmeister/zookeeper 168 [OK]
  13. jplock/zookeeper Builds a docker image for Zookeeper version 165 [OK]
  14. bitnami/zookeeper ZooKeeper is a centralized service for distr 77 [OK]
  15. mesoscloud/zookeeper ZooKeeper 73 [OK]
  16. digitalwonderland/zookeeper Latest Zookeeper - clusterable 23 [OK]
  17. debezium/zookeeper Zookeeper image required when running the De 17 [OK]
  18. [root@localhost ~]# docker pull zookeeper:latest
  19. latest: Pulling from library/zookeeper
  20. a2abf6c4d29d: Pull complete
  21. 2bbde5250315: Pull complete
  22. 202a34e7968e: Pull complete
  23. 4e4231e30efc: Pull complete
  24. 707593b95343: Pull complete
  25. b070e6dedb4b: Pull complete
  26. 46e5380f3905: Pull complete
  27. 8b7e330117e6: Pull complete
  28. Digest: sha256:2c8c5c2db6db22184e197afde13e33dad849af90004c330f20b17282bcd5afd7
  29. Status: Downloaded newer image for zookeeper:latest

第二步:创建ZooKeeper 挂载目录(数据挂载目录、配置挂载目录和日志挂载目录)

mkdir -p /usr/local/zookeeper/data # 数据挂载目录
mkdir -p /usr/local/zookeeper/conf # 配置挂载目录
mkdir -p /usr/local/zookeeper/logs # 日志挂载目录

  1. [root@localhost ~]# mkdir -p /usr/local/zookeeper/data
  2. [root@localhost ~]# mkdir -p /usr/local/zookeeper/conf
  3. [root@localhost ~]# mkdir -p /usr/local/zookeeper/logs

第三步:启动ZooKeeper容器

docker run -d \
--name zookeeper \
--privileged=true \
-p 2181:2181 \
--restart=always \
-v /usr/local/zookeeper/data:/data \
-v /usr/local/zookeeper/conf:/conf \
-v /usr/local/zookeeper/logs:/datalog \
zookeeper

  1. [root@localhost ~]# docker run -d \
  2. > --name zookeeper \
  3. > --privileged=true \
  4. > -p 2181:2181 \
  5. > --restart=always \
  6. > -v /usr/local/zookeeper/data:/data \
  7. > -v /usr/local/zookeeper/conf:/conf \
  8. > -v /usr/local/zookeeper/logs:/datalog \
  9. > zookeeper
  10. WARNING: IPv4 forwarding is disabled. Networking will not work.
  11. 1c3d38b948badbe1f74ee90acc567545af1b3c3417112f6c37890c5f4a3264f4

第四步:添加ZooKeeper配置文件,在挂载配置文件目录(/user/local/zookeeper/conf)下,新增zoo.cfg 配置文件,配置内容如下:

  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just
  11. # example sakes.
  12. dataDir=/data
  13. # the port at which the clients will connect
  14. clientPort=2181
  15. # the maximum number of client connections.
  16. # increase this if you need to handle more clients
  17. #maxClientCnxns=60
  18. #
  19. # Be sure to read the maintenance section of the
  20. # administrator guide before turning on autopurge.
  21. #
  22. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  23. #
  24. # The number of snapshots to retain in dataDir
  25. #autopurge.snapRetainCount=3
  26. # Purge task interval in hours
  27. # Set to "0" to disable auto purge feature
  28. #autopurge.purgeInterval=1
  29. ## Metrics Providers
  30. #
  31. # https://prometheus.io Metrics Exporter
  32. #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
  33. #metricsProvider.httpPort=7000
  34. #metricsProvider.exportJvmInfo=true

第五步:进入容器内部,验证容器状态

# 进入zookeeper 容器内部

docker exec -it zookeeper /bin/bash

# 检查容器状态

docker exec -it zookeeper /bin/bash ./bin/zkServer.sh status

  1. [root@localhost conf]# docker exec -it zookeeper /bin/bash ./bin/zkServer.sh status
  2. ZooKeeper JMX enabled by default
  3. Using config: /conf/zoo.cfg
  4. Client port found: 2181. Client address: localhost. Client SSL: false.
  5. Mode: standalone
  6. [root@localhost conf]# docker exec -it zookeeper zkCli.sh
  7. Connecting to localhost:2181
  8. log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
  9. log4j:WARN Please initialize the log4j system properly.
  10. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  11. Welcome to ZooKeeper!
  12. JLine support is enabled
  13. WATCHER::
  14. WatchedEvent state:SyncConnected type:None path:null

第六步:安装ZooInspector客户端连接

下载地址:https://issues.apache.org/jira/secure/attachment/12436620/ZooInspector.zip;

命令:java -jar zookeeper-dev-ZooInspector.jar

323c138d1c704a2ab1b48ba10280286b.png

遇到的问题:WARNING: IPv4 forwarding is disabled. Networking will not work

解决办法:

# vi /etc/sysctl.conf

或者

# vi /usr/lib/sysctl.d/00-system.conf

添加如下代码:

net.ipv4.ip_forward=1

重启network服务

# systemctl restart network

发表评论

表情:
评论列表 (有 0 条评论,160人围观)

还没有评论,来说两句吧...

相关阅读

    相关 docker 安装 zookeeper

    镜像下载 hub.docker.com 上有不少 ZK 镜像, 不过为了稳定起见, 我们就使用官方的 ZK 镜像吧. 首先执行如下命令: docker pull zo