3

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  [initandlisten] **          We suggest launching mongod like this to avoid performance problems:
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] **              numactl --interleave=all mongod [other options]
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] 
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] 
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-08-13T21:19:05.690+0900 I CONTROL  [initandlisten] 
2017-08-13T21:19:05.912+0900 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2017-08-13T21:19:05.915+0900 I REPL     [initandlisten] Did not find local voted for document at startup.
2017-08-13T21:19:05.915+0900 I REPL     [initandlisten] Did not find local replica set configuration document at startup;  NoMatchingDocument: Did not find replica set configuration document in local.system.replset
2017-08-13T21:19:05.916+0900 I NETWORK  [thread1] waiting for connections on port 27117

1 Answer 1

2

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

4
  • Thanks. According to the log the replSet config is being passed in but I still get the same error when running rs.initiate() Commented Aug 13, 2017 at 12:24
  • That is strange, because your log file say "Did not find replica set configuration document in local.system.replset" what means that mongod was started as replica set, but has not initialized. Are you really sure that you have connected to right instance? Meaning mongo --port 27117 where your mongod is currently. (and not default 27017) So, you don't have two instances running. pgrep mongod should list only one process.
    – JJussi
    Commented Aug 13, 2017 at 13:58
  • There is only one instance of mongod running. But I found the problem thanks to your suggestion. Although running the mongo client without specifying a port will result in the client checking mongos.conf for the non-standard port number and connecting correctly. It turns out that the rs.initiate() still thinks it is on the standard port, so running the client like so mongo --port 27117 resolved the problem. If you update your answer with the solution I'll happily mark it as the answer :-) Commented Aug 14, 2017 at 0:57
  • @user3188040 edit my answer
    – JJussi
    Commented Aug 14, 2017 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.