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.
- 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.
- 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.
-
Modify mongod.conf
replication:
replSetName: “kubic-test” -
# mongod --config /etc/mongod.conf
-
mongodb restart
# service mongod restart -
create replica set after connecting to mongo
$ mongo
> rs.initiate()