mongo mongoS 容器内的连接错误
mongo connection error inside mongoS container
我正在尝试在 Kubernetes 中编排一个 MongoDB 集群,使用 StatefulSets 和 Headless Services。我已经有一段时间试图找出其中的问题,但找不到任何我可以使用的东西。
在进行研究时,我发现 this repository which I cloned and adapted to the use case. You can find one of the manifests (the one for the mongoS instance) right here。
然后我 运行 generate.sh
脚本在存储库中发布,但与 gcloud
或 persistentVolume
相关的所有内容都已注释,只留下 statefulSet
/Service
产卵进程。一切似乎都运行良好,但每当脚本到达块
# Wait for the mongos to have started properly
echo "Waiting for the first mongos to come up (`date`)..."
echo " (IGNORE any reported not found & connection errors)"
echo -n " "
until kubectl --v=0 exec mongos-router-0 -c mongos-container -- mongo --quiet --eval 'db.getMongo()'; do
sleep 2
echo -n " "
done
echo "...first mongos is now running (`date`)"
echo
它只是漫不经心地给出这个错误信息:
2019-03-11T14:02:03.531+0000 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:343:13
@(connect):1:21
exception: connect failed
command terminated with exit code 1
因此我尝试直接从 pod 内部 运行 mongo
,但发生了同样的错误。然后我只是尝试 运行 mongo
在容器内使用不同的端口,运行ning mongo --port 27018
(也尝试了 27019 和 27020),只是为了看看它是哪种错误gives with non-exposed ports, 好像报同样的错误。
我怎么能 运行 mongo 在一个容器里 运行ning mongo 端口 27017?看来我必须 运行 mongod
在 运行 宁 mongo
shell 之前,即使 mongos
已经开始了。这真是令人难以置信,我觉得我错过了什么。我只在 mongos pods 中有这个错误,而 mongo-configdb 和 mongod-maindb 似乎 运行ning 顺利(和 运行在其中设置 mongo shell 不会出现任何错误。此外,在其中一个中执行 rs.status()
时效果很好)。
您可以找到一些 mongos
日志 there。
TL;DR
我怎么能 运行 mongo 在一个容器里 运行ning mongos 在端口 27017 上?
N.B.: 我正在使用来自官方 dockerhub 存储库的图像 mongo:3.6 .
我不太明白为什么,但是将 运行 端口从 27017 更改为 27020 效果很好。如果有人路过并可以解释如何,我很高兴听到 his/her 解释为 netstat -tunelp
(以及 ps aux
),而我的两个 k8s 节点上的 grepping 端口 27017 没有提供与端口 27017 相关的任何输出...
我正在尝试在 Kubernetes 中编排一个 MongoDB 集群,使用 StatefulSets 和 Headless Services。我已经有一段时间试图找出其中的问题,但找不到任何我可以使用的东西。
在进行研究时,我发现 this repository which I cloned and adapted to the use case. You can find one of the manifests (the one for the mongoS instance) right here。
然后我 运行 generate.sh
脚本在存储库中发布,但与 gcloud
或 persistentVolume
相关的所有内容都已注释,只留下 statefulSet
/Service
产卵进程。一切似乎都运行良好,但每当脚本到达块
# Wait for the mongos to have started properly
echo "Waiting for the first mongos to come up (`date`)..."
echo " (IGNORE any reported not found & connection errors)"
echo -n " "
until kubectl --v=0 exec mongos-router-0 -c mongos-container -- mongo --quiet --eval 'db.getMongo()'; do
sleep 2
echo -n " "
done
echo "...first mongos is now running (`date`)"
echo
它只是漫不经心地给出这个错误信息:
2019-03-11T14:02:03.531+0000 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:343:13
@(connect):1:21
exception: connect failed
command terminated with exit code 1
因此我尝试直接从 pod 内部 运行 mongo
,但发生了同样的错误。然后我只是尝试 运行 mongo
在容器内使用不同的端口,运行ning mongo --port 27018
(也尝试了 27019 和 27020),只是为了看看它是哪种错误gives with non-exposed ports, 好像报同样的错误。
我怎么能 运行 mongo 在一个容器里 运行ning mongo 端口 27017?看来我必须 运行 mongod
在 运行 宁 mongo
shell 之前,即使 mongos
已经开始了。这真是令人难以置信,我觉得我错过了什么。我只在 mongos pods 中有这个错误,而 mongo-configdb 和 mongod-maindb 似乎 运行ning 顺利(和 运行在其中设置 mongo shell 不会出现任何错误。此外,在其中一个中执行 rs.status()
时效果很好)。
您可以找到一些 mongos
日志 there。
TL;DR 我怎么能 运行 mongo 在一个容器里 运行ning mongos 在端口 27017 上?
N.B.: 我正在使用来自官方 dockerhub 存储库的图像 mongo:3.6 .
我不太明白为什么,但是将 运行 端口从 27017 更改为 27020 效果很好。如果有人路过并可以解释如何,我很高兴听到 his/her 解释为 netstat -tunelp
(以及 ps aux
),而我的两个 k8s 节点上的 grepping 端口 27017 没有提供与端口 27017 相关的任何输出...