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

Example Analysis of MySQL5.7+MHA+Keepalived High availability configuration

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

Share

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

This article mainly introduces the example analysis of MySQL5.7+MHA+Keepalived high availability configuration, which has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article.

Database architecture: one master and two slaves

Master:192.168.8.57

Slave1:192.168.8.58

Slave2:192.168.8.59

Manager:192.168.8.60

MHA Toolkit:

Mha4mysql-manager-0.58.tar.gz

Mha4mysql-node-0.58.tar.gz

Keepalived-1.4.5.tar.gz

1. Master-slave replication environment and MHA installation are as follows

Http://blog.itpub.net/30135314/viewspace-2217566/

2. Configure MHA related files

Master_ip_failover

My $vip = '192.168.8.88 systemctl stop keepalived 24 minutes my $key =' 1percent investors my $ssh_start_vip = "systemctl start keepalived"; my $ssh_stop_vip = "systemctl stop keepalived"

Master_ip_online_change

My $vip = '192.168.8.88 racing 24 percent new_master_ssh_port my $key =' 1percent leading my $ssh_start_vip = "systemctl start keepalived"; my $ssh_stop_vip = "systemctl stop keepalived"; my $orig_master_ssh_port = 22 orig_master_ssh_port my $new_master_ssh_port = 22 orig_master_ssh_port my $ssh_user = "root"; my $new_master_password='mysql';my $orig_master_password='mysql'

Add non-native IP binding support

Echo "net.ipv4.ip_nonlocal_bind=1" > > / etc/sysctl.confsysctl-p

4. Install and configure keepalived

Mount / dev/cdrom / mntyum install kernel-devel openssl-devel popt-devel-ytar zxvf keepalived-1.4.5.tar.gzcd keepalived-1.4.5./configure-- prefix=/usr/local/keepalived/make & & make install

Set keepalived to boot automatically

Systemctl enable keepalived

Configure keepalived

192.168.8.57

Mkdir / etc/keepalived# vi / etc/keepalived/keepalived.conf! Configuration file for keepalivedglobal_defs {notification_email {zdd5503@163.com} router_id 8.57notification_email_from zdd5503@163.comsmtp_server stmp.163.comsmtp_connect_timeout 30} vrrp_instance v_mysql {state BACKUPinterface enp0s3virtual_router_id 200priority 100advert_int 1nopreemptauthentication {auth_type PASSauth_pass mysql} virtual_ipaddress {192.168.8.88/24}} virtual_server 192.168.8.57 3306 {delay_loop 2lb_algo wrrlb_kind DRpersistence_timeout 60protocol TCPreal_server 192.168. 8.57 3306 {weight 3notify_down / etc/keepalived/keepalived_stop.shTCP_CHECK {connect_timeout 10nb_get_retry 3delay_before_retry 3connect_port 3306}} echo "#! / bin/bash" > / etc/keepalived/keepalived_stop.shecho "pkill keepalived" > > / etc/keepalived/keepalived_stop.shchmod uplix / etc/keepalived/keepalived_stop.sh

192.168.8.58

Mkdir / etc/keepalived# vi / etc/keepalived/keepalived.conf! Configuration file for keepalivedglobal_defs {notification_email {zdd5503@163.com} router_id 8.58notification_email_from zdd5503@163.comsmtp_server stmp.163.comsmtp_connect_timeout 30} vrrp_instance v_mysql {state BACKUPinterface enp0s3virtual_router_id 200priority 90advert_int 1nopreemptauthentication {auth_type PASSauth_pass mysql} virtual_ipaddress {192.168.8.88/24}} virtual_server 192.168.8.58 3306 {delay_loop 2lb_algo wrrlb_kind DRpersistence_timeout 60protocol TCPreal_server 192.168. 8.58 3306 {weight 3notify_down / etc/keepalived/keepalived_stop.shTCP_CHECK {connect_timeout 10nb_get_retry 3delay_before_retry 3connect_port 3306}} echo "#! / bin/bash" > / etc/keepalived/keepalived_stop.shecho "pkill keepalived" > > / etc/keepalived/keepalived_stop.shchmod uplix / etc/keepalived/keepalived_stop.sh

Start and view keepalived

192.168.8.57 and 192.168.8.58

Systemctl daemon-reloadsystemctl start keepalivedsystemctl enable keepalivedps-ef | grep keepalived

See the following process, that is, the startup is normal, otherwise, the startup fails

# ps-ef | grep keepalivedroot 16916 10 14:53? 00:00:00 / usr/local/keepalived/sbin/keepalived-Droot 16917 16916 0 14:53? 00:00:00 / usr/local/keepalived/sbin/keepalived-Droot 16918 16916 14:53? 00:00:00 / usr/local/keepalived/sbin/keepalived-Droot 17772 9992 0 16:17 pts/2 00:00:00 grep-- color=auto keepalived

View VIP

192.168.8.57

# ip a | grep 88 inet 192.168.88 Universe 24 scope global secondary enp0s3

192.168.8.58 I can't see 192.168.88ax 24.

Test the availability of keepalived (shut down the MHA process before testing to avoid interference caused by failover)

MySQL connection testing

It is found that the current VIP192.168.8.88 machine is 192.168.8.57.

# mysql-uroot-pmysql-h292.168.88-e "show variables like 'server_id'" mysql: [Warning] Using a password on the command line interface can be insecure.+-+-+ | Variable_name | Value | +-+ | server_id | 57 | +-+-+

Turn off keepalived testing

Shut down the keepalived process on 192.168.8.57, and VIP can no longer be found on this node

Ip a1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6:: 1/128 scope host valid_lft forever preferred_lft forever2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:4d:70:17 brd Ff:ff:ff:ff:ff:ff inet 192.168.8.58/24 brd 192.168.8.255 scope global noprefixroute enp0s3 valid_lft forever preferred_lft forever inet 192.168.8.88/24 scope global secondary enp0s3 valid_lft forever preferred_lft forever inet6 fe80::6a31:3e92:8b6f:83c0/64 scope link noprefixroute valid_lft forever preferred_lft forever inet6 fe80::5198:593b:cdc5:1f90/64 scope link tentative noprefixroute dadfailed Valid_lft forever preferred_lft forever3: virbr0: mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:f4:55:bb brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever4: virbr0-nic: mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000 link/ether 52:54:00:f4:55:bb brd ff:ff:ff:ff:ff:ff

You can see that VIP has floated to 192.168.8.58

The keepalived process on 192.168.8.57 is started, and the VIP is still on the 192.168.8.58 node.

Simulated downtime test

View VIP location

Mysql-uroot-pmysql-h292.168.88-e "show variables like 'server_id'" mysql: [Warning] Using a password on the command line interface can be insecure.+-+-+ | Variable_name | Value | +-+ | server_id | 57 | +-+-+

Shut down the 192.168.8.57 node mysql process

Mysql-uroot-pmysql-h292.168.88-e "show variables like 'server_id'" mysql: [Warning] Using a password on the command line interface can be insecure.+-+-+ | Variable_name | Value | +-+ | server_id | 58 | +-+-+

You can see that VIP has floated to the 192.168.8.58 node

7. Modify the keepalived log location

The default log is stored in the system log: / var/log/messages

Keep the log separately.

Modify vi / usr/local/keepalived/etc/sysconfig/keepalived

Modify KEEPALIVED_OPTIONS= "- D" to: KEEPALIVED_OPTIONS= "- D-d-S 0"

Vi / usr/local/keepalived/etc/sysconfig/keepalived# Options for keepalived. See `keepalived-- help' output and keepalived (8) and# keepalived.conf (5) man pages for a list of all options. Here are the most# common ones: # #-vrrp-P Only run with VRRP subsystem.#-check-C Only run with Health-checker subsystem.#-dont-release-vrrp-V Dont remove VRRP VIPs & VROUTEs on daemon stop.#-dont-release-ipvs-I Dont remove IPVS topology on daemon stop.#-dump-conf-d Dump the configuration data.#- -log-detail-D Detailed log messages.#-- log-facility-S 0-7 Set local syslog facility (default=LOG_DAEMON) # KEEPALIVED_OPTIONS= "- D-d-S 0"

Add at the end of / etc/rsyslog.conf

Vi / etc/rsyslog.conflocal0.*/var/log/keepalived.log

RHEL6:

/ etc/init.d/rsyslog restart

/ etc/init.d/keepalived restart

RHEL7:

Systemctl restart rsyslog

Systemctl restart keepalived

View keepalived Log

# tail-100f / var/log/keepalived.log Oct 27 17:07:25 master Keepalived_vrrp [22697]:-

< Global definitions >

-Oct 27 17:07:25 master Keepalived_vrrp [22697]: Router ID = 8.57Oct 27 17:07:25 master Keepalived_vrrp [22697]: Smtp server connection timeout = 30Oct 27 17:07:25 master Keepalived_vrrp [22697]: Email notification from = zdd5503@163.comOct 27 17:07:25 master Keepalived_vrrp [22697]: Email notification = zdd5503@163.comOct 27 17:07:25 master Keepalived_vrrp [22697]: Default interface = eth0Oct 27 17:07:25 master Keepalived_vrrp [22697]: LVS flush = falseOct 27 17:07:25 master Keepalived_vrrp [22697]: VRRP IPv4 mcast group = 224.0.0.18Oct 27 17:07:25 master Keepalived_vrrp [22697]: VRRP IPv6 mcast group = ff02::12Oct 27 17:07:25 master Keepalived_vrrp [22697]: Gratuitous ARP delay = 5Oct 27 17:07:25 master Keepalived_vrrp [22697]: Gratuitous ARP repeat = 5Oct 27 17:07:25 master Keepalived_vrrp [22697]: Gratuitous ARP refresh timer = 0Oct 27 17:07: 25 master Keepalived_vrrp [22697]: Gratuitous ARP refresh repeat = 1Oct 27 17:07:25 master Keepalived_vrrp [22697]: Gratuitous ARP lower priority delay = 5Oct 27 17:07:25 master Keepalived_vrrp [22697]: Gratuitous ARP lower priority repeat = 5Oct 27 17:07:25 master Keepalived_vrrp [22697]: Send advert after receive lower priority advert = trueOct 27 17:07:25 master Keepalived_vrrp [22697]: Send advert after receive higher priority advert = falseOct 27 17:07:25 master Keepalived_vrrp [22697]: Gratuitous ARP interval = 0Oct 27 17:07:25 master Keepalived_vrrp [22697]: Gratuitous NA interval = 0Oct 27 17:07:25 master Keepalived_vrrp [22697]: VRRP default protocol version = 2Oct 27 17:07:25 master Keepalived_vrrp [22697]: Iptables input chain = INPUTOct 27 17:07:25 master Keepalived_vrrp [22697]: VRRP check unicast_src = false

You can see that the log has been output and the location has changed.

Thank you for reading this article carefully. I hope the article "sample Analysis of MySQL5.7+MHA+Keepalived High availability configuration" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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