In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Mysql + keepalive high availability build
System environment: centos6.8
Ip:192.168.137.36 main library
192.168.137.38 slave library
VIP (Virtual ip/ floating ip): 192.168.137.100
Software version: mysql 5.7.20
Keepalived 1.2.13
Master-slave building strategy
Mysql1
Vim / etc/my.cnf
Binlog-do-db=test
Log-bin=mysql-bin
Server-id=1
Gtid-mode=ON
Enforce-gtid-consistency
Mysql2
Vim / etc/my.cnf
Gtid-mode=ON
Enforce-gtid-consistency
Log-bin=mysql-bin
Log-slave-updates=ON
Server-id=3
Binlog-do-db=test
Install keepalived
Yum install keepalived
Modify the configuration file of keepalived in 192.168.137.36 main library
Note: the color part is the modified part.
[root@zabbix ~] # cat / etc/keepalived/keepalived.conf
! Configuration File for keepalived
Global_defs {
Notification_email {
Root@localhost
}
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}
# VIP1
Vrrp_instance VI_1 {
State BACKUP
Interface eth0
Lvs_sync_daemon_inteface eth0
Virtual_router_id 151
Priority 100
Advert_int 5
Nopreempt
Authentication {
Auth_type PASS
Auth_pass 2222
}
Virtual_ipaddress {
192.168.137.100
}
}
Virtual_server 192.168.137.100 3306 {
Delay_loop 6
Lb_algo wrr
Lb_kind DR
Persistence_timeout 60
Protocol TCP
Real_server 192.168.137.36 3306 {
Weight 100
Notify_down / data/sh/mysql.sh
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 3306
}
}
}
Save exit
Modify the configuration file of keepalived from the library at 192.168.137.38
[root@localhost sh] # cat / etc/keepalived/keepalived.conf
! Configuration File for keepalived
Global_defs {
Notification_email {
Root@localhost
}
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}
# VIP1
Vrrp_instance VI_1 {
State BACKUP
Interface eth0
Lvs_sync_daemon_inteface eth0
Virtual_router_id 151
Priority 98
Advert_int 5
Nopreempt
Authentication {
Auth_type PASS
Auth_pass 2222
}
Virtual_ipaddress {
192.168.137.100
}
}
Virtual_server 192.168.137.100 3306 {
Delay_loop 6
Lb_algo wrr
Lb_kind DR
Persistence_timeout 60
Protocol TCP
Real_server 192.168.137.38 3306 {
Weight 98
Notify_down / data/sh/mysql.sh
TCP_CHECK {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 3306
}
}
}
Save exit
The configuration above is simple:
State BACKUP means standby mode, nopreempt is not preemptive, both sides are allocated as standby mode, and both sides are not preemptive, so the problem of "brain fissure" can be avoided. Priority 100is the weight, the higher the number, the higher the weight. When both sides are configured in BACKUP mode and nopreempt is configured, keepalived relies on this number to determine who is the master and who is the standby.
Both master and slave need to create / data/sh/mysql.sh scripts
Mkdir / data/sh
Vim / data/sh/mysql.sh adds the following:
#! / bin/bash
/ etc/init.d/keepalived stop
Chmod 755 / data/sh/mysql.sh
Modprobe ip_vs # load ip_vs module virtual IP to be used
Lsmod | grep ip_vs to check whether the ip_vs module has been loaded. If you see the following, the loading is successful:
/ etc/init.d/mysqld start # launch mysql
/ etc/init.d/keepalive start # launch keepalived
The operation on 36 is the same as on 38, except that priority 100 is changed to priority 98 in the keepalived.conf configuration file.
Real_server 192.168.137.36 changed to real_server 192.168.137.38 other unchanged.
View VIP command: ip a
At this point, the master of mysql is ready from high availability. You can test the mysql service on 36 to see if vip will drift to 38. Generally speaking, there is no problem. If there is a problem, please check your configuration, whether there are any errors in the steps, selinux, whether the firewall is off, etc.
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
Redis basic applications (1) = Overview: Redis's
© 2024 shulou.com SLNews company. All rights reserved.