1. Assume that 1 database server is Active server (master server), 2 and 3 is the backup server, when 1 fails, then will be in 2 and 3 to elect one (according to the weight of the rules) as an active server, and when 1 is back to normal, it will be the identity of the backup server to appear;
2. Set the value of the database server (in the configuration file to be set to a closed loop):
For example, set up a replica cluster of three databases:
Database 1:dbpath= D:/AA/AA/1
port= 1111 #端口号
bind_ip= 127.0.0.1 #服务器的IP地址
replset= child/127.0.0.1:2222 #备份的服务器同伴
Located in the 1.conf configuration file;
Database 2:dbpath= D:/AA/AA/2
port= 2222 #端口号
bind_ip= 127.0.0.1 #服务器的IP地址
replset= child/127.0.0.1:3333 #备份的服务器同伴
Located in the 2.conf configuration file;
Database 3:dbpath= D:/AA/AA/3
port= 333 #端口号
bind_ip= 127.0.0.1 #服务器的IP地址
replset= child/127.0.0.1:1111 #备份的服务器同伴
Located in the 3.conf configuration file;
And then in the corresponding server-initiated batch file in the 1.conf corresponding to the same as 1 database boot server Mongod--config the same as the same can be * * *;
In the shell, such as 1 database server Direct input: MONGO 127.0.0.1:1111 other similar;
3. If you want a replica cluster that is configured above to work, you must execute the command:
3.1 Use database name input: Db.runcommand ({"Replsetinitiate"):
{
"_id": "Child",
"Menbers": [{"_id": 1, "host": "127.0.0.1:1111"},{"_id": 1, "host": "127.0.0.1:2222"},{"_id": 1, "host": "127.0.0.1 : 3333 "}]
}
});
4. Use Rs.status () to view the status of the replica cluster database server;
The replica database server for MongoDB