HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

enable replicaSet in mongoDB yaml conf file

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
confenablefilemongodbreplicasetyaml

Problem

I want to enable oplog on mongoDB and the recommended approach is to setup a standalone replica set. I tried following the instructions here...

https://docs.mongodb.com/manual/reference/configuration-options/#replication-options

...and added the following to /etc/mongod.conf

replication:
   oplogSizeMB: 1024
   replSetName: rs0


After restarting I tried initialising and checking the the status but see the following...

> rs.initiate()
{
        "ok" : 0,
        "errmsg" : "This node was not started with the replSet option",
        "code" : 76,
        "codeName" : "NoReplicationEnabled"
}

> rs.conf()
2017-08-11T18:08:51.336+0900 E QUERY    [thread1] Error: Could not retrieve replica set config: {
        "ok" : 0,
        "errmsg" : "not running with --replSet",
        "code" : 76,
        "codeName" : "NoReplicationEnabled"
}


The error states run with the --repSet option, but if I try the following the error still appears

sudo /usr/bin/mongod --config /etc/mongod.conf --replSet rs0


Update
The config is being passed in

```
2017-08-13T21:19:03.708+0900 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=63900M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-08-13T21:19:05.688+0900 I CONTROL [initandlisten]
2017-08-13T21:19:05.689+0900 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-08-13T21:19:05.689+0900 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-08-13T21:19:05.689+0900 I CONTROL [initandlisten]
2017-08-13T21:19:05.690+0900 I CONTROL [initandlisten]
2017-08-13T21:19:05.690+0900 I CONTROL [initandlisten] ** WARNING: You are running on a NUMA machine.
2017-08-13T21:19:05.690+0900 I CONTROL [ini

Solution

Check your mongod.log file, there should be line what lists all configuration items from you /etc/mongod.conf

2017-08-12T12:44:23.999+0300 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27017 }, replication: { oplogSizeMB: 1024, replSetName: "rs0" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }


if you cannot see replication: { oplogSizeMB: 1024, replSetName: "rs0" } then it has NOT readed your current config file.

You can see what file it has readed when you look to start of that line config: "/etc/mongod.conf"

And remember, if your mongod is not running on standard 27017 port, you must adjust your commands to use the right port. Command rs.initiate() (without parameter), don't work if the port is something else than the default.

Update
If connecting to a specific port ensure you define it when using the client mongo --port 27117. For some reason the rs.initiate() command checks for a custom port based on the command line parameter and not what is defined in /etc/mongod.cof

Code Snippets

2017-08-12T12:44:23.999+0300 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27017 }, replication: { oplogSizeMB: 1024, replSetName: "rs0" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }

Context

StackExchange Database Administrators Q#183303, answer score: 2

Revisions (0)

No revisions yet.