Getting error while converting Replica set into Sharded cluster

Hi All,

I am doing practice to convert replica set into sharded cluster.

I have 3 node replica set.
Steps i followed till yet:

  1. Shutdown mongod process in all 3 nodes.
    2.Create a directory for config server setup in all 3 nodes
    mkdir -p /database/data/mongodb/configsvr1
    mkdir -p /database/data/mongodb/configsvr2
    mkdir -p /database/data/mongodb/configsvr3
    3.Started mongod process using below command.
    sudo mongod --configsvr --replSet configReplSet --dbpath “/database/data/mongodb/configsvr1” --logpath “/database/data/mongodb/configsvr1/configsvr1.log” --port 27020 --fork

sudo mongod --configsvr --replSet configReplSet --dbpath “/database/data/mongodb/configsvr2” --logpath “/database/data/mongodb/configsvr2/configsvr2.log” --port 27020 --fork

sudo mongod --configsvr --replSet configReplSet --dbpath “/database/data/mongodb/configsvr3” --logpath “/database/data/mongodb/configsvr3/configsvr3.log” --port 27020 --fork

  1. logged into mongo shell
    mongo --port 27020

After that while trying to initiate “configReplica set”, its throwing an error.
rs.initiate({
_id : “configReplSet”,
configsvr : true,
members: [
{ _id : 0, host: “xyz1a:27020” },
{ _id : 1, host: “xyz2a:27020” },
{ _id : 2, host: “xyz3a:27020” }
]
})

Error:

    "ok" : 0,
    "errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: xyz2a:27020 failed with Error connecting to xyz2a:27020 (XX.XX.X.XX:27020) :: caused by :: Connection refused, xyz3a:27020 failed with Error connecting to xyz3a:27020 (XX.XX.X.XX:27020) :: caused by :: Connection refused",
    "code" : 74,
    "codeName" : "NodeNotFound",
    "$gleStats" : {
            "lastOpTime" : Timestamp(0, 0),
            "electionId" : ObjectId("000000000000000000000000")
    },
    "lastCommittedOpTime" : Timestamp(0, 0),
    "$clusterTime" : {
            "clusterTime" : Timestamp(0, 0),
            "signature" : {
                    "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                    "keyId" : NumberLong(0)
            }
    }

}

Could you please help me out on this. Am not sure what mistake i did here.

Upon checking log,found below error.

2022-06-29T10:51:55.588+0100 I SHARDING [shard-registry-reload] Periodic reload of shard registry failed :: caused by :: NotYetInitialized: could not get updated shard list from config server :: caused by :: Cannot use non-local read concern until replica set is finished initializing.; will retry after 30s

Why sudo while starting mongod?
Are you not using IDE?
Did configserver node2 &3 start?
Check the mongod.logs
How can you run 3 mongods on same port?

“errmsg” : “replSetInitiate quorum check failed because not all proposed set members responded affirmatively: xyz2a:27020 failed with Error connecting to xyz2a:27020 (XX.XX.X.XX:27020) :: caused by :: Connection refused, xyz3a:27020 failed with Error connecting to xyz3a:27020 (XX.XX.X.XX:27020) :: caused by :: Connection refused”

This implies that xyz2a can’t communicate with xyz3a (either it isn’t started or something is blocking the connection). If these are on the same VM / server than you will definitely need to start them with different port numbers (as someone else mentioned). You can see if the mongod processes are running by doing ps -ax | grep mongo. If these are seperate VMs I would check if there are any firewalls blocking the connections by doing a telnet between the two servers. telnet xyz3a 27020.

Why sudo while starting mongod?- I need to run as root
Are you not using IDE?- No
Did configserver node2 &3 start?- Yes
How can you run 3 mongods on same port? - Its 3 virtual redhat servers