Replica Set primary in state OTHER

Hello,

I am very new to mongodb and I want to replicate a primary and one secondary node.
The replSetName is rs0 and if I log into mongodb I see on the primary rs0:OTHER
So I have to change this into rs0:PRIMARY but anything I do went wrong and the state everytime is OTHER.

The machines are running on a rockylinux 8.4
MongoDB Version is 4.0 wiredtiger

>rs0:OTHER> rs.status()
{
        "ok" : 0,
        "errmsg" : "Our replica set config is invalid or we are not a member of it",
        "code" : 93,
        "codeName" : "InvalidReplicaSetConfig"
}

The /etc/hosts file looks on any machine like this:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.1 rocketchat1.fritz.box rocketchat1
192.168.0.2 rocketchat2.fritz.box rocketchat2
> rs0:OTHER> rs.initiate()
{
        "ok" : 0,
        "errmsg" : "already initialized",
        "code" : 23,
        "codeName" : "AlreadyInitialized"
}

Anything I have forgotten? Please tell me and I will write it here

The messages:

and

brings the following question to me.

Have you re-used the data directory of a previous replica set that had a different name?

Share your configuration file.

Have you change any host names?

Yes I have one machine running on Cent OS 8 with rocketchat on mongodb 4.0 with different hostname and different IP address. on a Proxmox VE as virtual machine.
I have dumped the machine and redumped it on another Proxmox VE server which runs in our local network.
Also I have changed the hostname and the ip address. of the host.

I do not really know how to recover from this but I here is what I would try.

This is untested. Hopefully someone will pitch in before you try to confirm or correct.

  1. shutdown mongod on the new server
  2. change the configuration file on the new server to use the same replica set name as the old one
  3. go on the old machine and rs.add() the new server
  4. start the new server, hopefully it will join the old replica set
  5. wait until you are sure that the new machine is synced, should be fast since you start with the same data files
  6. go on the new machine and rs.remove() itself (that’s where I am not too sure what will happen on the new machine) my hope is that it’s rs.status() is un-initialized
  7. shutdown the new machine
  8. change the replica set name to the new name you want
  9. restart, then rs.initiate().

ok, I see the problem, if I change the /etc/mongod.conf

net:
  port: 27017
  bindIp: 127.0.0.1

to

net:
  port: 27017
  bindIp: 192.168.0.1

but I think for a cluster it is necessary to use 192.168.0.1 instead of 127.0.0.1 or am I wrong?

The address

is never routed from one machine to the other. So yes, you cannot use it for a cluster of physically different machines.

OK, so I have to change the bindIp: to a new (routed) IP.
But then the Primary changed into state other again.

Is the replica set name on the new machine the same as the old machine?

What is the output of rs.status()?

If so, try next step, that is, rs.add() from the old machine.

At this moment I have only one machine but it’s final taget to use two server.
So I have my RocketChat master server and have to change the bindIp: to 192.168.0.1 (excample)
After this the mongo db is in replicaset OTHER and now I have to fix it.

> rs01:PRIMARY> rs.status()
{
        "set" : "rs01",
        "date" : ISODate("2021-09-15T15:08:39.692Z"),
        "myState" : 1,
        "term" : NumberLong(125),
        "syncingTo" : "",
        "syncSourceHost" : "",
        "syncSourceId" : -1,
        "heartbeatIntervalMillis" : NumberLong(2000),
        "optimes" : {
                "lastCommittedOpTime" : {
                        "ts" : Timestamp(1631718513, 1),
                        "t" : NumberLong(125)
                },
                "readConcernMajorityOpTime" : {
                        "ts" : Timestamp(1631718513, 1),
                        "t" : NumberLong(125)
                },
                "appliedOpTime" : {
                        "ts" : Timestamp(1631718513, 1),
                        "t" : NumberLong(125)
                },
                "durableOpTime" : {
                        "ts" : Timestamp(1631718513, 1),
                        "t" : NumberLong(125)
                }
        },
        "lastStableCheckpointTimestamp" : Timestamp(1631718496, 2),
        "electionCandidateMetrics" : {
                "lastElectionReason" : "electionTimeout",
                "lastElectionDate" : ISODate("2021-09-15T14:59:13.874Z"),
                "electionTerm" : NumberLong(125),
                "lastCommittedOpTimeAtElection" : {
                        "ts" : Timestamp(0, 0),
                        "t" : NumberLong(-1)
                },
                "lastSeenOpTimeAtElection" : {
                        "ts" : Timestamp(1631717200, 2),
                        "t" : NumberLong(124)
                },
                "numVotesNeeded" : 1,
                "priorityAtElection" : 1,
                "electionTimeoutMillis" : NumberLong(10000),
                "newTermStartDate" : ISODate("2021-09-15T14:59:13.969Z"),
                "wMajorityWriteAvailabilityDate" : ISODate("2021-09-15T14:59:14.148Z")
        },
        "members" : [
                {
                        "_id" : 0,
                        "name" : "127.0.0.1:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 569,
                        "optime" : {
                                "ts" : Timestamp(1631718513, 1),
                                "t" : NumberLong(125)
                        },
                        "optimeDate" : ISODate("2021-09-15T15:08:33Z"),
                        "syncingTo" : "",
                        "syncSourceHost" : "",
                        "syncSourceId" : -1,
                        "infoMessage" : "",
                        "electionTime" : Timestamp(1631717953, 1),
                        "electionDate" : ISODate("2021-09-15T14:59:13Z"),
                        "configVersion" : 1,
                        "self" : true,
                        "lastHeartbeatMessage" : ""
                }
        ],
        "ok" : 1,
        "operationTime" : Timestamp(1631718513, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1631718513, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),

Looks like you are now PRIMARY.

Yes but only if I change to bindIp: 127.0.0.1

One option.

Restart with both the lan ip and 127.0.0.1 bound, you likely want 127.0.0.1 bound for convenience.

net:
  port: 27017
  bindIp: 192.168.0.1,127.0.0.1

Then you can reconfigure the replicaset:

var c = rs.conf()
//use hostnames, you'll thank yourself later
c.members[0].host='rocketchat1:27017'
rs.reconfig(c)

Another option:

Don’t bind 127.0.0.1 and reconfigure as-is:

var c = rs.conf()
//use hostnames, you'll thank yourself later
c.members[0].host='rocketchat1:27017'
rs.reconfig(c,{force:true})

Third option:

Drop the replicaset config and start again.

  1. Start mongod without replicaset enabled.
  2. Drop the local database.
use local
db.dropDatabase()
  1. Start mongod with replicaset option enabled.
  2. Initialize the replicaset.
rs.initiate({_id:'rs01',members:[{_id:0, host:'rocketchat1:27017'}]})
3 Likes

Many thanks for ypur reply that helped me verry well.
But a new problem occured and I will post it in another thread,

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