8.4.3. MongoDB
- Replication - http://docs.mongodb.org/manual/replication/
- Convert a Standalone to a Replica Set - http://docs.mongodb.org/manual/tutorial/convert-standalone-to-replica-set/
Procedure 8.10. To Install MongoDB on Each Host:
- On a minimum of three hosts, install MongoDB and turn on the MongoDB service to make it persistent:
#
yum install -y mongodb-server mongodb#chkconfig mongod on - If you choose to install MongoDB using the basic install script provided, you must also delete the initial data from all but one installation to make it a part of the replica set. Stop the MongoDB service and delete the data using:
#
service mongod stop#rm -rf /var/lib/mongodb/*
Procedure 8.11. To Configure the MongoDB Service on Each Host:
- Edit the
/etc/mongodb.conffile and modify or add the following information:bind_ip = 0.0.0.0 # allow access from all interfaces auth = true rest = true smallfiles = true keyFile = /etc/mongodb.keyfile replSet = ose journal = true
The following table provides a brief description of each setting from the example above.Table 8.1. Descriptions of
/etc/mongodb.confSettingsSetting Description bind_ip This specifies the IP address MongoDB listens on for connections. Although the value must be an external address to form a replica set, this procedure also requires it to be reachable on the localhostinterface. Specifying0.0.0.0binds to both.auth This enables the MongoDB authentication system, which requires a login to access databases or other information. rest This enables the simple REST API used by the replica set creation process. replSet This names a replica set, and must be consistent among all the members for replication to take place. keyFile This specifies the shared authentication key for the replica set, which is created in the next step. journal This enables writes to be journaled, which enables faster recoveries from crashes. smallfiles This reduces the initial size of data files, limits the files to 512MB, and reduces the size of the journal from 1GB to 128MB. - Create the shared key file with a secret value to synchronize the replica set. For security purposes, create a randomized value, and then copy it to all of the members of the replica set. Verify that the permissions are set correctly:
#
echo "sharedkey" > /etc/mongodb.keyfile#chown mongodb.mongodb /etc/mongodb.keyfile#chmod 400 /etc/mongodb.keyfile - Configure the firewall to allow MongoDB traffic on each host using the
lokkitcommand:#
lokkit --port=27017:tcpRed Hat Enterprise Linux provides different methods for configuring firewall ports. Alternatively, useiptablesdirectly to configure firewall ports. - Start the MongoDB service on each host:
#
service mongod start
Note
configure_datastore_add_replicants function performs the steps in the previous two procedures.
Procedure 8.12. To Form a Replica Set:
- Authenticate to the
admindatabase and initiate theosereplica set:#
mongo>use adminswitched to db admin >db.auth("admin", "password")1 >rs.initiate(){ "info2" : "no configuration explicitly specified -- making one", "me" : "mongo1.example.com:27017", "info" : "Config now saved locally. Should come online in about a minute.", "ok" : 1 } - Wait a few moments then press Enter until you see the
ose:PRIMARYprompt. Then add new members to the replica set:ose:PRIMARY>
rs.add("mongo2.example.com:27017"){ "ok" : 1 }Repeat as required for all datastore hosts, using the FQDN or any resolvable name for each host. - Verify the replica set members:
ose:PRIMARY>
rs.status(){ "set" : "ose", "date" : ISODate("2013-12-02T21:33:43Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "mongo1.example.com:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 1416, "optime" : Timestamp(1386019903, 1), "optimeDate" : ISODate("2013-12-02T21:31:43Z"), "self" : true }, { "_id" : 1, "name" : "mongo2.example.com:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 120, "optime" : Timestamp(1386019903, 1), "optimeDate" : ISODate("2013-12-02T21:31:43Z"), "lastHeartbeat" : ISODate("2013-12-02T21:33:43Z"), "lastHeartbeatRecv" : ISODate("2013-12-02T21:33:43Z"), "pingMs" : 1, "syncingTo" : "mongo1.example.com:27017" } ], "ok" : 1 } [...]
Procedure 8.13. To Configure the Broker Application to Use a Replica Set:
- If you have not configured a MongoDB user named
openshiftto allow access to the broker host before forming the replica set as described in Chapter 7, Manually Installing and Configuring a Broker Host, add it now. Database changes at this point are synchronized among all members of the replica set. - Edit the
/etc/openshift/broker.conffile on all broker hosts and setMONGO_HOST_PORTto the appropriate replica set members:# For replica sets, use ',' delimiter for multiple servers # Eg: MONGO_HOST_PORT="<host1:port1>,<host2:port2>..." MONGO_HOST_PORT="mongo1.example.com:27017,mongo2.example.com:27017,mongo3.example.com:27017" MONGO_USER="openshift" MONGO_PASSWORD="password" MONGO_DB="openshift_broker"

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.