addShard

On this page本页内容

Definition定义

addShard

Adds a shard replica set to a sharded cluster.将分片副本集添加到分片集群

Run addShard when connected to a mongos instance. 连接到mongos实例时运行addShardThe 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:该命令包含以下字段:

Field字段Type类型Description描述
addShardstring

The replica set name, hostname, and port of at least one member of the shard's replica set. 分片副本集的至少一个成员的副本集名称、主机名和端口。Any additional replica set member hostnames must be comma separated. 任何其他副本集成员主机名必须以逗号分隔。For example:例如:

<replica_set>/<hostname><:port>,<hostname><:port>, ...
maxSizeintegerOptional. 可选。The maximum size in megabytes of the shard. 分片的最大大小(MB)。If you set maxSize to 0, MongoDB does not limit the size of the shard.如果将maxSize设置为0,MongoDB不会限制分片的大小。
namestringOptional. 可选。A name for the shard. 分片的名称。If this is not specified, MongoDB automatically provides a unique name.如果未指定,MongoDB将自动提供唯一的名称。

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. 当您的机器具有不同的磁盘容量时,或者如果您想限制某些分片上的数据量,请指定maxSizeThe 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约束阻止平衡器将块迁移到分片。

Considerations注意事项

Balancing平衡

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目录

Hidden Members

Important重要

You cannot include a hidden member in the seed list provided to addShard.不能在提供给addShard的种子列表中包含隐藏成员

Examples示例

The following command adds a replica set as a shard:以下命令将副本集添加为分片:

use admin
db.runCommand( { addShard: "repl0/mongodb3.example.net:27327"} )
Warning警告

Do not use localhost for the hostname unless your config server is also running on localhost.除非您的配置服务器也在localhost上运行,否则不要使用localhost作为主机名。

←  abortReshardCollectionaddShardToZone →