大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
MongoDB主从模式如何修改主库的oplogsize,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
公司主营业务:成都网站设计、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出南开免费做网站回馈大家。
如果是集群分片环境建议使用官方方法:
https://docs.mongodb.com/v3.0/tutorial/change-oplog-size/
这里环境是传统的master/slave,并没有使用replicate set,而且后期版本mongodb将废弃m/s,如果是单实例或者传统m/s的结构,修改oplogsize只需删除local库即可,操作记录如下:
先关闭master和auth功能
[root@fogtestdb data]# vi /etc/mongodb.cnf
dbpath = /mongodb/data
logpath = /var/log/mongodb/mongodb.log
pidfilepath = /var/run/mongodb/mongodb.pid
logappend = true
port = 27017
fork = true
#master = true
maxConns=2048
noprealloc = true
httpinterface = true
oplogSize=1024
#auth=true
#keyFile = /etc/mongo.key
重启mogodb
[root@fogtestdb data]# mongod -f /etc/mongodb.cnf --shutdown
note: noprealloc may hurt performance in many applications
killing process with pid: 4749
[root@fogtestdb data]# mongod -f /etc/mongodb.cnf &
删除local库
[root@mongodb ~] # mongo
> use local
> db.dropDatabase()
修改oplogsize大小并启动mongodb
[root@fogtestdb data]# vi /etc/mongodb.cnf
dbpath = /mongodb/data
logpath = /var/log/mongodb/mongodb.log
pidfilepath = /var/run/mongodb/mongodb.pid
logappend = true
port = 27017
fork = true
master = true
maxConns=2048
noprealloc = true
httpinterface = true
oplogSize=20480
auth=true
keyFile = /etc/mongo.key
重启mongodb
[root@fogtestdb data]# mongod -f /etc/mongodb.cnf --shutdown
[root@fogtestdb data]# mongod -f /etc/mongodb.cnf &
[1] 4802
[root@fogtestdb data]# note: noprealloc may hurt performance in many applications
about to fork child process, waiting until server is ready for connections.
forked process: 4804
child process started successfully, parent exiting
[1]+ Done mongod -f /etc/mongodb.cnf
登入查看oplogsize
[root@fogtestdb data]# mongo 127.0.0.1:27017/admin -uroot -ptest
MongoDB shell version: 3.2.0
connecting to: 127.0.0.1:27017/admin
Server has startup warnings:
2017-02-22T14:52:04.246+0800 I CONTROL [initandlisten]
2017-02-22T14:52:04.246+0800 I CONTROL [initandlisten] ** WARNING: The server is started with the web server interface and access control.
2017-02-22T14:52:04.246+0800 I CONTROL [initandlisten] ** The web interfaces (rest, httpinterface and/or jsonp) are insecure
2017-02-22T14:52:04.246+0800 I CONTROL [initandlisten] ** and should be disabled unless required for backward compatibility.
2017-02-22T14:52:04.246+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-02-22T14:52:04.246+0800 I CONTROL [initandlisten]
>
查看oplog大小
> db.printReplicationInfo()
configured oplog size: 20480MB
log length start to end: 624021secs (173.34hrs)
oplog first event time: Fri Feb 10 2017 10:24:16 GMT+0800 (CST)
oplog last event time: Fri Feb 17 2017 15:44:37 GMT+0800 (CST)
now: Fri Feb 17 2017 15:44:47 GMT+0800 (CST)
看完上述内容,你们掌握MongoDB主从模式如何修改主库的oplogsize的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!