@@ -4,135 +4,138 @@ Deploy a Replica Set
4
4
5
5
.. default-domain:: mongodb
6
6
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.
10
10
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`.
14
13
15
14
Overview
16
15
--------
17
16
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
19
18
network partitions and other system failures. Additionally, these sets
20
19
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.
22
21
23
22
Requirements
24
23
------------
25
24
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
28
27
instances of the :program:`mongod` process on a local system. (e.g. a
29
28
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
32
31
separate host servers, served by redundant power circuits, and with
33
32
redundant network paths.
34
33
35
34
Procedure
36
35
---------
37
36
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
41
40
:ref:`installation tutorials <tutorials-installation>`.
42
41
43
- Development and Test Replica Set
44
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42
+ Deploy a Development or Testing Replica Set
43
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
44
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``.
51
46
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.
53
53
54
- .. code-block:: sh
54
+ a. Create the necessary data directories by issuing a command
55
+ similiar to the following:
55
56
56
- mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2
57
+ .. code-block:: sh
57
58
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
59
60
60
- .. code-block:: sh
61
+ #. Issue the following commands, each in a distinct screen window:
61
62
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
65
64
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
71
68
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>`.
76
75
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:
78
80
79
- mongo localhost:27017
81
+ .. code-block:: sh
80
82
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
83
84
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:
85
87
86
- rs.initiate()
88
+ .. code-block:: javascript
87
89
88
- Use the following shell function to display the current :doc:`replica
89
- configuration </reference/replica-configuration>`:
90
+ rs.initiate()
90
91
91
- .. code-block:: javascript
92
+ #. Display the current :doc:`replica configuration </reference/replica-configuration>`:
92
93
93
- rs.conf()
94
+ .. code-block:: javascript
94
95
95
- Now, issue the following sequence of commands to add two nodes to the
96
- replica set.
96
+ rs.conf()
97
97
98
- .. code-block:: javascript
98
+ #. Add two members to the replica set by issuing a sequence of commands
99
+ similar to the following.
99
100
100
- rs.add("localhost:27018")
101
- rs.add("localhost:27019")
101
+ .. code-block:: javascript
102
102
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")
106
105
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 .
109
108
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.
113
111
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.
116
112
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>`_
119
123
as an example of a basic automatically configured replica set.
120
124
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
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123
130
124
131
Production replica sets are very similar to the development or testing
125
132
deployment described above, with the following differences:
126
133
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
129
136
standard MongoDB port.
130
137
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
136
139
resolvable DNS or hostnames in the following scheme:
137
140
138
141
- ``mongodb0.example.net``
@@ -142,89 +145,92 @@ deployment described above, with the following differences:
142
145
Configure DNS names appropriately, *or* set up your systems'
143
146
``/etc/host`` file to reflect this configuration.
144
147
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
146
157
147
- .. code-block:: cfg
158
+ port = 27017
148
159
149
- port = 27017
160
+ bind_ip = 10.8.0.10
150
161
151
- bind_ip = 10.8.0.10
162
+ dbpath = /srv/mongodb/
152
163
153
- dbpath = /srv/mongodb/
164
+ fork = true
154
165
155
- fork = true
166
+ replSet = rs0
156
167
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.
158
177
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`.
168
181
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:
174
183
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:
177
186
178
- On each system issue the following command to start the
179
- :program:`mongod` process:
187
+ .. code-block:: sh
180
188
181
- .. code-block:: sh
189
+ mongod --config /etc/mongodb.conf
182
190
183
- mongod --config /etc/mongodb.conf
191
+ .. note::
184
192
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.
186
196
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:
190
198
191
- Log in with the :program:`mongo` shell to this host using the following
192
- command:
199
+ .. code-block:: sh
193
200
194
- .. code-block:: sh
201
+ mongo
195
202
196
- mongo
203
+ #. Use :method:`rs.initiate()` to initiate a replica set consisting of
204
+ the current member and using the default configuration:
197
205
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
200
207
201
- .. code-block:: javascript
208
+ rs.initiate()
202
209
203
- rs.initiate()
210
+ #. Display the current :doc:`replica configuration </reference/replica-configuration>`:
204
211
205
- Use the following shell function to display the current :doc:`replica
206
- configuration </reference/replica-configuration>`:
212
+ .. code-block:: javascript
207
213
208
- .. code-block:: javascript
214
+ rs.conf()
209
215
210
- rs.config()
216
+ #. Add two members to the replica set by issuing a sequence of commands
217
+ similar to the following.
211
218
212
- Now, issue the following sequence of commands to add two nodes to the
213
- replica set.
219
+ .. code-block:: javascript
214
220
215
- .. code-block:: javascript
221
+ rs.add("mongodb1.example.net")
222
+ rs.add("mongodb2.example.net")
216
223
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.
219
226
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.
223
229
224
230
.. seealso:: The documentation of the following shell functions for
225
231
more information:
226
232
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