MongodbreplSet start and configure initialize the windows environment www.2cto.com start three instances: Java code d: mongodbbinmongod -- replSetrs1 -- port28010 -- dbpathd: mongodbdb28010 -- logpathd: mongo-- logappendd: mongodbbinmongod -- replSet
Start mongodb replSet and configure initialize the windows environment www.2cto.com to start three instances: Java code d: \ mongodb \ bin \ mongod -- replSet rs1 -- port 28010 -- dbpath d: \ mongodb \ db \ 28010 \ -- logpath d: \ mongodb \ logs \ 28010.log -- logappend d: \ mongodb \ bin \ mongod -- replSet
Mongodb replSet startup and configuration Initialization
Windows Environment
Www.2cto.com
Start three instances:
Java code
D: \ mongodb \ bin \ mongod -- replSet rs1 -- port 28010 -- dbpath d: \ mongodb \ db \ 28010 \ -- logpath d: \ mongodb \ logs \ 28010.log -- logappend
D: \ mongodb \ bin \ mongod -- replSet rs1 -- port 28011 -- dbpath d: \ mongodb \ db \ 28011 \ -- logpath d: \ mongodb \ logs \ 28011.log -- logappend
D: \ mongodb \ bin \ mongod -- replSet rs1 -- port 28012 -- dbpath d: \ mongodb \ db \ 28012 \ -- logpath d: \ mongodb \ logs \ 28012.log -- logappend
Configuration and initialization: (only configured at the first time)
Java code www.2cto.com
D: \ mongodb \ bin \ mongo-port 28010
Rscfg = {
"_ Id": "rs1 ",
"Members ":[
{
"_ Id": 0,
"Host": "localhost: 28010"
},
{
"_ Id": 1,
"Host": "localhost: 28011"
},
{
"_ Id": 2,
"Host": "localhost: 28012"
}
]
}
Rs. initiate (rscfg );
Rs. status ();
(When garbled characters are displayed in cmd, enter: chcp 65001 in cmd, and then change the display font to Lucida Console)
Access the slave database so that the slave database can be queried, so as to share a large number of query operations on the master database:
Java code
D: \ mongodb \ bin \ mongo-port 28011
Db. getMongo (). setSlaveOk ()
D: \ mongodb \ bin \ mongo-port 28012
Db. getMongo (). setSlaveOk ()