0
votes

I am trying to create a replica set with two replicas and one arbiter. All members are launched using:

mongod --port 25670 --dbpath /data --replSet rs0

The data directory is an empty directory.

On one of the replicas I run rs.initiate but I get the error

replSetReconfig should only be run on PRIMARY, but my state is STARTUP2

I have tried waiting for a PRIMARY to be elected but even after two minutes, I see no indication that an election has taken place.

How do I force the replica set to elect a PRIMARY? Or is there a way to predict the PRIMARY?

1
you need to connect to an instance, not to the repset. Please take a look at docs.mongodb.com/manual/tutorial/deploy-replica-set It's a step-by-step guide. - Alex Blex
Not clear. I connect the client to the local instance and call rs.instantiate. I have read the guide and I believe I've followed it accurately. - Agnel Kurian
Evidently something went wrong. If you update the question with exact steps you did it might help you to get a sensible answer. The message suggests the repset is configured and performs initial sync docs.mongodb.com/manual/reference/replica-states/… - Alex Blex
Are all members in STARTUP2 state? This state suggests that the member you are trying to rs.initiate() on may already be in the process of initial sync. What specific version of MongoDB are you trying to install? What is the output of rs.status() on the member you are trying to initiate as a primary? - Stennie

1 Answers

0
votes

The only solution that I found to work consistently is as follows:

  1. Shutdown all servers.
  2. Launch the first replica server.
  3. rs.initiate the replica set with only the first server.
  4. Launch the second replica.
  5. Add it to the replica set.
  6. Finally launch and add the arbiter. For the arbiter it did not matter if I did addArb even before launching the arbiter instance.