MongoDB Tutorial if you are using Replica Sets.
This tutorial builds on the tutorial located here. Refer
to that tutorial on the basics of installing just a single MongoDB
MongoDB supports what is called a Replica set. This differs slightly from the master/slave paridigmn where all transactions in a master/slave took place through the master - the slave served mostly as a hot spare.
Replica sets can function all at once and provides a "High Availability" setup. The master node of a replica set accepts all incoming changes and then the secondary nodes (which can be to the nth in number) consume the changes. All nodes within a replica set can answer to a query. If you have a large replica set it is highly advised that one node be set up as an Arbitrator - the decision maker if this a conflict between the nodes.
Refer to here on how to setup a replica set or let your fingers do the walking in Google as there are many good tutorials on how to accomplish that.
A very important "Ah-Gotcha" about replica sets. DNS and Hostnames can cause you much grief with replica sets. By default Mongo takes the hostname of the machine to be used in the replica set configuration (data that gets passed back to the PHP Mongo client). This can cause a big problem if the replica set configuration has a server name within it that can't be resolved from your external servers.
If you are building this in AWS reference this post on StackOverflow about how to automatically configure and create DNS entries for EC2 instances using Route53, a python utility, and instance meta-data. This also gives you a handy fixed DNS name for you primary Mongo server of your replica set that can be configured in your Drupal setup.
Now for the actual configuration for replica sets. This configuration is exactly the same as the other tutorial with the addition of online one line of code:
'connection_options' => array( 'replicaSet' => 'REPLICASETNAME' ),
So the complete settings.php additions that need to be added look like:
$conf['mongodb_connections'] = array(
'default' => array( // Connection name/alias
'host' => 'USER:PASS@HOST1,USER@PASS@HOST2,....', // Omit USER:PASS@ if Mongo isn't configured to use authentication. Add more than one for fallover.
'db' => 'YOURDBNAME', // Database name. Make something up, mongodb will automatically create the database.
'connection_options' => array( 'replicaSet' => 'REPLICASETNAME' ), //The name of the Replica Set you are attaching to
# -- Configure Cache
$conf['cache_backends'] = 'sites/all/modules/contrib/mongodb/mongodb_cache/mongodb_cache.inc';
$conf['cache_class_cache'] = 'DrupalMongoDBCache';
$conf['cache_class_cache_bootstrap'] = 'DrupalMongoDBCache';
$conf['cache_default_class'] = 'DrupalMongoDBCache';
# -- Don't touch SQL if in Cache
$conf['page_cache_without_database'] = TRUE;
$conf['page_cache_invoke_hooks'] = FALSE;
# Session Caching
$conf['session_inc'] = 'sites/all/modules/contrib/mongodb/mongodb_session/mongodb_session.inc';
$conf['cache_session'] = 'DrupalMongoDBCache';
# Field Storage
$conf['field_storage_default'] = 'mongodb_field_storage';
# Message Queue
$conf['queue_default_class'] = 'MongoDBQueue';
The last thing that can be added is the following. If you want to make it so that the php driver be able to query the slaves of the replica set (you probably do if you are running a replica set), add the following to your settings.php file
MongoCursor::$slaveOkay = true;