mongodb副本集

mongod  --replSet  rs1  --keyFile  D:\MongoDB\data\r1   --port 28010 --dbpath D:\MongoDB\data\db1 --logpath=D:\MongoDB\data\r1.log --logappend


mongod  --replSet  rs1  --keyFile  D:\MongoDB\data\r2  --port 28011 --dbpath D:\MongoDB\data\db2 --logpath=D:\MongoDB\data\r2.log --logappend


mongod  --replSet  rs1  --keyFile  D:\MongoDB\data\r3  --port 28012 --dbpath D:\MongoDB\data\db3 --logpath=D:\MongoDB\data\r3.log --logappend


mongod  --replSet  rs1  --keyFile  D:\MongoDB\data\r4  --port 28013 --dbpath D:\MongoDB\data\db4 --logpath=D:\MongoDB\data\r4.log --logappend






D:\MongoDB\Server\3.0\bin




mongo -port 28010 
mongo -port 28011




config_rs1 = {_id: 'rs1', members: [ 
    {_id: 0, host: 'localhost:28010', priority:1},  
    {_id: 1, host: 'localhost:28011'}, 
    {_id: 2, host: 'localhost:28012'}] 

rs.initiate(config_rs1);
rs.status()
rs.isMaster()
show collections


use admin;
db.createUser( {
    user: "sa",
    pwd: "sa",
    roles: [ { role: "root", db: "admin" } ]
  });




 db.auth('sa','sa');

你可能感兴趣的:(数据库)