Skip to content

Commit e1d9a26

Browse files
author
Bob Grabar
committed
DOCS-246 edits to deploy rs tutorial
1 parent 7c78aca commit e1d9a26

File tree

1 file changed

+136
-130
lines changed

1 file changed

+136
-130
lines changed

source/tutorial/deploy-replica-set.txt

Lines changed: 136 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -4,135 +4,138 @@ Deploy a Replica Set
44

55
.. default-domain:: mongodb
66

7-
This tutorial describes the process for deploying a three member
8-
:term:`replica set` , with specific instructions for development and
9-
test as well as for production systems.
7+
This tutorial describes how to deploy a three member
8+
:term:`replica set`, with specific instructions for development
9+
and test systems and for production systems.
1010

11-
.. seealso:: ":doc:`/core/replication`" and
12-
":doc:`/administration/replication-architectures`" for appropriate
13-
background.
11+
.. seealso:: For appropriate background, see :doc:`/core/replication`
12+
and :doc:`/administration/replication-architectures`.
1413

1514
Overview
1615
--------
1716

18-
Three member replica sets provide enough redundancy to survive most
17+
Three member :term:`replica sets <replica set>` provide enough redundancy to survive most
1918
network partitions and other system failures. Additionally, these sets
2019
have sufficient capacity for many distributed read operations. Most
21-
deployments require no additional nodes or configuration.
20+
deployments require no additional members or configuration.
2221

2322
Requirements
2423
------------
2524

26-
Three distinct systems, so that each system can run its own instance
27-
of :program:`mongod`. For development systems you may run all three
25+
A replica set requires three distinct systems so that each system can run its own instance
26+
of :program:`mongod`. For development systems you can run all three
2827
instances of the :program:`mongod` process on a local system. (e.g. a
2928
laptop) or within a virtual instance. For production environments, you
30-
should endeavor to maintain as much separation between the nodes. For
31-
example, when using VMs in Production, each node should live on
29+
should endeavor to maintain as much separation between the members as possible. For
30+
example, when using VMs in Production, each member should live on
3231
separate host servers, served by redundant power circuits, and with
3332
redundant network paths.
3433

3534
Procedure
3635
---------
3736

38-
This procedure assumes that you already have instances of MongoDB
39-
installed on all systems that you hope to have as members of your
40-
replica set. If you have not already installed MongoDB, see the
37+
These procedures assume you already have instances of MongoDB
38+
installed on the systems you will add as members of your
39+
:term:`replica set`. If you have not already installed MongoDB, see the
4140
:ref:`installation tutorials <tutorials-installation>`.
4241

43-
Development and Test Replica Set
44-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
Deploy a Development or Testing Replica Set
43+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4544

46-
Begin by starting three instances of :program:`mongod`. For ephemeral
47-
tests and the purposes of this guide, you may run the :program:`mongod`
48-
instances in separate windows of GNU Screen. OS X and most Linux
49-
distributions come with screen installed by default [#screen]_
50-
systems.
45+
The examples in this procedure create a new replica set named ``rs0``.
5146

52-
Issue the following command to create the necessary data directories:
47+
1. Start three instances of :program:`mongod` as members of a replica
48+
set named ``rs0``, as described in this step. For ephemeral tests and
49+
the purposes of this guide, you may run the :program:`mongod`
50+
instances in separate windows of GNU Screen. OS X and most Linux
51+
distributions come with screen installed by default [#screen]_
52+
systems.
5353

54-
.. code-block:: sh
54+
a. Create the necessary data directories by issuing a command
55+
similiar to the following:
5556

56-
mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2
57+
.. code-block:: sh
5758

58-
Issue the following commands, each in a distinct screen window:
59+
mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2
5960

60-
.. code-block:: sh
61+
#. Issue the following commands, each in a distinct screen window:
6162

62-
mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0
63-
mongod --port 27018 --dbpath /srv/mongodb/rs0-1 --replSet rs0
64-
mongod --port 27019 --dbpath /srv/mongodb/rs0-2 --replSet rs0
63+
.. code-block:: sh
6564

66-
These command start members of a replica set named ``rs0``, each
67-
running on a distinct port. Alternatively, if you are already using these
68-
ports, you can select different ports. See the documentation of the
69-
following options for more information: :option:`--port <mongod --port>`,
70-
:option:`--dbpath <mongod --dbpath>`, and :option:`--replSet <mongod --replSet>`.
65+
mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0
66+
mongod --port 27018 --dbpath /srv/mongodb/rs0-1 --replSet rs0
67+
mongod --port 27019 --dbpath /srv/mongodb/rs0-2 --replSet rs0
7168

72-
Connect to the :program:`mongod` instance with the :program:`mongo`
73-
shell to the first host. If you're running this command remotely,
74-
replace "localhost" with the appropriate hostname. In a new shell
75-
session, enter the following:
69+
This starts each instance as a member of a replica set named
70+
``rs0``, each running on a distinct port. If you are already using
71+
these ports, you can select different ports. See the documentation
72+
of the following options for more information: :option:`--port
73+
<mongod --port>`, :option:`--dbpath <mongod --dbpath>`, and
74+
:option:`--replSet <mongod --replSet>`.
7675

77-
.. code-block:: sh
76+
#. Open a :program:`mongo` shell and connect to the first
77+
:program:`mongod` instance. If you're running this command remotely,
78+
replace "localhost" with the appropriate hostname. In a new shell
79+
session, enter the following:
7880

79-
mongo localhost:27017
81+
.. code-block:: sh
8082

81-
Issue the following shell function to initiate a replica set
82-
consisting of the current node, using the default configuration:
83+
mongo localhost:27017
8384

84-
.. code-block:: javascript
85+
#. Use :method:`rs.initiate()` to initiate a replica set consisting of
86+
the current member and using the default configuration:
8587

86-
rs.initiate()
88+
.. code-block:: javascript
8789

88-
Use the following shell function to display the current :doc:`replica
89-
configuration </reference/replica-configuration>`:
90+
rs.initiate()
9091

91-
.. code-block:: javascript
92+
#. Display the current :doc:`replica configuration </reference/replica-configuration>`:
9293

93-
rs.conf()
94+
.. code-block:: javascript
9495

95-
Now, issue the following sequence of commands to add two nodes to the
96-
replica set.
96+
rs.conf()
9797

98-
.. code-block:: javascript
98+
#. Add two members to the replica set by issuing a sequence of commands
99+
similar to the following.
99100

100-
rs.add("localhost:27018")
101-
rs.add("localhost:27019")
101+
.. code-block:: javascript
102102

103-
Congratulations, after these commands return you will have a fully
104-
functional replica set. The new replica set should successfully elect
105-
a :term:`primary` node within a few seconds.
103+
rs.add("localhost:27018")
104+
rs.add("localhost:27019")
106105

107-
Check the status of your replica set at any time with the
108-
:method:`rs.status()` operation.
106+
After these commands return you have a fully functional replica set.
107+
New replica sets elect a :term:`primary` within a seconds.
109108

110-
See the documentation of the following shell functions for more
111-
information: :method:`rs.initiate()`, :method:`rs.conf()`,
112-
:method:`rs.reconfig()` and :method:`rs.add()`.
109+
#. Check the status of your replica set at any time with the
110+
:method:`rs.status()` operation.
113111

114-
.. [#screen] `GNU Screen <http://www.gnu.org/software/screen/>`_ is packaged as
115-
``screen`` on Debian-based, Fedora/Red Hat-based, and Arch Linux.
116112

117-
.. seealso:: You may also consider the "`simple setup script
118-
<https://github.com/mongodb/mongo-snippets/blob/master/replication/simple-setup.py>`_"
113+
.. seealso:: The documentation of the following shell functions for
114+
more information:
115+
116+
- :method:`rs.initiate()`
117+
- :method:`rs.conf()`
118+
- :method:`rs.reconfig()`
119+
- :method:`rs.add()`
120+
121+
You may also consider the `simple setup script
122+
<https://github.com/mongodb/mongo-snippets/blob/master/replication/simple-setup.py>`_
119123
as an example of a basic automatically configured replica set.
120124

121-
Production Replica Set
122-
~~~~~~~~~~~~~~~~~~~~~~
125+
.. [#screen] `GNU Screen <http://www.gnu.org/software/screen/>`_ is packaged as
126+
``screen`` on Debian-based, Fedora/Red Hat-based, and Arch Linux.
127+
128+
Deploy a Production Replica Set
129+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123130

124131
Production replica sets are very similar to the development or testing
125132
deployment described above, with the following differences:
126133

127-
- Each member of the replica set will reside on it's own machine, and
128-
the MongoDB processes will all bind to port ``27017``, which is the
134+
- Each member of the replica set resides on it's own machine, and
135+
the MongoDB processes all bind to port ``27017``, which is the
129136
standard MongoDB port.
130137

131-
- Specify all run-time configuration in :doc:`configuration files
132-
</reference/configuration-options>` rather than as :doc:`command
133-
line options </reference/mongod>`.
134-
135-
- Each member of the replica set needs to be accessible by way of
138+
- Each member of the replica set must be accessible by way of
136139
resolvable DNS or hostnames in the following scheme:
137140

138141
- ``mongodb0.example.net``
@@ -142,89 +145,92 @@ deployment described above, with the following differences:
142145
Configure DNS names appropriately, *or* set up your systems'
143146
``/etc/host`` file to reflect this configuration.
144147

145-
Use the following configuration for each MongoDB instance.
148+
- You specify run-time configuration on each system in a
149+
:doc:`configuration file <reference/configuration-options>` stored in
150+
``/etc/mongodb.conf`` or in a related location. You *do not* specify
151+
run-time configuration through command line options.
152+
153+
For each MongoDB instance, use the following configuration. Set
154+
configuration values appropriate to your systems:
155+
156+
.. code-block:: cfg
146157

147-
.. code-block:: cfg
158+
port = 27017
148159

149-
port = 27017
160+
bind_ip = 10.8.0.10
150161

151-
bind_ip = 10.8.0.10
162+
dbpath = /srv/mongodb/
152163

153-
dbpath = /srv/mongodb/
164+
fork = true
154165

155-
fork = true
166+
replSet = rs0
156167

157-
replSet = rs0
168+
You do not need to specify an interface with :setting:`bind_ip`.
169+
However, if you do not specify an interface, MongoDB listens for
170+
connections on all available IPv4 interfaces. Modify
171+
:setting:`bind_ip` to reflect a secure interface on your system that
172+
is able to access all other members of the set *and* on which all
173+
other members of the replica set can access the current member. The
174+
DNS or host names must point and resolve to this IP address.
175+
Configure network rules or a virtual private network (i.e. "VPN") to
176+
permit this access.
158177

159-
You do not need to specify an interface with
160-
:setting:`bind_ip`. However, if you do not specify an interface,
161-
MongoDB will listen for connections on all available IPv4
162-
interfaces. Modify :setting:`bind_ip` to reflect a secure interface on
163-
your system that will be able to access all other members of the set
164-
*and* on which all other members of the replica set can access the
165-
current node. The DNS or host names need to point and resolve to this
166-
IP address. Configure network rules or a virtual private network
167-
(i.e. "VPN") to permit this access.
178+
For more documentation on run time options used above and on
179+
additional configuration options, see
180+
:doc:`/reference/configuration-options`.
168181

169-
For more documentation of the run time options used above, see:
170-
:setting:`dbpath`, :setting:`port`, :setting:`replSet`,
171-
:setting:`bind_ip`, and :setting:`fork`. Also consider any additional
172-
:doc:`configuration options </reference/configuration-options>` that
173-
your deployment may require.
182+
To deploy a production replica set:
174183

175-
Store the configuration file on each system, at ``/etc/mongodb.conf``
176-
or a related location on the file system.
184+
1. On each system start the :program:`mongod` process by issuing a
185+
command similar to following:
177186

178-
On each system issue the following command to start the
179-
:program:`mongod` process:
187+
.. code-block:: sh
180188

181-
.. code-block:: sh
189+
mongod --config /etc/mongodb.conf
182190

183-
mongod --config /etc/mongodb.conf
191+
.. note::
184192

185-
.. note::
193+
In production deployments you likely want to use and configure a
194+
:term:`control script` to manage this process based on this
195+
command. Control scripts are beyond the scope of this document.
186196

187-
In production deployments you likely want to use and configure a
188-
:term:`control script` to manage this process based on this
189-
command. Control scripts are beyond the scope of this document.
197+
#. Open a :program:`mongo` shell connected to this host:
190198

191-
Log in with the :program:`mongo` shell to this host using the following
192-
command:
199+
.. code-block:: sh
193200

194-
.. code-block:: sh
201+
mongo
195202

196-
mongo
203+
#. Use :method:`rs.initiate()` to initiate a replica set consisting of
204+
the current member and using the default configuration:
197205

198-
Issue the following shell function to initiate a replica set
199-
consisting of the current node, using the default configuration:
206+
.. code-block:: javascript
200207

201-
.. code-block:: javascript
208+
rs.initiate()
202209

203-
rs.initiate()
210+
#. Display the current :doc:`replica configuration </reference/replica-configuration>`:
204211

205-
Use the following shell function to display the current :doc:`replica
206-
configuration </reference/replica-configuration>`:
212+
.. code-block:: javascript
207213

208-
.. code-block:: javascript
214+
rs.conf()
209215

210-
rs.config()
216+
#. Add two members to the replica set by issuing a sequence of commands
217+
similar to the following.
211218

212-
Now, issue the following sequence of commands to add two nodes to the
213-
replica set.
219+
.. code-block:: javascript
214220

215-
.. code-block:: javascript
221+
rs.add("mongodb1.example.net")
222+
rs.add("mongodb2.example.net")
216223

217-
rs.add("mongodb1.example.net")
218-
rs.add("mongodb2.example.net")
224+
After these commands return you have a fully functional replica set.
225+
New replica sets elect a :term:`primary` within a seconds.
219226

220-
Congratulations, after these commands return you will have a fully
221-
functional replica set. New replica sets will elect a :term:`primary`
222-
within a few moments.
227+
#. Check the status of your replica set at any time with the
228+
:method:`rs.status()` operation.
223229

224230
.. seealso:: The documentation of the following shell functions for
225231
more information:
226232

227-
- :method:`rs.initiate()`,
228-
- :method:`rs.conf()`,
229-
- :method:`rs.reconfig()`, and
230-
- :method:`rs.add()`.
233+
- :method:`rs.initiate()`
234+
- :method:`rs.conf()`
235+
- :method:`rs.reconfig()`
236+
- :method:`rs.add()`

0 commit comments

Comments
 (0)