← Back to all articles
Blog

Enable oplog on a standalone mongodb server for synchronization between mongodb servers

First, edit /etc/mongod.conf to add replication settings in two key places.

processManagement:
  timeZoneInfo: /usr/share/zoneinfo
  fork: true
replication:
  oplogSizeMB: 1024
  replSetName: rs

The first setting runs the process in the background through fork. The second enables replication, with oplog sized at 1G.

Step two: stop and restart mongo

ps -ef | grep mongo
root      2006     1  0 08:41 ?        00:00:03 /usr/bin/mongod --config /etc/mongod.conf
kill 2006
/usr/bin/mongod --config /etc/mongod.conf

Run the commands in order. If ps reports process ID 2006, use kill 2006.

Step three: enable rs and oplog in the mongo shell

mongo
use admin
db.auth('admin','admin')
1
rs.initiate()

Authentication is enabled in my settings, with admin credentials admin,admin and root permissions. Thus db.auth(‘admin’,’admin’) authenticates. Finally run rs.initiate() to initialize successfully.

Step four: verify

rs:PRIMARY>

If the mongo shell displays this prompt, initialization succeeded.