Deploying a ReplicaSet with one node fails (NotYetInitialized Error)

Hi folks! I am having trouble with the mongoDB tutorial to create replica sets. I want to create a replicaSet with a single node (don’t ask) and I am not sure what I am doing wrong so I thought I would post. Even when I tried with tutorial with 3 replicaSet nodes it failed. (I also had someone else follow my same steps and the error was the same on their end)

My goal here is to deploy a replica set with one node. (ie no replicas) According to [the mongodb documentation](https://docs.mongodb.com/manual/administration/replica-set-deployment/ there are two tutorials that seem relevant [Deploy A Replica Set] and [Convert a Standalone to a Replica Set]. But after reading the purpose of “Convert a Standalone to a Replica Set” it seems that “Deploy A Replica Set” is more along the lines of what I need. (since I don’t already have an instance running)

Ubuntu: 20.04
MongoDB 5.0

First I create a new multipass instance so I have a clean machine

multipass launch -n replica-tutorial
multipass shell replica-tutorial

According to the documentation for Deploy A Replica Set I performed the following steps:

[Requirements]

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

[Hostnames]
I add my hostname to dns

sudo vim /etc/hosts
192.168.184.26 mongodb0.example.net

Note this ip is from the ip a command

[Connectivity]

sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 27017/tcp

[Configuration]

sudo mkdir -p /data/db
sudo chown -R mongodb:mongodb /data/db
sudo chmod -R 777 /data/db

Add the following changes to the config file

sudo vi /etc/mongod.conf
storage:
  dbPath: /data/db
….

replication:
  replSetName: "rs0"

net:
  bindIp: localhost,192.168.184.26

[Start Member of Replica Set]

mongod --replSet "rs0" --bind_ip localhost,192.168.184.26 --dbpath /data/db

Note I add * --dbpath and the ip address listed here was retrieved from the command *ip a

At this point I get an error saying:

"NotYetInitialized: Replication has not yet been configured"

But initiation doesn’t happen until after [steps 2] and [3] in the tutorial so I am not sure why it can’t start until I initialize since according to the tutorial you are supposed to start the mongod instance and then initialize. What step am I missing

You have shown config file but started mongod from command line?

From where you are getting that message.How you are saying it did not start
You have to run rs.initiate() after connecting to the node to complete the setup

Hi @Ramachandra_Tummala thanks for responding to my post :slight_smile:

I got that message from the output of mongod --replSet "rs0" --bind_ip localhost,192.168.184.26 --dbpath /data/db

When I open a new shell and get access to the node with mongo ip and then do rs.initiate() it seems to get resolved. BUT mongod seems to keep running. After some googling I saw that mongod runs as a background process so it makes sense that it doesn’t terminate. Is it just some sort of logger?

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