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

Keepalived1.4.0 application achieves high availability of master and standby on MySQL 5.7.19

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

Share

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

This article mainly introduces the Keepalived1.4.0 application to achieve high availability of master and standby on MySQL 5.7.19. The content of the article is carefully selected and edited by the author, which is of certain pertinence and is of great significance to everyone's reference. The following is to understand with the author that Keepalived1.4.0 application can achieve high availability of master and standby on MySQL 5.7.19.

1. Basic environment

JDK 1.8_171

MySQL 5.7.19

CentOS 7.4

Keepalived 1.4.0

DB1:192.168.200.180

DB2:192.168.200.181

VIP: 192.168.200.99

2. Download and install Keepalived2.1, keepalived download address: wget http://www.keepalived.org/software/keepalived-1.4.0.tar.gz 2.2, keepalived installation

Both sets are installed in this way.

Yum install gcc gcc-c++ make openssl openssl-devel net-snmp-devel psmisc ipvsadm libnfnetlink-devel popt popt-devel popt-static openssl-devel kernel-devel libnl libnl-devel-y # installation depends on cd / usr/local/srctar-zvxf keepalived-1.4.0.tar.gz # decompress cd keepalived-1.4.0./configure-- prefix=/usr/local/keepalived-- enable-snmp # compile make & & make install # install mkdir / etc/ Keepalivedcp / usr/local/keepalived/etc/keepalived/keepalived.conf / etc/keepalived/ # copy and configure ln-s / usr/local/keepalived/sbin/keepalived / usr/sbin/keepalivedln-s / usr/local/keepalived/sbin/keepalived / sbin/keepalived2.3, Keepalived configuration

The configuration above DB1:

[root@mysql01 keepalived-1.4.0] # cp / etc/keepalived/keepalived.conf / etc/keepalived/keepalived.conf_ bak [root @ mysql01 keepalived-1.4.0] # vim / etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs {notification_email {nvidiacheng@163.com} notification_email_from nvidiacheng@163.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id Node_Master} vrrp_instance VI_1 {state BACKUP # can be configured in master and backup modes. In order to prevent brain fissure, both active and standby modes need to be set to backup mode. Master mode preempts the VIP interface ens33 # Nic name virtual_router_id 43 # VRRP group name, and the settings of the two nodes must be the same to indicate that each node belongs to the same VRRP group priority 100 # weight The primary node should be larger than the slave node unicast_src_ip 192.168.200.180 # local IP address unicast_peer {192.168.200.181 # peer IP address, this address must not be forgotten} nopreempt # cooperate with backup to prevent the primary library service from returning to normal after switching IP drifts over the advert_int 1 # Multicast message sending interval. The settings of the two nodes must be the same authentication {# set the verification information. The two nodes must be consistent with auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.200.99 # VIP address} virtual_server 192.168.200.99 3306 {delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 50 protocol TCP real_server 192.168.200.180 3306 {weight 1 Notify_down / etc/keepalived/mysql.sh TCP_CHECK {connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 3306}

Configuration above DB2

[root@mysql02 keepalived-1.4.0] # cp / etc/keepalived/keepalived.conf / etc/keepalived/keepalived.conf_ bak [root @ mysql02 keepalived-1.4.0] # vim / etc/keepalived/keepalived.conf! Configuration File for keepalived global_defs {notification_email {nvidiacheng@163.com} notification_email_from nvidiacheng@163.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id Node_backup} vrrp_instance VI_1 {state BACKUP interface ens33 virtual_router_id 43 priority 90 unicast_src_ip 192.168.200 . 181 unicast_peer {192.168.200.180} advert_int 1 authentication {auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.200.99}} virtual_server 192.168.200.99 3306 {delay_loop 2 lb_algo Wrr lb_kind DR persistence_timeout 60 protocol TCP real_server 192.168.200.181 3306 {weight 1 notify_down / etc/keepalived/mysql.sh echo'3' > / etc/keepalived/t.log TCP_CHECK {connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 3306}

Mysql.sh script configuration content (2 sets are the same):

[root@mysql01 keepalived] # vim / etcswap keepalivedserver mysql.shangxinxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Assign executable permissions to mysql.sh

[root@mysql01 keepalived] # chmod + x mysql.sh

After all the configurations are completed, launch keepalived for testing:

Service keepalived start # start Keepalivedservice keepalived restart # restart Keepalivedservice keepalived stop # stop Keepalivedservice keepalived status # check Keepalived running status ps aux | grep keepalived # check the Keepalived process

3.3.Test Keepalived

After the Keepalived is started in both sets, check the Nic separately.

As can be seen from the figure above, the VIP address is on the primary node.

Use the Navicat tool to connect 2 nodes and VIP nodes respectively

At this time, we stop the MySQL of node 1 and simulate the database failure of the primary node to test whether the VIP will drift to the standby node.

As shown in the figure above, after the primary node MySQL stops, the Keepalived process ends and the VIP address is missing.

Check the Nic of the backup node and find that VIP has drifted over.

Open VIP with Navicat, you can access it normally, but the master node cannot be opened.

Restart the MySQL service and Keepalived service of the primary node and stop testing on the standby node (skip)

After reading the above about the high availability of Keepalived1.4.0 applications on MySQL 5.7.19, many readers must have some understanding. If you need more industry knowledge and information, you can continue to follow our industry information column.

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