@@ -7,26 +7,24 @@ Deploy a Shard Cluster
77Synopsis
88--------
99
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`.
1615
1716Requirements
1817------------
1918
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>`.
2321
2422.. warning:: Sharding and "localhost" Addresses
2523
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
2826 :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``
3028 for *all* host settings. If you mix localhost addresses and remote
3129 host address, MongoDB will produce errors.
3230
@@ -40,105 +38,97 @@ Begin by configuring three config servers. These are very small
4038:program:`mongod` instances that provide cluster metadata. You must
4139have exactly *three* instances in production deployments. For
4240redundancy 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`.
4449
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 :
4651
4752.. code-block:: sh
4853
4954 mongod --configsvr
5055
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.
5762
5863Repeat this process for all three config servers.
5964
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-
7265Start ``mongos`` Instances
7366~~~~~~~~~~~~~~~~~~~~~~~~~~
7467
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``.
8181
8282Use the following command at a system prompt to start a
83- :program:`mongos`:
83+ :program:`mongos` instance :
8484
8585.. code-block:: sh
8686
8787 mongos --configdb config0.mongodb.example.net,config1.mongodb.example.net,config2.mongodb.example.net --port 27017
8888
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:
9190
9291- ``config0.mongodb.example.net``
9392- ``config1.mongodb.example.net``
9493- ``config2.mongodb.example.net``
9594
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-
10395Add Shards to the Cluster
10496~~~~~~~~~~~~~~~~~~~~~~~~~
10597
10698In 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`.
111102
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:
115108
116109.. code-block:: sh
117110
118111 mongo mongos0.mongodb.example.net
119112
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:.
121116
122117 sh.addShard( "shard0.example.net" )
123118 sh.addShard( "shard1.example.net" )
124119
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-
130120 .. versionchanged:: 2.0.3
131121
132122 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
134124 the members of the replica set and adjust its configuration
135125 accordingly.
136126
137127 Before version 2.0.3, you must specify the shard in the
138128 following form: the replica set name, followed by a forward
139129 slash, followed by a comma-separated list of seeds for the
140130 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:
142132
143133 .. code-block:: javascript
144134
@@ -162,28 +152,26 @@ connected to a :program:`mongos` instance in your cluster:
162152
163153 sh.enableSharding("records")
164154
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
167157around 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.
170159
171160Enable Sharding for Collections
172161~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
173162
174- Finally, you may enable sharding on a per-collection basis. Because
163+ You can enable sharding on a per-collection basis. Because
175164MongoDB 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:
187175
188176.. code-block:: javascript
189177
@@ -240,6 +228,6 @@ In order, these operations shard:
240228 ``{ "hashed_id": 1 }``.
241229
242230 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
245233 evenly distribute documents throughout your cluster.
0 commit comments