Jayyrus
Jayyrus

Reputation: 13051

ReplicaSet with only 2 nodes

i've got two server with a mongo instance each.

On the first server i set mongo instance as primary and on the second mongo is secondary.

I haven't got the possibility to take another server to make it as arbiter.

How can i use mongodb with just two server?

If primary fails, secondary becomes automatically primary?

Thanks!

Upvotes: 2

Views: 2602

Answers (2)

Andrei Beziazychnyi
Andrei Beziazychnyi

Reputation: 2917

It is not a good practice to have even number of members in replica set because it leads to election problem. In order to be elected node is required to get majority of votes. If you have two members you need to get two votes, that is impossible in case at least one node is down. There are several options:

  1. add lightweight arbiter node to the first or second server to replicaSet, so you would have three members in replica set. It doesn't prevent you from recovery in case of network partition, but it is a bit better than just having two node replica set.

  2. use replica set in master-slave mode, i.e. without automatic recovery, you could achive it by setting votes:2 for primary. If primary is down, you need to reconfigure replica set and set votes:2 for secondary, then secondary would be elected as primary. So you would have option for manual recovery.

Upvotes: 2

Sammaye
Sammaye

Reputation: 43884

How can i use mongodb with just two server?

If you really want to go down this road, which may I add is a very bad road then you can set your primary to have no votes, in which case the only voting member would be the secondary in the event of a failover, however, this then causes another problem. In the event of a secondary failover you cannot have a primary elected (failover of any member will trigger an election).

So even though with 2 members you can account for one failover you cannot account for both equally.

Upvotes: 1

Related Questions