0


Docker 安装Zookeeper

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

查看本地镜像

docker images

检索ZooKeeper 镜像

docker search zookeeper

拉取ZooKeeper镜像最新版本

docker pull zookeeper:latest

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              0e901e68141f        2 months ago        142MB
mysql               5.7                 2a0961b7de03        2 months ago        462MB
minio/minio         latest              e31e0721a96b        7 months ago        406MB
rabbitmq            management          6c3c2a225947        7 months ago        253MB
elasticsearch       7.6.2               f29a1ee41030        2 years ago         791MB
delron/fastdfs      latest              8487e86fc6ee        4 years ago         464MB
[root@localhost ~]# docker search zookeeper
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
zookeeper                          Apache ZooKeeper is an open-source server wh…   1258                [OK]
wurstmeister/zookeeper                                                             168                                     [OK]
jplock/zookeeper                   Builds a docker image for Zookeeper version …   165                                     [OK]
bitnami/zookeeper                  ZooKeeper is a centralized service for distr…   77                                      [OK]
mesoscloud/zookeeper               ZooKeeper                                       73                                      [OK]
digitalwonderland/zookeeper        Latest Zookeeper - clusterable                  23                                      [OK]
debezium/zookeeper                 Zookeeper image required when running the De…   17                                      [OK]

[root@localhost ~]# docker pull zookeeper:latest
latest: Pulling from library/zookeeper
a2abf6c4d29d: Pull complete
2bbde5250315: Pull complete
202a34e7968e: Pull complete
4e4231e30efc: Pull complete
707593b95343: Pull complete
b070e6dedb4b: Pull complete
46e5380f3905: Pull complete
8b7e330117e6: Pull complete
Digest: sha256:2c8c5c2db6db22184e197afde13e33dad849af90004c330f20b17282bcd5afd7
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 # 日志挂载目录


[root@localhost ~]# mkdir -p /usr/local/zookeeper/data
[root@localhost ~]# mkdir -p /usr/local/zookeeper/conf
[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

[root@localhost ~]# 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
WARNING: IPv4 forwarding is disabled. Networking will not work.
1c3d38b948badbe1f74ee90acc567545af1b3c3417112f6c37890c5f4a3264f4

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

# The number of  milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

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

进入zookeeper 容器内部

docker exec -it zookeeper /bin/bash

检查容器状态

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

[root@localhost conf]# docker exec -it zookeeper /bin/bash ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
[root@localhost conf]# docker exec -it zookeeper zkCli.sh
Connecting to localhost:2181
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Welcome to ZooKeeper!
JLine support is enabled

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

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

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

命令:

java -jar zookeeper-dev-ZooInspector.jar

遇到的问题: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


本文转载自: https://blog.csdn.net/zhouzhiwengang/article/details/126168972
版权归原作者 在奋斗的大道 所有, 如有侵权,请联系我们删除。

“Docker 安装Zookeeper”的评论:

还没有评论