sh.addShard()

On this page本页内容

Definition定义

sh.addShard(<url>)

Adds a shard replica set to a sharded cluster. 将分片副本集添加到分片群集This method must be run on a mongos instance.此方法必须在mongos实例上运行。

The sh.addShard() method has the following parameter:sh.addShard()方法具有以下参数:

Parameter参数Type类型Description描述
hoststring

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>, ...

The sh.addShard() method has the following prototype form:sh.addShard()方法具有以下原型形式:

sh.addShard("<replica_set>/<hostname><:port>")
Warning警告

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

mongos installed from official .deb and .rpm packages have the bind_ip configuration set to 127.0.0.1 by default.从正式.deb.rpm包安装的bind_ip配置默认设置为127.0.0.1

mongos uses "majority" for the addShard command and its helper sh.addShard().addShard命令及其助手sh.addShard()使用"majority"

The sh.addShard() method is a helper for the addShard command. sh.addShard()方法是addShard命令的助手。The addShard command has additional options which are not available with this helper.addShard命令具有此助手无法使用的其他选项。

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 sh.addShard().不能在提供给sh.addShard()的种子列表中包含隐藏成员

Example示例

To add a shard, specify the name of the replica set and the hostname of at least one member of the replica set, as a seed. 要添加分片,请将副本集的名称和副本集至少一个成员的主机名指定为种子。If you specify additional hostnames, all must be members of the same replica set.如果指定其他主机名,则所有主机名都必须是同一复制集的成员。

The following example adds a replica set named repl0 and specifies one member of the replica set:以下示例添加名为repl0的副本集,并指定副本集的一个成员:

sh.addShard("repl0/mongodb3.example.net:27327")
←  sh.abortReshardCollection()sh.addShardTag() →