mongodb - FailedToSatisfyReadPreference:找不到匹配读取首选项的主机{模式:“primary”}
问题描述
我想为我的项目使用 mongodb-shard。我创建了一个 helm chart https://github.com/b-rohit/mongodb-shard-chart来部署到 kubernetes 集群。
我使用kind
本地运行的集群来测试它。配置和分片服务器运行正常。我能够在他们的 mongo shell 中执行命令。mongos 服务器无法连接到配置服务器中的副本集。我在 mongos 中收到以下错误消息
2020-04-17T13:33:31.579+0000 W SHARDING [replSetDistLockPinger] pinging failed for distributed lock pinger :: caused by :: FailedToSatisfyReadPreference: Could not find host matching read preference { mode: "primary" } for set mongors1conf
2020-04-17T13:33:31.579+0000 W SHARDING [mongosMain] Error initializing sharding state, sleeping for 2 seconds and trying again :: caused by :: FailedToSatisfyReadPreference: Error loading clusterID :: caused by :: Could not find host matching read preference { mode: "nearest" } for set mongors1conf
2020-04-17T13:33:31.579+0000 I SHARDING [shard-registry-reload] Periodic reload of shard registry failed :: caused by :: FailedToSatisfyReadPreference: could not get updated shard list from config server :: caused by :: Could not find host matching read preference { mode: "nearest" } for set mongors1conf; will retry after 30s
在配置服务器日志如下
2020-04-17T13:33:11.578+0000 I NETWORK [listener] connection accepted from 10.244.0.6:34400 #5 (1 connection now open)
2020-04-17T13:33:11.578+0000 I NETWORK [conn5] received client metadata from 10.244.0.6:34400 conn5: { driver: { name: "NetworkInterfaceTL", version: "4.2.5" }, os: { type: "Linux", name: "Ubuntu", architecture: "x86_64", version: "18.04" } }
2020-04-17T13:33:11.589+0000 I ACCESS [conn5] Successfully authenticated as principal __system on local from client 10.244.0.6:34400
2020-04-17T13:33:38.197+0000 I SHARDING [replSetDistLockPinger] Marking collection config.lockpings as collection version: <unsharded>
2020-04-17T13:33:38.202+0000 W SHARDING [replSetDistLockPinger] pinging failed for distributed lock pinger :: caused by :: LockStateChangeFailed: findAndModify query predicate didn't match any lock document
2020-04-17T13:44:39.743+0000 I CONTROL [LogicalSessionCacheRefresh] Failed to create config.system.sessions: Cannot create config.system.sessions until there are shards, will try again at the next refresh interval
2020-04-17T13:44:39.743+0000 I CONTROL [LogicalSessionCacheRefresh] Sessions collection is not set up; waiting until next sessions refresh interval: Cannot create config.system.sessions until there are shards
2020-04-17T13:44:39.743+0000 I SH_REFR [ConfigServerCatalogCacheLoader-1] Refresh for collection config.system.sessions took 0 ms and found the collection is not sharded
2020-04-17T13:44:39.743+0000 I CONTROL [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: Collection config.system.sessions is not sharded.
2020-04-17T13:44:42.570+0000 I NETWORK [conn5] end connection 10.244.0.10:37922 (0 connections now open)
我是 mongodb 的新手。整理这张图表花了很多时间。我也检查了其他类似的问题。在 mongodb 中找不到匹配读取首选项的主机
我无法进一步调试它。
解决方案
您的配置服务器副本集是:
- 未运行(并非所有节点都已启动)
- 不是副本集(replSetInitiate 未执行或失败)
- 从分片节点不正确地引用(错误的主机、ip 或错误的副本集名称)
- 已启动并正在运行,但由于防火墙规则,您的分片不允许访问它
mongo
确保您可以从运行分片的机器上的 shell访问副本集节点mongod
。
推荐阅读
- image - 在 SwiftUI 中使用 PencilKit 将绘图转换为图像
- sas - 比较 SAS 中不同版本的 PDF 文档
- java - 使用 @Query 调用存储过程会导致异常:调用 ProcedureName 时参数的数量或类型错误
- return - 中断 LPC 微控制器上的寄存器写操作
- javascript - 跨浏览器 3D 动画
- load-balancing - 两个基于 4G 加密狗的 ISP 需要负载平衡路由器
- sql - 如何根据字母顺序仅保留 1 个结果以与 SQL 查询保持一致?
- php - 将照片上传到数据库(到服务器而不是本地主机)
- javascript - 根据字符串在对象数组中查找嵌套对象
- python - 模块化更大的 tkinter 程序