For more info see original article.
- Read what is OpLog
- Read official MongoDB reference
- Existing ReplicaSet is required for OpLog, read how to create one: on single server or multiple (cluster) servers
oplogger
user - User withread
access tolocal
database, where is OpLog is storedoplogger
role - Role which grantsread
access tolocal
database<password>
- placeholder, should be changed to strong password. Always placed in double quotes
# Mongo Shell:
use admin
db.runCommand({createRole:"oplogger", privileges:[{resource: {db:"local", collection:"system.replset"}, actions: ["find"]}], roles:[{role:"read", db:"local"}]})
// Mongo Shell:
use admin
// For MongoDB 2.4
db.createUser({user:"oplogger", pwd:<password>, roles:[], otherDBRoles:{local:["read"]}})
// For MongoDB >= 2.6
db.createUser({user:"oplogger", pwd:<password>, roles:[{role: "read", db: "local"}]})
db.runCommand({grantRolesToUser:"oplogger", roles:["oplogger"]})
# Mongo Shell:
use admin
show users
By default OpLog will take 5% of total disk size. It's a good idea to limit it.
If your application relies on OpLog and will read/watch for changes - OpLog size should fit in RAM, we recommend to set it to 25%-50% of RAM.
In examples below we set OpLog size to 8192
MB or 8Gb.
Via /etc/mongod.conf
:
replication:
oplogSizeMB: 8192
replSetName: rs0
Via mongod
command flag:
mongod --oplogSize 8192 --config /etc/mongod.conf
Note: This won't work on existing OpLog, to change size of existing OpLog read this article.
mongodb://oplogger:<password>@<SRV_1>:<PORT>,<SRV_2>:<PORT>,<SRV_3>:<PORT>/local?authSource=admin&replicaSet=rs0