标签:
1.修改oplog的大小
db.shutdownServer()
mongod --port 37017 --dbpath /usr/local/mongodb-linux-x86_64-3.2.0/data
[root@node1 mongodb-linux-x86_64-3.2.0]# mongodump --db local --collection ‘oplog.rs‘ --port 37017 2015-12-27T02:27:40.577+0800 writing local.oplog.rs to dump/local/oplog.rs.bson 2015-12-27T02:27:40.579+0800 done dumping local.oplog.rs (4 documents)
[root@node1 mongodb-linux-x86_64-3.2.0]# mongo --port 37017
MongoDB shell version: 3.2.0
connecting to: 127.0.0.1:37017/test
> db.temp.save(db.oplog.rs.find({},{ts:1,h:1}).sort({$natural:-1}).limit(1).next());
WriteResult({ "nInserted" : 1 })
> db.temp.find();
{ "_id" : ObjectId("567edd9e48b1a3ebcf06049c"), "ts" : Timestamp(1451203909, 1), "h" : NumberLong("4300737341732033822") }
db.oplog.rs.drop()
db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024 * 1024) } )
(单位是字节)
db.oplog.rs.save( db.temp.findOne() ) 把temp中oplog保存到新建的oplog中
db.oplog.rs.find()
db.shutdownServer()
mongod --replSet rs0 --dbpath
/usr/local/mongodb-linux-x86_64-3.2.0/data
rs.stepDown()
cfg = rs.conf()
cfg.members[0].priority = 0.5
cfg.members[1].priority = 0.5
cfg.members[2].priority = 1
rs.reconfig(cfg)
db.adminCommand({replSetStepDown: 86400, force: 1}) 24小时内让其成为主节点
mongo
>rs.freeze(120);120秒内不能成为主节点
mongo
>rs.stepDown(120);
120秒内不能成为主节点
rs0:SECONDARY> rs.printSlaveReplicationInfo();
source: 192.168.75.10:27017
syncedTo: Sun Dec 27 2015 16:11:49 GMT+0800 (CST)
0 secs (0 hrs) behind the primary
source: 192.168.75.11:27017
syncedTo: Sun Dec 27 2015 16:11:49 GMT+0800 (CST)
0 secs (0 hrs) behind the primary
db = db.getSiblingDB("local")
db.oplog.rs.find().sort({$natural:-1}).limit(1)
db.oplog.rs.find({ts:{$type:17}}).sort({$natural:-1}).limit(1)
第一个查询结果
{ "ts" : {t: 1347982456000, i: 1},
"h" : NumberLong("8191276672478122996"),
"op" : "n",
"ns" : "",
"o" : { "msg" : "Reconfig set", "version" : 4 } }
- 第二个查询结果
{ "ts" : Timestamp(1347982454000, 1),
"h" : NumberLong("6188469075153256465"),
"op" : "n",
"ns" : "",
"o" : { "msg" : "Reconfig set", "version" : 3 } }
db.oplog.rs.update( { ts: { t:1347982456000, i:1 } },
{ $set: { ts: new Timestamp(1347982456000, 1)}})
标签:
原文地址:http://www.cnblogs.com/skyrim/p/5099839.html