2015-12-08 14:35:50.0|分类: MongoDB|浏览量: 3487
mongo查看状态 rs.status() mongo启动程序 mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0 --smallfiles --oplogSize 128 初始化副本集 rs.initiate() 初始化副本集配置 rsconf = { _id: "rs0", members: [ { _id: 0, host: "<hostname>:27017" } ] } rs.initiate( rsconf ) 验证副本集配置 rs.conf() { "_id" : "rs0", "version" : 1, "members" : [ { "_id" : 1, "host" : "mongodb0.example.net:27017" } ] } 增加副本集成员 rs.add("mongodb1.example.net") rs.add("mongodb2.example.net") 增加副本集成员,并且设置成优先级0 rs.add({_id: 1, host: "mongodb3.example.net:27017", priority: 0, hidden: true}) 查看副本集状态 rs.status() 配置成员优先级0 cfg = rs.conf() cfg.members[2].priority = 0 rs.reconfig(cfg) 增加副本集arbiter rs.addArb("mongodb4.example.net") 副本集删除成员 rs.remove("mongod3.example.net:27017") rs.remove("mongod3.example.net") change the hostname to mongo2.example.net for the replica set member configured at members[0], issue the following sequence of commands: cfg = rs.conf() cfg.members[0].host = "mongo2.example.net" rs.reconfig(cfg) 改变成员变量的优先级 cfg = rs.conf() cfg.members[0].priority = 3 cfg.members[1].priority = 1 cfg.members[2].priority = 2 rs.reconfig(cfg) Configure a Hidden Replica Set Member cfg = rs.conf() cfg.members[0].priority = 0 cfg.members[0].hidden = true rs.reconfig(cfg) 配置延迟副本集 cfg = rs.conf() cfg.members[0].priority = 0 cfg.members[0].hidden = true cfg.members[0].slaveDelay = 3600 rs.reconfig(cfg) Configure Non-Voting Replica Set Member cfg = rs.conf() cfg.members[3].votes = 0 cfg.members[4].votes = 0 cfg.members[5].votes = 0 rs.reconfig(cfg) |