-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
add-shards-to-shard-cluster.txt
83 lines (58 loc) · 2.56 KB
/
add-shards-to-shard-cluster.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
.. _sharding-procedure-add-shard:
=======================
Add Shards to a Cluster
=======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
You add shards to a :term:`sharded cluster` after you create the cluster
or any time that you need to add capacity to the cluster. If you have not
created a sharded cluster, see :ref:`sharding-procedure-setup`.
In production environments, all shards should be :term:`replica sets
<replica set>`.
Considerations
--------------
Balancing
~~~~~~~~~
.. include:: /includes/fact-adding-shards-changes-cluster-balance.rst
Capacity Planning
~~~~~~~~~~~~~~~~~
When adding a shard to a cluster, always ensure that the cluster has
enough capacity to support the migration required for balancing the
cluster without affecting legitimate production traffic.
Add a Shard to a Cluster
------------------------
You interact with a sharded cluster by connecting to a :binary:`~bin.mongos`
instance.
1. From a :binary:`~bin.mongo` shell, connect to the :binary:`~bin.mongos`
instance. For example, if a :binary:`~bin.mongos` is accessible at
``mongos0.example.net`` on port ``27017``, issue the following
command:
.. code-block:: sh
mongo --host mongos0.example.net --port 27017
#. Add a shard to the cluster using the :method:`sh.addShard()`
method, as shown in the examples below. Issue :method:`sh.addShard()`
separately for each shard. If the shard is a replica set, specify the
name of the replica set and specify a member of the set. In
production deployments, all shards should be replica sets.
.. optional:: You can instead use the :dbcommand:`addShard` database
command, which lets you specify a name and maximum size for the
shard. If you do not specify these, MongoDB automatically assigns
a name and maximum size. To use the database command, see
:dbcommand:`addShard`.
The following are examples of adding a shard with
:method:`sh.addShard()`:
- To add a shard for a replica set named ``rs1`` with a member
running on port ``27018`` on ``mongodb0.example.net``, issue the
following command:
.. code-block:: javascript
sh.addShard( "rs1/mongodb0.example.net:27018" )
- To add a shard for a standalone :binary:`~bin.mongod` on port ``27018``
of ``mongodb0.example.net``, issue the following command:
.. code-block:: javascript
sh.addShard( "mongodb0.example.net:27018" )
.. note:: It might take some time for :term:`chunks <chunk>` to
migrate to the new shard.