Answer the question
In order to leave comments, you need to log in
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
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 } )
“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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question