Este contenido no está disponible en el idioma seleccionado.

8.4.3. MongoDB


Use replica sets to achieve redundancy with MongoDB. See the following documents on the MongoDB website for more background information:
The following instructions describe how to create a replica set with the MongoDB package included with OpenShift Enterprise.

Procedure 8.10. To Install MongoDB on Each Host:

  1. 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
    Copy to Clipboard Toggle word wrap
  2. 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/*
    Copy to Clipboard Toggle word wrap

Procedure 8.11. To Configure the MongoDB Service on Each Host:

  1. Edit the /etc/mongodb.conf file 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
    Copy to Clipboard Toggle word wrap
    The following table provides a brief description of each setting from the example above.
    Expand
    Table 8.1. Descriptions of /etc/mongodb.conf Settings
    Setting 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 localhost interface. Specifying 0.0.0.0 binds 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.
  2. 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.keyfileecho "sharedkey" > /etc/mongodb.keyfileecho "sharedkey" > /etc/mongodb.keyfile
    # chown mongodb.mongodb /etc/mongodb.keyfile
    # chmod 400 /etc/mongodb.keyfile
    Copy to Clipboard Toggle word wrap
  3. Configure the firewall to allow MongoDB traffic on each host using the lokkit command:
    # lokkit --port=27017:tcp
    Copy to Clipboard Toggle word wrap
    Red Hat Enterprise Linux provides different methods for configuring firewall ports. Alternatively, use iptables directly to configure firewall ports.
  4. Start the MongoDB service on each host:
    # service mongod start
    Copy to Clipboard Toggle word wrap

Note

If you use the kickstart or bash script, the configure_datastore_add_replicants function performs the steps in the previous two procedures.
After all hosts to be included in the replica set are configured and started, use the MongoDB shell to connect to the primary instance and define the replica set. Although you might have already added data to the primary instance, other instances must be empty.

Procedure 8.12. To Form a Replica Set:

  1. Authenticate to the admin database and initiate the ose replica set:
    # mongo
    > use admin
    switched to db admin
    
    > db.auth("admin", "password")db.auth("admin", "password")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
    }
    Copy to Clipboard Toggle word wrap
  2. Wait a few moments then press Enter until you see the ose:PRIMARY prompt. Then add new members to the replica set:
    ose:PRIMARY> rs.add("mongo2.example.com:27017")rs.add("mongo2.example.com:27017")rs.add("mongo2.example.com:27017")
    { "ok" : 1 }
    Copy to Clipboard Toggle word wrap
    Repeat as required for all datastore hosts, using the FQDN or any resolvable name for each host.
  3. 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
    }
    [...]
    
    Copy to Clipboard Toggle word wrap
Update all broker hosts to use the new replica set.

Procedure 8.13. To Configure the Broker Application to Use a Replica Set:

  1. If you have not configured a MongoDB user named openshift to 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.
  2. Edit the /etc/openshift/broker.conf file on all broker hosts and set MONGO_HOST_PORT to 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"
    Copy to Clipboard Toggle word wrap
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat