失败到满足读取首选项:找不到主机匹配的读取首选项 { 模式: "primary" }



我想在我的项目中使用mongodb shard。我创建了一个舵图https://github.com/b-rohit/mongodb-shard-chart部署到kubernetes集群。

我使用本地运行的kind集群来测试它。config和shard服务器运行正常。我能够在他们的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未执行或失败(
  • 从shard节点错误引用(错误的主机、ip或错误的副本集名称(
  • 已启动并运行,但由于防火墙规则,您的碎片不允许访问它

确保您可以从运行碎片mongod的机器的mongoshell访问副本集节点。

最新更新