MongoDB Could not find host matching read preference { mode: \"primary\" } for set repl_shard1

本文记录了解决在MongoDB4.0分片集群中添加分片时出现的“Couldnotfindhostmatchingreadpreference”错误的过程。作者经过多次尝试,最终发现统一所有节点的keyfile保持一致是解决问题的关键。

最近在测试 MongoDB 4.0 分片集群 ,搭建好所有节点后,往mongos添加分片的时候,一直报错 Could not find host matching read preference { mode: \"primary\" } for set ,如下

mongos> sh.addShard( "repl_shard2/10.204.11.124:29017");
{
        "ok" : 0,
        "errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set repl_shard1",
        "code" : 133,
        "codeName" : "FailedToSatisfyReadPreference",
        "operationTime" : Timestamp(1542786188, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1542786188, 1),
                "signature" : {
                        "hash" : BinData(0,"Lmc4YJaTUKcado6xM7nDQtvQ2G8="),
                        "keyId" : NumberLong("6626207086785069082")
                }
        }
}

各种Google,大部分遇到这个问题的是执行的副本集名称和实际不符,或者ip写错了,也有说是4.0认证更新的问题,基本能试的方案都试过了,无解,感觉就在答案边缘,但一直解不开。版本降到3.6也不行。困扰好几天了这个问题。把 read preference 相关的文档翻了个遍也没找到什么可疑点。今天经灵机一动,难道是keyfiel的问题?统一了一遍所有节点keyile,保持一致。奇迹发生了。

mongos> sh.addShard( "repl_shard1/10.204.11.124:29017");
{
        "shardAdded" : "repl_shard1",
        "ok" : 1,
        "operationTime" : Timestamp(1542785896, 10),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1542785896, 10),
                "signature" : {
                        "hash" : BinData(0,"2uSDXB6O0lmeKabvUIe4wcIYKdg="),
                        "keyId" : NumberLong("6626207086785069082")
                }
        }
}

添加成功。这个问题居然网上一个案例没有。mongod这个报错信息我也是醉了。

转载于:https://my.oschina.net/xxj123go/blog/2885721

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值