|
MongoDB Database Management
Configuring a Replica Set: Adding a Secondary
How do you start?
.
- Make sure MongoDB is installed but stopped
- Add an entry to DNS or the local "/etc/hosts" file to identify all replica hosts
- Example: mongo0rs0.company.com, mongo1rs0.company.com, etc.
- Ensure that the secondary can connect to the primary
How many MongoDB instances should go into a set?
.
- A minimum of 3 is recommended:
1 primary and 2 secondaries - Maximum of 7 "voting" members
- Add as many non-voting members as desired
- Set priority=0 to make a member non-voting
How do you configure the mongod.conf file?
.
- Set the parameters as appropriate to your system
- Comment out bind_ip to allow MongoDB to respond to all network cards
- You must configure the replSet parameter
- Example: replSet=rs0
- Do not set priority here!
- Master/Slave configuration is not recommended: use replica sets
How do you initialize the secondary?
.
- Follow one of these strategies:
- 1A backup the /data/db folder of the primary
- 1B restore to the /data/db folder of the secondary
- OR 2A remove all files and folders from the /data/db folder of the secondary
What needs to be done on the primary?
.
- Add an entry to DNS or the local "/etc/hosts" file to identify the secondaries
- Example: mongo1rs0.company.com, mongo2rs0.company.com, etc.
- From the mongo command shell on the primary:
- rs.add("dns.address|hostname")
- Wait for the synchronization to occur
How do you know the replica set is running?
.
- Access the mongo shell
- The command prompt should reflect the status
- View status: rs.status()
- View config: rs.conf()
|
|