【问题标题】:Unable to insert document into shard collections无法将文档插入分片集合
【发布时间】:2018-06-19 15:20:14
【问题描述】:

我收到错误“如果不以 --shardsvr 开头,则无法接受分片命令” 在将文档插入任何分片集合时。

我的设置是这样的

rs0: mongon1, mongon2, mongon3

rs1: mongon4, mongon5, mongon6 在端口 27017

配置:mongoconf1、mongoconf2、mongoconf3都在27019端口

mongom 上的 Mongos:27017 在 mongos 服务器上使用以下命令成功启动 mongos

mongos --configdb configReplSet/mongoconfs1:27019,mongoconfs2:27019,mongoconfs3:27019

以下是我的分片状态

--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5b21a5847e4ba64674ee085e")
  }
  shards:
    {  "_id" : "rs0",  "host" : "rs0/mongon1:27017,mongon2:27017,mongon3:27017",  "state" : 1 }
    {  "_id" : "rs1",  "host" : "rs1/mongodbn5:27017,mongon4:27017,mongon6:27017",  "state" : 1 }
  active mongoses:
    "3.6.5" : 1
  autosplit:
    Currently enabled: yes
  balancer:
    Currently enabled:  yes
    Currently running:  no
    Failed balancer rounds in last 5 attempts:  5
    Last reported error:  Could not find host matching read preference { mode: "primary" } for set rs0
    Time of Reported error:  Thu Jun 14 2018 00:44:12 GMT+0000 (UTC)
    Migration Results for the last 24 hours: 
            No recent migrations
  databases:
    {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
            config.system.sessions
                    shard key: { "_id" : 1 }
                    unique: false
                    balancing: true
                    chunks:
                            rs1     1
                    { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : rs1 Timestamp(1, 0) 
    {  "_id" : "experimentine",  "primary" : "rs1",  "partitioned" : true }
    {  "_id" : "experimentone",  "primary" : "rs1",  "partitioned" : true }
            experimentone.run1
                    shard key: { "id" : 1 }
                    unique: false
                    balancing: true
                    chunks:
                            rs1     1
                    { "id" : { "$minKey" : 1 } } -->> { "id" : { "$maxKey" : 1 } } on : rs1 Timestamp(1, 0) 
    {  "_id" : "masterdb",  "primary" : "rs0",  "partitioned" : true }
            masterdb.mastercollection
                    shard key: { "id" : 1 }
                    unique: false
                    balancing: true
                    chunks:
                            rs0     1
                    { "id" : { "$minKey" : 1 } } -->> { "id" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 0) 
    {  "_id" : "test",  "primary" : "rs0",  "partitioned" : false }
    {  "_id" : "testdb",  "primary" : "rs0",  "partitioned" : true }
            testdb.demo
                    shard key: { "name" : 1 }
                    unique: false
                    balancing: true
                    chunks:
                            rs0     1
                    { "name" : { "$minKey" : 1 } } -->> { "name" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 0) 

请帮我找出哪里出错了。

【问题讨论】:

    标签: mongodb sharding mongo-shell


    【解决方案1】:

    我发现了插入问题。我使用的是 mongodb.conf 文件,在这些配置文件中我必须提到分片:节点的详细信息是分片集群的一部分。我错过了在属于分片集的所有 mongod 服务器的 mongod.conf 文件中输入分片详细信息。

    我所有的 mongod 节点都应该在 mongod.conf 文件的 ** sharding** 部分中包含以下内容。

    #sharding:
    sharding:
      clusterRole: shardsvr
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-22
      • 1970-01-01
      • 2021-03-28
      • 2016-08-22
      • 2015-07-03
      • 2016-09-22
      相关资源
      最近更新 更多