共计 3052 个字符,预计需要花费 8 分钟才能阅读完成。
如果是集群分片环境建议使用官方方法: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 相关教程见以下内容:
CentOS 编译安装 MongoDB 与 mongoDB 的 php 扩展 http://www.linuxidc.com/Linux/2012-02/53833.htm
CentOS 6 使用 yum 安装 MongoDB 及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htm
Ubuntu 13.04 下安装 MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htm
MongoDB 入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htm
Ubunu 14.04 下 MongoDB 的安装指南 http://www.linuxidc.com/Linux/2014-08/105364.htm
《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htm
Nagios 监控 MongoDB 分片集群服务实战 http://www.linuxidc.com/Linux/2014-10/107826.htm
基于 CentOS 6.5 操作系统搭建 MongoDB 服务 http://www.linuxidc.com/Linux/2014-11/108900.htm
MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141503.htm