@@ -9,11 +9,11 @@ Shard Cluster Administration
9
9
10
10
This document describes common administrative tasks.
11
11
For a full introduction to sharding in MongoDB see
12
- " :doc:`/core/sharding`," and for a complete overview of all sharding
13
- documentation in the MongoDB Manual, see " :doc:`/sharding`." The
14
- " :doc:`/administration/sharding-architectures`" document provides an
12
+ :doc:`/core/sharding`, and for a complete overview of all sharding
13
+ documentation in the MongoDB Manual, see :doc:`/sharding`. The
14
+ :doc:`/administration/sharding-architectures` document provides an
15
15
overview of deployment possibilities to help deploy a shard
16
- cluster. Finally, the " :doc:`/core/sharding-internals`" document
16
+ cluster. Finally, the :doc:`/core/sharding-internals` document
17
17
provides a more detailed introduction to sharding when troubleshooting
18
18
issues or understanding your cluster's behavior.
19
19
@@ -43,83 +43,63 @@ single server. For production, use the configurations described in
43
43
scratch, see the :doc:`/tutorial/deploy-shard-cluster` tutorial for
44
44
more detail or use the following procedure as a quick starting point:
45
45
46
- 1. Set up the required config servers, shards, and :program:`mongos`
47
- instances described in :ref:`Sharding Infrastructure
48
- <sharding-requirements-infrastructure>`.
46
+ 1. Create data directories for each of the three (3) config server instances.
49
47
50
-
51
- #. Start the three (3) config servers.
52
-
53
- #. On all three config server instances, issue the following
54
- command to start the :program:`mongod` process:
48
+ #. Start the three config server instances. For example, to start a
49
+ config server instance running on TCP port ``27018`` with the data
50
+ stored in ``/data/configdb``, type the following:
55
51
56
52
.. code-block:: sh
57
53
58
- mongod --configsvr
54
+ mongod --configsvr --dbpath /data/configdb --port 27018
59
55
60
- This starts a :program:`mongod` instance running on TCP port
61
- ``27018``, with the data stored in the ``/data/configdb`` path. All other
62
- :doc:`command line </reference/mongod>` and :doc:`configuration
63
- file </reference/configuration-options>` options are available for config
64
- server instances.
56
+ For additional command options, see :doc:`/reference/mongod`
57
+ and :doc:`/reference/configuration-options`.
65
58
66
59
.. include:: /includes/note-config-server-startup.rst
67
60
68
- #. Start a :program:`mongos` instance issuing the following command:
69
-
70
- .. code-block:: sh
61
+ #. Start the three :program:`mongos` instances. For example, to start a
62
+ :program:`mongos` instance running on the following hosts:
71
63
72
- mongos --configdb config0.mongodb.example.net,config1.mongodb.example.net,config2.mongodb.example.net --port 27017
64
+ - ``mongos0.example.net``
65
+ - ``mongos1.example.net``
66
+ - ``mongos2.example.net``
73
67
74
- #. Connect to the :program:`mongos` instance using the :program:`mongo`
75
- shell.
68
+ You would issue the following command:
76
69
77
70
.. code-block:: sh
78
71
79
- mongo mongos.mongodb.example.net
80
-
81
- #. Add shards to the cluster.
72
+ mongos --configdb mongos0.example.net,mongos1.example.net,mongos2.example.net
82
73
83
- Run the following commands while connected to a :program:`mongos` to
84
- initialize the cluster.
74
+ #. Connect to one of the :program:`mongos` instances. For example, if
75
+ a :program:`mongos` is accessible at ``mongos0.example.net`` on
76
+ port ``27017``, issue the following command:
85
77
86
- First, you need to tell the cluster where to find the individual
87
- shards. You can do this using the :dbcommand:`addShard` command.
78
+ .. code-block:: sh
88
79
89
- .. code-block:: javascript
80
+ mongo mongos0.example.net
90
81
91
- sh.addShard( "[hostname]:[port]" )
82
+ #. Add shards to the cluster. From the :program:`mongo` shell connected
83
+ to the :program:`mongos` instance, call the :method:`sh.addShard()`
84
+ method for each shard to add to the cluster.
92
85
93
86
For example:
94
87
95
88
.. code-block:: javascript
96
89
97
90
sh.addShard( "mongodb0.example.net:27027" )
98
91
99
- MongoDB will discover all other members of the replica set, if
100
- ``mongodb0.example.net:27027`` is a member of a replica set.
92
+ If ``mongodb0.example.net:27027`` is a member of a replica
93
+ set, MongoDB will discover all other members of the replica set.
101
94
102
95
.. note:: In production deployments, all shards should be replica sets.
103
96
104
97
Repeat this step for each new shard in your cluster.
105
98
106
99
.. optional::
107
100
108
- You may specify a "name" as an argument to the
109
- :dbcommand:`addShard`, as follows:
110
-
111
- .. code-block:: javascript
112
-
113
- db.runCommand( { addShard: mongodb0.example.net, name: "mongodb0" } )
114
-
115
- Or:
116
-
117
- .. code-block:: javascript
118
-
119
- sh.addShard( mongodb0.example.net, name: "mongodb0" )
120
-
121
- If you do not specify a shard name, then MongoDB will assign a
122
- name upon creation.
101
+ You can specify a name for the shard and a maximum size. See
102
+ :dbcommand:`addShard`.
123
103
124
104
.. note::
125
105
@@ -139,25 +119,26 @@ single server. For production, use the configurations described in
139
119
140
120
sh.addShard( "repl0/mongodb0.example.net:27027,mongodb1.example.net:27017,mongodb2.example.net:27017" )
141
121
142
- #. Enable sharding for any database that you want to shard.
122
+ #. Enable sharding for each database you want to shard.
123
+ While sharding operates on a per-collection basis, you must enable
124
+ sharding for each database that holds collections you want to shard.
125
+ This step is a meta-data change and will not redistribute your data.
143
126
144
- MongoDB enables sharding on a per-database basis. This is only a
145
- meta-data change and will not redistribute your data. To enable
146
- sharding for a given database, use the :dbcommand:`enableSharding`
147
- command or the :method:`sh.enableSharding()` shell function.
127
+ To enable sharding for a given database, use the
128
+ :dbcommand:`enableSharding` command or the
129
+ :method:`sh.enableSharding()` shell function, as shown below. Replace
130
+ ``<database>`` with the name of the database on which to enable
131
+ sharding.
148
132
149
133
.. code-block:: javascript
150
134
151
- db.runCommand( { enableSharding: [ database] } )
135
+ db.runCommand( { enableSharding: < database> } )
152
136
153
137
Or:
154
138
155
139
.. code-block:: javascript
156
140
157
- sh.enableSharding([database])
158
-
159
- Replace ``[database]`` with the name of the database you wish to
160
- enable sharding on.
141
+ sh.enableSharding(<database>)
161
142
162
143
.. note::
163
144
@@ -169,21 +150,21 @@ single server. For production, use the configurations described in
169
150
170
151
#. Enable sharding on a per-collection basis.
171
152
172
- Finally, you must explicitly specify collections to shard. The
153
+ Finally, you must explicitly specify collections to shard. The
173
154
collections must belong to a database for which you have enabled
174
155
sharding. When you shard a collection, you also choose the shard
175
156
key. To shard a collection, run the :dbcommand:`shardCollection`
176
157
command or the :method:`sh.shardCollection()` shell helper.
177
158
178
159
.. code-block:: javascript
179
160
180
- db.runCommand( { shardCollection: "[ database].[ collection] ", key: "[ shard-key] " } )
161
+ db.runCommand( { shardCollection: "< database>.< collection> ", key: "< shard-key> " } )
181
162
182
163
Or:
183
164
184
165
.. code-block:: javascript
185
166
186
- sh.shardCollection("[ database].[ collection] ", "key")
167
+ sh.shardCollection("< database>.< collection> ", "key")
187
168
188
169
For example:
189
170
@@ -218,6 +199,17 @@ This section describes common maintenance procedure, including: how to
218
199
add and remove nodes, how to manually split chunks, and how to disable
219
200
the balancer for backups.
220
201
202
+ List the Set of Configured Shards
203
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204
+
205
+ To list the current set of configured shards and verify that all shards
206
+ have been committed to the system, run the :dbcommand:`listShards`
207
+ command:
208
+
209
+ .. code-block:: javascript
210
+
211
+ db.runCommand( { listshards : 1 } )
212
+
221
213
.. _sharding-procedure-add-shard:
222
214
223
215
Adding a Shard to a Cluster
@@ -235,9 +227,9 @@ procedure:
235
227
236
228
.. code-block:: javascript
237
229
238
- sh.addShard( "[ hostname]:[ port] " )
230
+ sh.addShard( "< hostname>:< port> " )
239
231
240
- Replace ``[ hostname] `` and ``[ port] `` with the hostname and TCP
232
+ Replace ``< hostname> `` and ``< port> `` with the hostname and TCP
241
233
port number of where the shard is accessible.
242
234
243
235
For example:
0 commit comments