1. MySQL master-slave configuration
Link>> https://blog.csdn.net/m0_46674735/article/details/109597636
2.keepalived configuration
2.1 Introduction to keepalived
- Keepalived is a free, open source, highly available software written in C language!
- It is based on the VRRP (Virtual Routing Redundancy) protocol to achieve high availability!
- In the beginning, it was mainly for the management of lvs load balancing and internal node monitoring! Later, if VRRP functions, we will use it and some other software, such as MySQL, Nginx, Haproxy, etc. to combine to achieve high availability clusters!
- The software is mature, stable, and has a very good performance in many scenarios!
2.2 Keepalived realizes high availability principle
- The nodes in the keepalived cluster have two states: MASTER and BACKUP
- MASTER will periodically send broadcast packets to all BACKUPs in the cluster through arp! BACKUP can receive the broadcast, indicating that the MASTER is working properly! If the BACKUP does not receive the broadcast of the MASTER over time, a new MASTER will be elected from all the BACKUPs to continue working! Ensure that there is always a MASTER working in the cluster to achieve high availability!
2.3 KeepAlived and MySQL association
- Keepalived will configure a virtual server after startup, and the virtual server will have a VIP address
- Our application connects to the database through VIP, and the virtual server will forward it to the internal real MySQL server after receiving the access request!
- In the Keepalived cluster, the MASTER host will have a VIP address, and the BACKUP host will not have a VIP address! Only when the BACKUP host state changes to the MASTER state will it have a VIP address
- So as long as there is a MASTER host in the cluster, there will be a VIP address! Then our application can find MySQL through VIP
2.4 Preemption mode configuration
2.4.1 Install keepalived software on both Server1 and Server2
2.4.2 Modify the keepalived configuration file of Server1 and start the keepalived service after modification
! If the IP address fails to drift, change "service keepalived stop"
to "pkill keepalived"
2.4.3 Modify the keepalived configuration file of Server2, and start the keepalived service after modification
2.4.4 Verify the result on Server1:
2.4.5 View the verification result on the log on Server2:
2.4.6 Stop the MySQL service on Server1:
2.4.7 Check that the active/standby switchover is successful on Server2
2.4.8 Start MySQL and keepalived services on Server1
2.4.9 Check the success of preemption on Server1
2.5 Non-preemptive mode configuration
Only one line of parameters is required in the configuration file, and the other parts are the same as the preemption mode