0

I know Mongodb suggest the replication set minimum is 3

Can I use two servers to install Mongodb with 4 replication sets in order to prevent Write failure when one node down?

My idea is to install two more instances on each server to fake/get rid of it:

  • Mongodb 1

    • Replcation set 1 (Master)
    • Replcation set 2 (Secondary)
  • Mongodb 2

    • Replcation set 3 (Secondary)
    • Replcation set 4 (Arbiter)

If one server down, it still has two replication sets for it.

Can anyone can comment my idea? I would like to know is there any issue/risk needed to consider? Thanks!

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
Sury.C
  • 71
  • 11

3 Answers3

2

This is a bad idea. Your suggested configuration would be counter-productive for two main reasons:

  1. Running two instances of MongoDB on the same hosts will lead to them both running slowly and awkwardly, competing for memory, cpu, disk i/o, etc.
  2. If one of the hosts goes down, the two nodes on the other will not be able to continue the replica set because with only two nodes running out of four, you don't have the majority necessary to become primary.

MongoDB is intended to be run effectively on multiple hosts, so it is designed for that; even if you could find a way to shoe-horn a functioning replica set onto only two hosts, you would be working against MongoDB's design and struggling to make it work effectively.

Really, your best option is to run a single mongod instance on each of your two hosts, and to run an arbiter on a third (separate) host; that kind of normal 3-host configuration is an effective and straightforward way of achieving both data replication and high availability.

Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
  • 1) Performance is not an issue for it. 2) I am thinking to add up 6 nodes and 3 nodes in each side – Sury.C May 18 '17 at 06:23
  • OK, I see your point from the URL https://docs.mongodb.com/manual/core/replica-set-architectures/ Even if how I try to produce the number of node is both servers, the Fault Tolerance number cannot be a half of members total. (That's mean if I shutdown one of the server, it doesn't have enough majority to elect a new primary). Thanks – Sury.C May 18 '17 at 06:30
1

Please read https://docs.mongodb.com/manual/replication/

Even number of members in a set is not recommended. The only reason to add an Arbiter is to resolve this issue and increase number of members by 1 to make it odd. It makes no sense to add 2 Arbiters at all.

Similarly there is no point to put an Arbiter to the same server with any other member. It is quite lightweight, so you can co-locate it with an application server for example.

Having 2 db servers the best replica set configuration would be:

  • Mongodb 1

    • Master
  • Mongodb 2

    • Secondary
  • Any other server

    • Arbiter
Alex Blex
  • 34,704
  • 7
  • 48
  • 75
  • I am not going to add 2 arbiters in it. just one arbiter – Sury.C May 17 '17 at 10:49
  • And I want to deploy two nodes only MongoDB with failover support. This idea comes up and it seems resolve the issue (Single Mongodb instance will become Readonly) – Sury.C May 17 '17 at 10:51
  • 1
    I must get the question wrong, but I read it as you are trying to create a replica set with 4 members, one of which is an arbiter co-located with a secondary, which is wrong. Number of members should be odd. – Alex Blex May 17 '17 at 10:54
0

Simple answer is, no you cannot do it..

Reason is "majority". If you loose one server of those two, you don't have majority of votes online.

This is reason, why 3 is minimum. It can be 3 data bearing nodes or 2 data bearing nodes and one arbiter. All of those have one vote and if you loose one of those, replica set still have 2/3 votes what is majority. Like 3/5 or 4/7.

Values 1/2 (or 2/4) are not majority.

JJussi
  • 1,540
  • 12
  • 12