简体   繁体   English

如何通过卷在 docker 设置中保留 Zookeeper 数据?

[英]How to persist Zookeeper data in a docker setup via a volume?

So, I am setting up Zookeeper in my local environment on docker using the official docker image .因此,我正在使用官方 docker 映像在 docker 上的本地环境中设置 Zookeeper。 Now, what I want with this Zookeeper setup is to be able to persist the nodes and their values by mounting the Zookeeper data directory as a volume inside my container.现在,我想要这个 Zookeeper 设置是能够通过将 Zookeeper 数据目录安装为容器内的卷来持久化节点及其值。

This is straightforward, but what's confusing me is that Zookeeper's data directory inside the container is at /data while the datalog directory is at /datalog .这很简单,但让我感到困惑的是,容器内 Zookeeper 的数据目录位于/data而数据日志目录位于/datalog Ideally, I would expect Zookeeper to persist the nodes and values inside the data folder as well in addition to the datalog directory.理想情况下,除了 datalog 目录之外,我还希望 Zookeeper 将节点和值保存在数据文件夹中。 However, I find that while the datalog directory has the data in log.* files, the data directory does not have any data related to the test nodes that I created.但是,我发现虽然 datalog 目录中有log.*文件中的数据,但数据目录中没有任何与我创建的测试节点相关的数据。

bash-4.4# pwd
/datalog/version-2
bash-4.4# ls
log.1  log.3  log.5  log.8


bash-4.4# pwd
/data/version-2
bash-4.4# ls
bash-4.4# 

My goal is achieved with this Zookeeper service in my docker-compose.yml -我的目标是通过我docker-compose.yml Zookeeper 服务实现的 -

volumes:
  - zkdata:/datalog

but this seems counter-intuitive that I am mounting the transaction logs directory instead of the actual data directory.但这似乎违反直觉,我正在安装事务日志目录而不是实际数据目录。 How and where does Zookeeper actually persist the node data and how can I correctly mount it as a volume in my docker container? Zookeeper 如何以及在何处实际保存节点数据,以及如何将其作为卷正确安装在我的 docker 容器中?

I can actually set the ZOO_DATA_LOG_DIR environmental variable to /data and mount that as a docker volume, but my question is really about why the Zookeeper data is empty while the datalog directory isn't.我实际上可以将ZOO_DATA_LOG_DIR环境变量设置为/data并将其安装为ZOO_DATA_LOG_DIR卷,但我的问题实际上是关于为什么 Zookeeper 数据为空而 datalog 目录不是空的。

Probably you should see the dataDir path in zookeeper config and mount that path in the volumes.可能您应该在 zookeeper 配置中看到 dataDir 路径并将该路径安装在卷中。 In my case zookeeper config is present at /config/zoo.cfg在我的情况下,zookeeper 配置存在于 /config/zoo.cfg

dataDir=/data
dataLogDir=/datalog
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=true
server.1=localhost:2888:3888;2181

dataDir is the place where zookeeper stores the in-memory database snapshots which will be referred in case of failure. dataDir 是zookeeper 存储内存数据库快照的地方,在发生故障时将引用这些快照。

Since the dataDir is /data so I mounted /data directory in volumes so the entry would be :由于 dataDir 是 /data 所以我在卷中安装了 /data 目录,所以条目是:

volumes:
  - zkdata:/data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM