MongoDB主從模式修改主庫的oplogsize

靜以致遠√團團發表於2017-02-24
如果是叢集分片環境建議使用官方方法:
這裡環境是傳統的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)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29320885/viewspace-2134234/,如需轉載,請註明出處,否則將追究法律責任。

相關文章