Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Working principle and function of Keepalived dual main Hot standby for High availability of MySQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly gives you a brief introduction to the working principle and function of MySQL's high-availability Keepalived dual-master hot backup. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here. Let's go straight to the topic. I hope this article on the working principle and function of MySQL's high-availability Keepalived dual-master hot backup can bring you some practical help.

The so-called "dual hot standby" means that both machines are running, but not both machines are providing services at the same time. When one of the service providers fails, the other will automatically take over and provide service immediately, and the switching time is very short.

Keepalived works on the VRRP (Virtual Router Redundancy Protocol) virtual routing redundancy protocol. There are two important concepts in VRRP: the VRRP router and the virtual router, the master router and the backup router.

VRRP router refers to the router running VRRP, is a physical entity, virtual router refers to the creation of VRRP protocol, is a logical concept. A group of VRRP routers work together to form a virtual router. There is an election mechanism in Vrrp, which is used to select the route that provides the service, that is, the master route, and the other routes become backup routes. When the master route fails, a master route will be re-elected in the backup route to continue to work to ensure uninterrupted service.

Environment description:

OS:Ubuntu16.04

MASTER:172.16.29.205

BACKUP:172.16.29.197

VIP:172.16.29.206

[root@masterr ~] # vi / etc/keepalived/keepalived.confglobal_defs {notification_email {test@sina.com} notification_email_from admin@test.comsmtp_server 127.0.0.1smtp_connect_timeout 30router_id MYSQL_HA # logo, two masters are the same} vrrp_instance VI_1 {state BACKUP # both set BACKUP interface eth0 virtual_router_id 51 # master / standby same priority # priority Backup setting 90 advert_int 1 nopreempt # does not actively preempt resources, only in the high priority setting of master, backup does not set authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {172.16.29.206}} virtual_server 172.16.29.206 3306 {delay_loop 2 # lb_algo rr # LVS algorithm, we turn off # lb_kind DR # LVS mode, if not The standby CVM cannot connect to the primary MySQL persistence_timeout 50 # the connection of the same IP through VIP is assigned to the same real CVM within 60 seconds protocol TCP real_server 172.16.29.205 3306 {# detect the local mysql,backup also write to detect the local mysql weight 3 notify_down / etc/keepalived/mysql.sh # execute this script when mysq serves down Kill keepalived to switch TCP_CHECK {connect_timeout 3 # connection timeout nb_get_retry 3 # retry number delay_before_retry 3 # retry interval}} [root@masterr ~] # vi / usrloc localableql.shql.shroupql.shqql.bins Basido service keepalived stop [root@masterr ~] # chmod + x / usr/local/keepalived/mysql.sh [root@masterr] # / etc/init.d/keepalived start

Backup CVM only modifies priority to 90, nopreempt is not set, and real_server sets local IP.

3. Test high availability

1. Connect via VIP through the Mysql client to see if the connection is successful.

two。 You can use the ip addr command to check which CVM the VIP is on to stop the mysql service of master.

3. You can see the master / slave switching process by viewing / var/log/messges log.

After the failure of 4.master CVM is restored, whether to actively preempt resources and become active CVM.

The working principle and function of MySQL's high availability Keepalived dual-master hot backup will stop here. If you want to know about other related issues, you can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report