Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 2.48 KB

enable-oplog.md

File metadata and controls

65 lines (52 loc) · 2.48 KB

Enable OpLog

For more info see original article.

Before you go:

Definitions:

  • oplogger user - User with read access to local database, where is OpLog is stored
  • oplogger role - Role which grants read access to local database
  • <password> - placeholder, should be changed to strong password. Always placed in double quotes

1. In Mongo Shell on PRIMARY: Create oplogger role:

# Mongo Shell:
use admin
db.runCommand({createRole:"oplogger", privileges:[{resource: {db:"local", collection:"system.replset"}, actions: ["find"]}], roles:[{role:"read", db:"local"}]})

2. In Mongo Shell on PRIMARY: Create oplogger user and grant oplogger role:

// 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"]})

3. In Mongo Shell on PRIMARY: Make sure user is properly created:

# Mongo Shell:
use admin
show users

4. Limit OpLog size:

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.

5. Connection string:

mongodb://oplogger:<password>@<SRV_1>:<PORT>,<SRV_2>:<PORT>,<SRV_3>:<PORT>/local?authSource=admin&replicaSet=rs0