我正在尝试拆分我的收藏。当我执行命令时:
sh.enableSharding("testdb")
我得到:
{
"ok" : 1,
"operationTime" : Timestamp(1552083125, 2),
"$clusterTime" : {
"clusterTime" : Timestamp(1552083125, 2),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
现在,当我尝试使用以下命令对我的集合进行分片时:“sh.shardCollection("testdb.testcollection", {testkey:1})”
我收到错误:
{
"ok" : 0,
"errmsg" : "Cannot accept sharding commands if not started with --shardsvr",
"code" : 193,
"codeName" : "NoShardingEnabled",
"operationTime" : Timestamp(1552083136, 4),
"$clusterTime" : {
"clusterTime" : Timestamp(1552083136, 4),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
我检查了分片的状态,看起来它是成功的:
sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5c82df7b7a98360e9dd3c5da")
}
shards:
{ "_id" : "shard0000", "host" : "127.0.0.1:27023", "state" : 1 }
{ "_id" : "shard0001", "host" : "127.0.0.1:27024", "state" : 1 }
active mongoses:
"4.0.6" : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "config", "primary" : "config", "partitioned" : true }
{ "_id" : "testdb", "primary" : "shard0000", "partitioned" : true, "version" : { "uuid" : UUID("ed327ab3-1de9-4a0a-89f5-8d0bf81015fc"), "lastMod" : 1 } }
那么为什么当我尝试 shardCollection 时会出现该错误?我在 mongos 实例中运行所有这些
如果需要将副本集添加为分片集群中的分片,则在启动 mongod 进程时必须使用 --shardsvr 参数。
如果它是配置服务器,则 --configsvr 参数是必需的
参考以下链接进行部署
部署分片集群