K
K
Konstantin Rudenkov2013-11-06 14:10:16
MongoDB
Konstantin Rudenkov, 2013-11-06 14:10:16

Return mongodb primary to its place

Hello.

I immediately warn you that I did not manage to google the solution. And writing it yourself is a little “expensive”, because JS is hard. :)

I have a replica-set cluster of N mongodb machines on Hetzner. From time to time, hetzner's machines crash, and accordingly, the arbitrators transfer primary to another server, and then they don’t return it back (or I don’t know how to do it ...).

My question is: does anyone have a home script template for mongo in their bins, which can ... well, let's say, by cron, check who is primary, and if you need to return primary back, how will the server become available?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
subvillion, 2013-11-06
@rudenkovk

There is no need for crutches in the form of a crown, there are node priorities and they need to be set, without priorities all nodes are equivalent and the arbitrator does not return the master to the desired master after the resumption of his work.
On the current master, you need to run:

cfg = rs.conf()
cfg.members[0].priority = 2.5
cfg.members[1].priority = 1
cfg.members[2].priority = 1
rs.reconfig(cfg, { force: true } )

Where members[0]… [2] is the number of the node in the replicaset, the higher the priority value, the more “priority” the server is.

K
Konstantin Rudenkov, 2013-11-06
@rudenkovk

“On the current master, you need to execute:” - I can read the documentation.
The current master has fallen, the master has moved. I came in the morning, found the current master, performed the procedure on it and slept again until a new fall. This is what I want to automate.

K
Konstantin Rudenkov, 2013-11-06
@rudenkovk

It's clear, details. I'm not talking about that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question