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将分片复制集添加到分片集群中。此方法必须在mongosinstance.mongos实例上运行。Importantmongosh Method
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
addShardcommand.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:Thesh.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>, ...
Thesh.addShard()method has the following prototype form:sh.addShard()方法具有以下原型形式:sh.addShard("<replica_set>/<hostname><:port>")
WarningDo not use除非您的配置服务器也在localhostfor the hostname unless your config server is also running onlocalhost.localhost上运行,否则不要使用localhost作为主机名。默认情况下,从官方mongosinstalled from official .deb and .rpm packages have thebind_ipconfiguration set to127.0.0.1by default..deb和.rpm包安装的mongos的bind_ip配置设置为127.0.0.1。mongosuses对"majority"for theaddShardcommand and its helpersh.addShard().addShard命令及其助手sh.addShard()使用"majority"。
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 Balancer Internals for more information.平衡器将开始迁移块,以便集群实现平衡。有关更多信息,请参阅平衡器内部。
Hidden Members隐藏的成员
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")