Mongodb 5.0 replica set is not created during mongodb first installation

Hi, I’m installing mongodb 5.0 community edition on Ubuntu Linux 20.04v, but I keep having problems creating replica set.

There are two phenomena related to replica set generation that we are currently experiencing.

  1. After setting up mongodb security, if you create a replica set, the phrase is generated as shown below and the replica set is not generated.

  1. After creating the replica set, proceeding with the security settings will result in an error stating that the authentication key is required. To resolve this issue, create a key and modify the key file path to security in mongod.conf, run ‘mongod —config /etc/mongod.conf’ and restart the service, but mongodb does not run.

There is only one physical server that you want to apply mongodb to. There is one node and one cluster each, and the name is the same, so only the primary is composed of a replica set.

I set the mongod.conf file as below.

mongod.conf

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
journal:
  enabled: true
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0

# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:
security:
  authorization: "enabled"
  keyFile: "/home/mongo_key/mongodb.key"
#operationProfiling:

#replication:
replication:
  replSetName: "kubic-test"

#sharding:

And I executed the following commands to create a replica set.

  1. Modify mongod.conf
    replication:
    replSetName: “kubic-test”

  2. # mongod --config /etc/mongod.conf

  3. mongodb restart
    # service mongod restart

  4. create replica set after connecting to mongo
    $ mongo
    > rs.initiate()

Remove authorization:enabled from your config file
keyfile does both internal member authentication and access control

Also why you are starting mongod with config file?
Once you edit your config file and restart the service the new params should take effect
You should have only one mongod running either manually started one or the one which is started by service

Once authorization: enabled was removed and a cluster-related role was added to the user role, a replica set was created.

To talk about the reason for running Mongod with config file, I thought I had to write service start to run Mongod. I didn’t know that mongod --config was also a method of running mongod, and I knew that I had to apply the mongod --config command to apply the conf change.