首页 > 数据库 > NoSQL > mongodb副本集集群测试
副本集测试
hared:PRIMARY> for(var
i=0;i<100000;i++){for(var i=0;i<100000;i++){
...
db.test2.insert({"name":"zhangting"});db.test2.insert({"name":"zhangting"});
... };};
WriteResult({ "nInserted" : 1 })
shared:PRIMARY>
shared:PRIMARY> show dbs;show dbs;
local
2.077GB
test
0.078GB
test2
0.078GB
shared:PRIMARY> useruser
2015-08-24T22:25:08.904-0400 E QUERY ReferenceError: user is not defined
at (shell):1:1
shared:PRIMARY>
shared:PRIMARY> use test;use test;
switched to db test
shared:PRIMARY> show collections;show
collections;
system.indexes
testdb
shared:SECONDARY>
db.getMongo().setSlaveOk();db.getMongo().setSlaveOk();
shared:SECONDARY> show collections;show
collections;
system.indexes
test22
user
shared:SECONDARY>
db.test2.count();db.test2.count();
100000
shared:SECONDARY>
通过db.printReplicationInfo() 可以查看副本集节点的oplog状态:
查看副本集节点的oplog的状态
shared:PRIMARY>
db.printReplicationInfo();db.printReplicationInfo();
configured oplog size: 2003.8828125MB
log length start to end: 71820secs
(19.95hrs)
oplog first event time: Mon Aug 24 2015 02:41:45 GMT-0400 (EDT)
oplog last event time: Mon Aug 24 2015 22:38:45 GMT-0400 (EDT)
now: Mon Aug 24 2015 22:56:06
GMT-0400 (EDT)
shared:PRIMARY>
oplog的大小是2003m 其中持有数据时间为20秒
可以在启动mongod的时候指定 oplogsize
./bin/mongod --fork --dbpath data/rs0-0/
--logpath log/rs0-0/rs0-0.log --rest --replSet rs0 --oplogSize 500 --port 37017
在现有的副本集中修改oplog的大小是相当麻烦的而且影响副本集性能,因此我们最好是预先根据应用的情况评估好oplog的大小:如果应用程序是读多写少,那么默认的大小已经足够了。如果你的应用下面几种场景很多可能考虑需要更大的oplog:
前面已经提到MongoDB副本集中secondary节点是通过oplog来同步primary节点数据的,那具体的细节是怎么样的?在说数据如何同步之间先介绍一下replication lag,因为存在数据同步那必然存在一定程度的落后。这个问题对于整个MongoDB副本集的部署是至关重要的
shared:PRIMARY>db.printSlaveReplicationInfo();
source: 172.17.5.51:27017
syncedTo: Mon Aug 24 2015 22:38:45 GMT-0400 (EDT)
0 secs (0 hrs) behind the primary
source: 172.17.5.52:27017
syncedTo: Mon Aug 24 2015 22:38:45 GMT-0400 (EDT)
0 secs (0 hrs) behind the primary
shared:PRIMARY>
可以看出数据没有滞后
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29898569/viewspace-1782256/ ,如需转载,请注明出处,否则将追究法律责任。