In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to use keepalived in postgresql to switch IP. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
There are many ways to switch IP, but we are willing to do it in a simple way. The problems involved in high availability here are two 1-host shutdown of 2 PostgreSQL service DOWN, while weird ones, such as PG service, but do not respond, are not considered.
The following solution is only suitable for the dual-machine solution (if it is three machines, you can also emulate the priority in MHA and adjust one of them not to participate in the switch)
Here, keepalived is used to switch IP. In previous issues, there is a way to automatically switch from repmgrd to master, so the rest is the switching problem of IP. Two words of reason, convenient.
I will not talk about the installation and configuration of keepalived here, but draw a diagram of the main principles.
It is the master and slave switch, and the witness here can be eliminated, mainly depends on the requirements (if you do not know, you can see the previous issues). To cut the nonsense, the following points need to be paid attention to
1 how to set the POSTGRESQL.CONF snooping address
2 what to do when the host fails and starts again
Question 1 of course, listen should be set to 0.0.0.0 instead of native IP.
Question 2 of course, you can't get back the VIP after the failed host starts. What about the new owner who works normally? what's more terrible is that there will be problems with the consistency of the data. This can not be careless, otherwise, it will not be far away from being resigned.
To deal with this problem, keepalived needs to set nopreempt to prevent the failed master. After starting again, preempt VIP, and the other two KEEPALIVED.conf should be set to the state of backup. Use priority to determine which one is the master. In addition, the gap between priority should not be set too large, otherwise you may wait for a period of time before VIP switch. Of course, it is very possible that regmgr has not yet promote slave library because VIP switch is too fast, and the program may report an error. But this is better than the following situation, for example, the main library failed and restarted, but your promote has been done, and if the VIP is not switched, the data will be inconsistent, so it is better to switch the VIP quickly, even if the promote is not finished.
Here are some configurations for KEEPALIVED
Let's just do it and see if it works.
1 there are currently 21 22 two machines, VIP 23
At present, the main library is on 22, turn off the POSTGRESQL service of 22, wait for REPMGRD to switch between master and slave, and at the same time check the service of PG through KEEPALIVED, and then switch IP.
1 normal status 21 slave library
2 off 22, 22 has been unable to connect
3 check whether the current master and slave have been switched, and whether the IP has switched
Has been switched, master-slave, 21 has become the master library, IP has also been switched later.
The advantages of doing so
The utility model has the advantages of simple construction and convenient deployment, and can meet the high availability demand of a large area.
The disadvantage of doing so
Part of the work is not rigorous, need to debug and master related skills.
The above content is how to use keepalived in postgresql to switch IP. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.