Mongodb fails to start after adding replication in config

I am trying to set up a replica set on my Ubuntu 18.04. MongoDB version: 5.0.0
I have secured the Mongodb service using password based authentication.

When I add the replication value in /etc/mongod.conf
replication:
replSetName: “rs0”

And restart mongodb, this error shows up:

What should I do to solve this?

It says bad value security.keyfile is needed

You need keyfile for internal authentication of replicaset members

security:
authorization: enabled
keyFile: /your_path/your-keyfile
Please refer documentation on how to create a keyfile with openssl

But before this I didn’t need a keyfile for authentication.
Is it necessary to set this up in newer versions?

keyfile is a must for replication configuration
What was your setup before adding replication?
It must be a standalone DB
Please check this doc.It applies to all versions

No it wasn’t a standalone. It was a replica set with only one member.
I implemented the key file authentication from the docs but now I’m getting a new error.

In text:
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2021-07-18 23:30:06 IST; 12s ago
Docs: https://docs.mongodb.org/manual
Process: 2648 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
Main PID: 2648 (code=exited, status=1/FAILURE)

Jul 18 23:30:06 sahilnare78-HP-Laptop-15-bs1xx systemd[1]: Started MongoDB Database Server.
Jul 18 23:30:06 sahilnare78-HP-Laptop-15-bs1xx systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Jul 18 23:30:06 sahilnare78-HP-Laptop-15-bs1xx systemd[1]: mongod.service: Failed with result ‘exit-code’.

I’m not sure where this error is coming from.

Okay, so I got the solution.

I uninstalled the MongoDB version 5.0.0 and installed version 4.4.2 (which I was using previously).

So now there is no need of using key file authentication for setting up replica set.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.