becomes inaccessible. See the MongoDB Cloud Manager documentation 43 and Ops Manager documentation 44 for more information. 

Balancing and Chunk Distribution The most effective sharded cluster deployments evenly balance chunks among the shards. To facilitate this, MongoDB has a background balancer process that distributes data to ensure that chunks are always optimally distributed among the shards . 

Issue the db.printShardingStatus() or sh.status() command to the mongos by way of the mongo shell. This returns an overview of the entire cluster including the database name, and a list of the chunks. 

Stale Locks In nearly every case, all locks used by the balancer are automatically released when they become stale. However, because any long lasting lock can block future balancing, it’s important to ensure that all locks are legitimate. To check the lock status of the database, connect to a mongos instance using the mongo shell. Issue the following command sequence to switch to the config database and display all outstanding locks on the shard database: 

use config db.locks.find() 

For active deployments, the above query can provide insights. The balancing process, which originates on a randomly selected mongos , takes a special “balancer” lock that prevents other balancing activity from transpiring. Use the following command, also to the config database, to check the status of the “balancer” lock. 

db.locks.find( { _id : "balancer" } ) 

If this lock exists, make sure that the balancer process is actively using this lock. 

## Additional Resources 

• MongoDB Production Readiness Consulting Package 45 

## Run-time Database Configuration 

The command line and configuration file interfaces provide MongoDB administrators with a large num- ber of options and settings for controlling the operation of the database system. This document provides an overview of common configurations and examples of best-practice configurations for common use cases. 

While both interfaces provide access to the same collection of options and settings, this document primarily uses the configuration file interface. If you run MongoDB using a control script or installed from a package for your operating system, you likely already have a configuration file located at /etc/mongod.conf . Confirm this by checking the contents of the /etc/init.d/mongod or /etc/rc.d/mongod script to ensure that the control scripts start the mongod with the appropriate configuration file (see below.) 

To start a MongoDB instance using this configuration file, issue a command in the following form: 

mongod --config /etc/mongod.conf mongod -f /etc/mongod.conf 

Modify the values in the /etc/mongod.conf file on your system to control the configuration of your database instance. 

