centos6 keepalived+mysql master and slave high-availability cluster

1. MySQL master-slave configuration

Link>> https://blog.csdn.net/m0_46674735/article/details/109597636

2.keepalived configuration

2.1 Introduction to keepalived

  1. Keepalived is a free, open source, highly available software written in C language!
  2. It is based on the VRRP (Virtual Routing Redundancy) protocol to achieve high availability!
  3. 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!
  4. The software is mature, stable, and has a very good performance in many scenarios!

2.2 Keepalived realizes high availability principle

  1. The nodes in the keepalived cluster have two states: MASTER and BACKUP
  2. 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!
    Insert picture description here

2.3 KeepAlived and MySQL association

  1. Keepalived will configure a virtual server after startup, and the virtual server will have a VIP address
  2. 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!
  3. 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
  4. 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
    Insert picture description here

2.4 Preemption mode configuration

2.4.1 Install keepalived software on both Server1 and Server2

Insert picture description here

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"Insert picture description hereInsert picture description here
Insert picture description here

2.4.3 Modify the keepalived configuration file of Server2, and start the keepalived service after modification

Insert picture description here
Insert picture description here

2.4.4 Verify the result on Server1:

Insert picture description here

2.4.5 View the verification result on the log on Server2:

Insert picture description here

2.4.6 Stop the MySQL service on Server1:

Insert picture description here

2.4.7 Check that the active/standby switchover is successful on Server2

Insert picture description here
Insert picture description here

2.4.8 Start MySQL and keepalived services on Server1

Insert picture description here
Insert picture description here

2.4.9 Check the success of preemption on Server1

Insert picture description here

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
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46674735/article/details/112408519