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

How to use KeepAlived to build MySQL High availability Environment

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

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to use KeepAlived to build a high availability environment for MySQL". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Use KeepAlived to build a highly available environment for MySQL.

First, set up the master-slave replication of MySQL

Open binlog in Master and create a replication account

Then enter the command in Slave

Change master to

Master_host='192.168.1.70'

Master_port=3306

Master_user='xx'

Master_password='xx'

Then use start slave to turn on replication.

Then compile and install KeepAlived

Enter the keepalived-1.2.12 directory

And then use the

. / configure

Make & & make install

Then edit the KeepAlived configuration file on the Master server

Vim / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Router_id HA_MySQL

}

Vrrp_instance VI_1 {

State BACKUP

Interface eth0

Virtual_router_id 51

Priority 100

Advert_int 1

Nopreempt

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

192.168.1.199

}

}

Virtual_server 192.168.1.199 3306 {

Delay_loop 2

Lb_algo wrr

Lb_kind DR

Persistence_timeout 60

Protocol TCP

Real_server 192.168.1.70 3306 {

Weight 3

Notify_down / root/shutdown.sh

TCP_CHECK {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

Connect_port 3306

}

}

}

Then edit the configuration file for Slave

Vim / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Router_id HA_MySQL

}

Vrrp_instance VI_1 {

State BACKUP

Interface eth0

Virtual_router_id 51

Priority 90

Advert_int 1

Nopreempt

Authentication {

Auth_type PASS

Auth_pass 1111

}

Virtual_ipaddress {

192.168.1.199

}

}

Virtual_server 192.168.1.199 3306 {

Delay_loop 2

Lb_algo wrr

Lb_kind DR

Persistence_timeout 60

Protocol TCP

Real_server 192.168.1.80 3306 {

Weight 3

Notify_down / root/shutdown.sh

TCP_CHECK {

Connect_timeout 10

Nb_get_retry 3

Delay_before_retry 3

Connect_port 3306

}

}

}

Among them

Priority indicates priority

Virtual_ipaddress virtual IP address (VIP)

Delay_loop checks real_server status every 2 seconds

Script executed after notify_down detects service down

Connect_timeout connection timeout

Number of nb_get_retry reconnections

Interval between delay_before_retry reconnection

Connect_port Health check Port

Shutdown.sh can consider adding email alerts.

#! / bin/bash

Pkill keepalived

Start the MySQL and KeepAlived services on both servers

Service mysql start

Service keepalived start

The server_id of Master is 1

The server_id of Slave is 2

Then connect to the MySQL of VIP, and you can see that you have connected to the Master server (server_id is 1)

If kill falls off, Master's MySQL,KeepAlived will be automatically transferred to Slave.

Execute on the Master server

Killall mysqld

Then check the server_id again.

After a brief loss of connection, the VIP,server_id on the reconnection has become 2, indicating that the VIP has pointed to the Slave

The nopreempt parameter indicates whether to continue pointing VIP to Master after Master returns to normal.

In this case, the switch will be triggered again.

The KeepAlived of the two servers will have heartbeat detection.

If Master's MySQL service is down (port 3306 is down), he will choose to kill himself.

Slave's KeepAlived detects this through a heartbeat test and takes over VIP's request.

KeepAlived still has a lot of parameters that don't understand what it means.

After Slave is upgraded to Master, the switching script for production environment should wait for all relay logs to be applied, otherwise data may be lost.

Reference:

Http://blog.csdn.net/wzy0623/article/details/38587839

This is the end of the content of "how to use KeepAlived to build a high availability environment for MySQL". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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