On this page本页内容
addShard
Adds a shard replica set to a sharded cluster.将分片副本集添加到分片集群。
Run 连接到addShard when connected to a mongos instance. mongos实例时运行addShard。The command takes the following form to add a shard replica set:该命令采用以下形式添加分片副本集:
{ addShard: "<replica_set>/<hostname><:port>", maxSize: <size>, name: "<shard_name>" }
The command contains the following fields:该命令包含以下字段:
addShard | string |
<replica_set>/<hostname><:port>,<hostname><:port>, ... |
maxSize | integer | maxSize to 0, MongoDB does not limit the size of the shard.maxSize设置为0,MongoDB不会限制分片的大小。
|
name | string |
The addShard command stores shard configuration information in the config database. addShard命令将分片配置信息存储在config数据库中。Always run 使用addShard when using the admin database.admin数据库时始终运行addShard。
Specify a 当您的机器具有不同的磁盘容量时,或者如果您想限制某些分片上的数据量,请指定maxSize when you have machines with different disk capacities, or if you want to limit the amount of data on some shards. maxSize。The 当在分片上运行maxSize constraint prevents the balancer from migrating chunks to the shard when the totalSize returned from running listDatabases on the shard exceeds the value of maxSize.listDatabases返回的totalSize超过maxSize的值时,maxSize约束阻止平衡器将块迁移到分片。
When you add a shard to a sharded cluster, you affect the balance of chunks among the shards of a cluster for all existing sharded collections. 将分片添加到分片集群时,会影响集群中所有现有分片集合的分片之间的块平衡。The balancer will begin migrating chunks so that the cluster will achieve balance. 平衡器将开始迁移块,以便集群实现平衡。See Cluster Balancer for more information.有关详细信息,请参阅群集平衡器。
Chunk migrations can have an impact on disk space, as the source shard automatically archives the migrated documents by default. 分块迁移会对磁盘空间产生影响,因为默认情况下源分片会自动归档迁移的文档。For details, see 有关详细信息,请参阅moveChunk directory.moveChunk目录。
You cannot include a hidden member in the seed list provided to 不能在提供给addShard.addShard的种子列表中包含隐藏成员。
The following command adds a replica set as a shard:以下命令将副本集添加为分片:
use admin
db.runCommand( { addShard: "repl0/mongodb3.example.net:27327"} )
Do not use 除非您的配置服务器也在localhost for the hostname unless your config server is also running on localhost.localhost上运行,否则不要使用localhost作为主机名。