@@ -7,26 +7,24 @@ Deploy a Shard Cluster
7
7
Synopsis
8
8
--------
9
9
10
- This document outlines the full procedure for deploying a
11
- :term:`shard cluster` in MongoDB. Use the
12
- ":doc:`/tutorial/convert-replica-set-to-replicated-shard-cluster`"
13
- procedure if you have an existing replica set. If you have a
14
- standalone :program:`mongod` instance you can use this tutorial to
15
- deploy a shard cluster.
10
+ This document describes how to deploy a :term:`shard cluster` for a
11
+ standalone :program:`mongod` instance.
12
+
13
+ To deploy a shard cluster for an existing replica set, see instead
14
+ :doc:`/tutorial/convert-replica-set-to-replicated-shard-cluster`.
16
15
17
16
Requirements
18
17
------------
19
18
20
- See the ":ref:`Requirements for Shard Clusters
21
- <sharding-requirements>`" section for more information about potential
22
- requirements for shard cluster.
19
+ Before deploying a shard cluster, see the requirements listed in
20
+ :ref:`Requirements for Shard Clusters <sharding-requirements>`.
23
21
24
22
.. warning:: Sharding and "localhost" Addresses
25
23
26
- If you use either "localhost" or " ``127.0.0.1``" as the hostname
27
- portion of any host identifier, either the ``host`` argument to
24
+ If you use either "localhost" or ``127.0.0.1`` as the hostname
25
+ portion of any host identifier, for example as the ``host`` argument to
28
26
:dbcommand:`addShard` or the value to the :option:`mongos --configdb`
29
- run time option, then you must use "localhost" or " ``127.0.0.1``"
27
+ run time option, then you must use "localhost" or ``127.0.0.1``
30
28
for *all* host settings. If you mix localhost addresses and remote
31
29
host address, MongoDB will produce errors.
32
30
@@ -40,105 +38,97 @@ Begin by configuring three config servers. These are very small
40
38
:program:`mongod` instances that provide cluster metadata. You must
41
39
have exactly *three* instances in production deployments. For
42
40
redundancy these instances should run on different systems and
43
- servers.
41
+ servers. It's important to separate config server :program:`mongod`
42
+ instances to provide redundancy and to ensure that cluster
43
+ metadata is secure and durable.
44
+
45
+ Because the config server :program:`mongod` instances receive relatively
46
+ little traffic and demand only a small portion of system resources, you
47
+ can run the instances on systems that run other services, such as on
48
+ shards or on servers that run :program:`mongos`.
44
49
45
- At a system prompt use the following command to start a config server :
50
+ To start a config server, type the following command at a system prompt :
46
51
47
52
.. code-block:: sh
48
53
49
54
mongod --configsvr
50
55
51
- The :option:`--configsrv` stores config database in the `configdb/`
52
- subdirectory of the :setting:`dbpath` directory, which is
53
- `` /data/db/`` by default. Additionally, a config server instance will
54
- be accessible via port ``27019``. You may use other :doc:`mongod
55
- runtime options </reference/configuration-options>` in addition to
56
- :setting:`configsvr` as needed.
56
+ The :option:`--configsrv` stores a config database in the `configdb/`
57
+ subdirectory of the :setting:`dbpath` directory. By default, the
58
+ :setting:`dbpath` directory is `` /data/db/``. The config server instance
59
+ is accessible via port ``27019``. In addition to :setting:`configsvr`,
60
+ use other :doc:`mongod runtime options </reference/configuration-options>`
61
+ as needed.
57
62
58
63
Repeat this process for all three config servers.
59
64
60
- .. note::
61
-
62
- It's important to separate config server :program:`mongod`
63
- instances to provide redundancy and ensure that the cluster
64
- metadata is secure and durable. Nevertheless, config
65
- :program:`mongod` instances themselves do not demand a large number
66
- of system resources and receive relatively little traffic. As a
67
- result you may choose to run config server instances on a system
68
- that also runs another service: on three of the shards, on a server
69
- that has a :program:`mongos`, or another component of your
70
- infrastructure.
71
-
72
65
Start ``mongos`` Instances
73
66
~~~~~~~~~~~~~~~~~~~~~~~~~~
74
67
75
- All operations against a shard cluster use a :program:`mongos`
76
- instance to route queries and operations to the appropriate shards,
77
- and to interact with the configdb instances. :program:`mongos`
78
- instances are lightweight and a shard cluster can have many
79
- :program:`mongos` instances: typically, you will run one
80
- :program:`mongos` instance on each of your application servers.
68
+ All operations against a shard cluster go through the :program:`mongos`
69
+ instance. The :program:`mongos` instance routes queries and operations
70
+ to the appropriate shards and interacts with the configdb instances.
71
+
72
+ :program:`mongos` instances are lightweight, and a shard cluster can
73
+ have multiple instances. Typically, you run one :program:`mongos`
74
+ instance on each of your application servers.
75
+
76
+ You must specify three config servers. Use resolvable host names for
77
+ all hosts, using DNS or your system's hostfile to provide operational
78
+ flexibility.
79
+
80
+ The :program:`mongos` instance runs on the default MongoDB port of ``27017``.
81
81
82
82
Use the following command at a system prompt to start a
83
- :program:`mongos`:
83
+ :program:`mongos` instance :
84
84
85
85
.. code-block:: sh
86
86
87
87
mongos --configdb config0.mongodb.example.net,config1.mongodb.example.net,config2.mongodb.example.net --port 27017
88
88
89
- This invocation assumes that you have config servers running on the
90
- following hosts:
89
+ The above example assumes that you have config servers running on the following hosts:
91
90
92
91
- ``config0.mongodb.example.net``
93
92
- ``config1.mongodb.example.net``
94
93
- ``config2.mongodb.example.net``
95
94
96
- The :program:`mongos` will run on the default MongoDB port of
97
- ``27017``.
98
-
99
- You must specify three config servers. Use resolvable host names for
100
- all hosts, using DNS or your systems hostfile to provide operational
101
- flexibility.
102
-
103
95
Add Shards to the Cluster
104
96
~~~~~~~~~~~~~~~~~~~~~~~~~
105
97
106
98
In a production shard cluster, each shard is itself a :term:`replica
107
- set`. Deploy at least two replica sets, for use as shards. See
108
- ":doc:`/tutorial/deploy-replica-set`" for instructions regarding
109
- replica set deployment. When you have two active and functioning
110
- replica sets, continue below.
99
+ set`. You must deploy at least two replica sets for use as shards. For
100
+ instructions on deploying replica sets, see
101
+ :doc:`/tutorial/deploy-replica-set`.
111
102
112
- Log into a :program:`mongos` using the :program:`mongo` shell. If the
113
- :program:`mongos` is accessible at ``mongos0.mongodb.example.net`` on
114
- port ``27017`` then this invocation would resemble:
103
+ When you have two active and functioning replica sets, perform the procedure here:
104
+
105
+ Using the :program:`mongo` shell, log into a :program:`mongos`. For example,
106
+ if the :program:`mongos` is accessible at
107
+ ``mongos0.mongodb.example.net`` on port ``27017`` you would type:
115
108
116
109
.. code-block:: sh
117
110
118
111
mongo mongos0.mongodb.example.net
119
112
120
- Then, use the :func:`sh.addShard()` to add each shard to the cluster.
113
+ To add each shard to the cluster, Use :func:`sh.addShard()`. For
114
+ example, to add two shards with the hostnames ``shard0.example.net`` and
115
+ ``shard1.example.net`` on port ``27017``, type:.
121
116
122
117
sh.addShard( "shard0.example.net" )
123
118
sh.addShard( "shard1.example.net" )
124
119
125
- This will add two shards with the hostnames ``shard0.example.net`` and
126
- ``shard1.example.net`` on port ``27017``.
127
-
128
- .. note:: In production deployments, all shards should be replica sets.
129
-
130
120
.. versionchanged:: 2.0.3
131
121
132
122
After version 2.0.3, you may use the above form to add replica
133
- sets to a cluster and the cluster will automatically discover
123
+ sets to a cluster. The cluster will automatically discover
134
124
the members of the replica set and adjust its configuration
135
125
accordingly.
136
126
137
127
Before version 2.0.3, you must specify the shard in the
138
128
following form: the replica set name, followed by a forward
139
129
slash, followed by a comma-separated list of seeds for the
140
130
replica set. For example, if the name of the replica set is
141
- " ``repl0``" , then your :func:`sh.addShard` command might resemble:
131
+ ``repl0``, then your :func:`sh.addShard` command might resemble:
142
132
143
133
.. code-block:: javascript
144
134
@@ -162,28 +152,26 @@ connected to a :program:`mongos` instance in your cluster:
162
152
163
153
sh.enableSharding("records")
164
154
165
- Where ``records`` is the name of the database that holds a collection
166
- that you want to shard. :func:`sh.enableSharding()` is a wrapper
155
+ Where ``records`` is the name of the database that holds the collection
156
+ you want to shard. :func:`sh.enableSharding()` is a wrapper
167
157
around the :dbcommand:`enableSharding` :term:`database command`. You
168
- may enable sharding for as many databases as you like in your
169
- deployment.
158
+ can enable sharding for multiple databases in your deployment.
170
159
171
160
Enable Sharding for Collections
172
161
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173
162
174
- Finally, you may enable sharding on a per-collection basis. Because
163
+ You can enable sharding on a per-collection basis. Because
175
164
MongoDB uses "range based sharding," you must specify a :term:`shard
176
- key` that MongoDB can use to distribute your documents among the
177
- shards. See the section of this manual that provides an :ref:`overview
178
- of shard keys <sharding-shard-key>` as well as the section that
179
- explores the :ref:`features of good shard keys in-depth
180
- <sharding-shard-key>`.
181
-
182
- Enable sharding for a collection using the
183
- :func:`sh.shardCollection()` helper in the :program:`mongo` shell,
184
- which provides a wrapper around the :dbcommand:`shardCollection`
185
- :term:`database command`. The shell helper has the following prototype
186
- form:
165
+ key` MongoDB can use to distribute your documents among the
166
+ shards. For more information, see the sections of this manual that give
167
+ an :ref:`overview of shard keys <sharding-shard-key>` and that
168
+ give an in-depth exploration of the
169
+ :ref:`features of good shard keys <sharding-shard-key>`.
170
+
171
+ To enable sharding for a collection, use the
172
+ :func:`sh.shardCollection()` helper in the :program:`mongo` shell.
173
+ The helper provides a wrapper around the :dbcommand:`shardCollection`
174
+ :term:`database command` and has the following prototype form:
187
175
188
176
.. code-block:: javascript
189
177
@@ -240,6 +228,6 @@ In order, these operations shard:
240
228
``{ "hashed_id": 1 }``.
241
229
242
230
This shard key distributes documents by the value of the
243
- ``hashed_id`` field. Presumably this is a is a computed value that
244
- holds the hash of some value in your documents, and will be able to
231
+ ``hashed_id`` field. Presumably this is a computed value that
232
+ holds the hash of some value in your documents and is able to
245
233
evenly distribute documents throughout your cluster.
0 commit comments