Two nodes MongoDB replica set without arbiter

前端 未结 4 1019
谎友^
谎友^ 2021-01-11 13:23

Is it possible to create a MongoDB replica set consisting of only 1 primary and 1 secondary member? I would like to have delayed replica set that will copy data from primary

相关标签:
4条回答
  • 2021-01-11 13:38

    Yes you can and all you really need to do is set the member to not be eligible for primary.

    There is documentation on how to make sure a member cannot be elected as primary here: http://docs.mongodb.org/manual/tutorial/configure-secondary-only-replica-set-member/

    0 讨论(0)
  • 2021-01-11 13:51

    Short answer: don't.

    Long answer: the way automatic failover works in MongoDB is that a replica set needs a qualified majority to successfully elect a new primary. Delayed members do have votes in elections. So if either of your nodes fails the replica set finds out that it doesn't have this majority and the current primary steps down even if it didn't fail. So what you essentially do is doubling the chances of making your replica set fail. An arbiter is a very cheap process, in term of RAM usage, CPU and even disk space when run with --smallfiles --no-journal --noprealloc or the equivalent options set in the config file. Note that the mentioned options are safe to use, since an arbiter essentially only checks the heartbeats of the data bearing nodes. You could put the arbiter on the application server for example.

    Disclaimer: the following procedure is strongly discouraged to use. Proceed at your own risk.

    You could set the votes of the delayed server to 0. This way the undelayed node will call for an election in case the delayed member fails, comes to the conclusion that it is the only node online of the replica set and that it has the majority of votes (1/1) and will continue to work as expected. This course of action needs some attention, as you will have an even number of votes again in case you add a member to the replica set later and makes it necessary to reconfigure the replica set. It also has serious implications with network fragmentation issues. Again: Use at your own risk

    0 讨论(0)
  • 2021-01-11 13:58

    In this case, the best option is add an arbiter. I tried before with votes, but on 2 nodes replicaset you can have some issues with sync.

    0 讨论(0)
  • 2021-01-11 14:02

    Yes, it is possible but not recommended. The caveat of this approach is no automatic failovers.

    If you primary goes down then you will have to manually make the other server as primary.

    If you are keeping you secondary only as a mirror of your primary and you are fine with manual failover then it should work for you.

    More info here:

    http://openmymind.net/Does-My-Replica-Set-Need-An-Arbiter/

    0 讨论(0)
提交回复
热议问题