Set up the MongoDB replica sets mode. This article is tested in version 2.0.5.
Mongo: http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.5.tgz
Decompress the package to the/usr/local/MongoDB/directory.
Assume that there are three servers, server1 server2 server3 (Act as arbiter). If you start a command on one server, you need to add different ports and direct them to different database storage addresses.
Run the following commands on the three servers:
# Rm-RDF/mnt/dbdata /*
# Rm-RDF/mnt/dblog /*
# Mkdir-P/mnt/dbdata
# Mkdir-P/mnt/dblog
# Mkdir-P/mnt/dbkey
# Echo "my pass word">/mnt/dbkey/pass
# Chmod 600/mnt/dbkey/pass
Start Mongo on three servers
#/Usr/local/MongoDB/bin/mongod -- Keyfile/mnt/dbkey/pass -- replset myset -- dbpath/mnt/dbdata -- logpath/mnt/dblog/mongodb1.log -- auth -- fork
Set replica sets
Run
#/Usr/local/MongoDB/bin/Mongo
> CFG = {
_ ID: "myset ",
Members :[
{_ ID: 0, host: "server1 "},
{_ ID: 1, host: "server2"}]}
> Rs. Initiate (CFG );
Wait for several minutes to complete.
Or execute Rs. Initiate () and then execute
Rs. Add ("server2 ");
Add the arbiter Server
Primary> Rs. addarb ("server3 ");
Execute Rs. Status (); if everything is normal, OK.
--------------------------------------------------------
Set the database password:
Use Admin
DB. adduser ("rootuser", "1111111 ");
Logon:
/Usr/local/MongoDB/bin/Mongo
Use Admin
DB. Auth ("rootuser", "1111111 ");
To add a database and set a password, run the command on primary.