gpt4 book ai didi

Azure 应用服务中的 MongoDB,通过 Docker-Compose

转载 作者:行者123 更新时间:2023-12-03 06:25:51 26 4
gpt4 key购买 nike

我会保持这个非常简单,因为我已经回到了基础知识 - 我的容器配置有点复杂,但这很快就证明了问题。

我有以下适用于 Azure 应用服务的 docker-compose:

version: '3.4'
services:


mongo:
image: myrepo/myrepo:mongo-1
restart: always
volumes:
- mongo:/var/mydata
environment:
MONGO_INITDB_ROOT_USERNAME: xxx
MONGO_INITDB_ROOT_PASSWORD: xxx
ports:
- "27017:27107"
networks:
- app-network

volumes:
mongo:
driver: azure_file
driver_opts:
share_name: mongo
storage_account_name: xxx
storage_account_key: xxx

networks:
app-network:

没什么特别的。然后,我创建了一个自定义 Mongo 图像,如下所示:

FROM mongo
EXPOSE 27017

ENTRYPOINT ["mongod", "--dbpath=/var/mydata", "--bind_ip_all"]

这一切似乎都被接受了。我在其他地方读到,安装到/data/db 是一个坏主意,因为它会导致问题 - 所以我坚持这些准则。

Azure 文件共享似乎配置正确。但是,当我启动容器时,我在 Mongo 启动期间收到重复的错误消息,指出它无法打开 WiredTiger.wt - 并尝试重复创建新的错误消息。我可以从一个完全空的文件共享开始 - 它仍然这样做。文件正在由 Mongo 在共享中创建。

我束手无策,因为我尝试了很多建议(太多了,无法在此提及),但我根本无法弄清楚这一点。

我可能会错过的任何东西都会受到极大的欢迎。文件权限似乎没问题,因为我可以触摸和/或从共享中删除文件,没有问题 - 这似乎只是 Mongo 的问题。

非常感谢。

更新

这是容器运行时的一些输出 - 您可以看到它使用 WiredTiger 文件尝试了几次:

2023-02-26T20:41:30.809321991Z {"t":{"$date":"2023-02-26T20:41:30.809+00:00"},"s":"I",  "c":"WT",       "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1677444090,"ts_usec":809021,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_BLOCK","category_id":3,"verbose_level":"NOTICE","verbose_level_id":-1,"msg":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.7"}}}
2023-02-26T20:41:30.840231616Z {"t":{"$date":"2023-02-26T20:41:30.839+00:00"},"s":"E", "c":"WT", "id":22435, "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":1,"message":{"ts_sec":1677444090,"ts_usec":839910,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_DEFAULT","category_id":9,"verbose_level":"ERROR","verbose_level_id":-3,"msg":"__posix_open_file:805:/var/mydata/WiredTiger.wt: handle-open: open","error_str":"Operation not permitted","error_code":1}}}
2023-02-26T20:41:31.002537945Z {"t":{"$date":"2023-02-26T20:41:31.002+00:00"},"s":"E", "c":"WT", "id":22435, "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":17,"message":{"ts_sec":1677444091,"ts_usec":2211,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_DEFAULT","category_id":9,"verbose_level":"ERROR","verbose_level_id":-3,"msg":"__posix_open_file:805:/var/mydata/WiredTiger.wt: handle-open: open","error_str":"File exists","error_code":17}}}
2023-02-26T20:41:31.050284867Z {"t":{"$date":"2023-02-26T20:41:31.050+00:00"},"s":"I", "c":"WT", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":{"ts_sec":1677444091,"ts_usec":50047,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_BLOCK","category_id":3,"verbose_level":"NOTICE","verbose_level_id":-1,"msg":"unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.8"}}}
2023-02-26T20:41:31.080410844Z {"t":{"$date":"2023-02-26T20:41:31.080+00:00"},"s":"E", "c":"WT", "id":22435, "ctx":"initandlisten","msg":"WiredTiger error message","attr":{"error":1,"message":{"ts_sec":1677444091,"ts_usec":80113,"thread":"14:0x7dfcbbc19cc0","session_name":"connection","category":"WT_VERB_DEFAULT","category_id":9,"verbose_level":"ERROR","verbose_level_id":-3,"msg":"__posix_open_file:805:/var/mydata/WiredTiger.wt: handle-open: open","error_str":"Operation not permitted","error_code":1}}}
2023-02-26T20:41:31.097099487Z {"t":{"$date":"2023-02-26T20:41:31.096+00:00"},"s":"W", "c":"STORAGE", "id":22347, "ctx":"initandlisten","msg":"Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade."}
2023-02-26T20:41:31.097778289Z {"t":{"$date":"2023-02-26T20:41:31.097+00:00"},"s":"F", "c":"STORAGE", "id":28595, "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"1: Operation not permitted"}}
2023-02-26T20:41:31.098377890Z {"t":{"$date":"2023-02-26T20:41:31.097+00:00"},"s":"F", "c":"ASSERT", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28595,"file":"src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp","line":708}}

这几乎就像存在某种权限问题?显然我使用了正确的文件共享 key 等,否则我的测试命令将无法工作。我已经尝试过 chown/chgrp 来 root 以防万一 - 没有区别(不是我认为的) - 使用以下内容:

CMD [ "sh", "-c", "ls -l /var; touch /var/mydata/test.txt; rm /var/mydata/test.txt; chmod -R 777 /var/mydata; chown -R root /var/mydata; chgrp root /var/mydata; mongod --dbpath=/var/mydata --bind_ip_all" ]

重申一下 - Azure 文件共享是否为空并不重要 - 它始终会重试 WiredTiger 文件大约 8 次左右,直到容器放弃并终止。

更新#2

我还尝试创建自定义镜像,复制包含数据库路径等的 Mongo 配置文件,而不是使用 docker-compose 的命令行参数或环境变量 - 仍然不高兴。

最佳答案

在尝试使用 Azure 存储帐户设置持久存储时,我遇到了与您相同的问题,并最终找到了解决方案。

Azure 文件共享似乎与 MongoDB 的底层存储驱动程序 WiredTiger 不兼容。我不知 Prop 体原因,但我也无法通过更改权限、创建自定义镜像等方式解决。

解决方案是使用 Azure Cosmos DB for MongoDB。 Cosmos 中的 MongoDB API 允许您利用现有的 Mongo 库,因此您应该能够通过最少的代码更改来使用它。我所要做的就是将我的 mongo 连接字符串替换为 Cosmos 提供的连接字符串。

以下是帮助您入门的文档:https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/introduction

希望这对您有所帮助,祝您好运!

关于Azure 应用服务中的 MongoDB,通过 Docker-Compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75573836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com