centos7 keepalived+mysql master and slave high-availability cluster

1. mysql mutual master and slave architecture

1.1 Experimental environment

1.1.1 Both server systems are centos7

1.1.2 Server IP distribution

MySQL Server1 : 192.168.153.135
MySQL Server2 : 192.168.153.136

1.1.3 Before the experiment, the server is closed firewall and selinux

Turn off the firewall command:

systemctl stop firewalld

Close the selinux command:

setenforce 0

1.1.4 Specific configuration: centos7 is the same as centos6

The centos7 installation database client name is: mariadb, and the server name is: mariadb-server

 yum -y install mariadb-server mariadb

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

2. Keepalived preemption mode configuration

2.1 Install keepalived software on both servers

yum -y install keepalived

2.2 Modify the keepalived configuration file on Server1

2.2.1 Modify command

vim /etc/keepalived/keepalived.conf 

2.2.2 The revised content is as follows:

1) Comment out vrrp_strict on line 14, the comment symbol is!

The meaning of the vrrp_strict parameter is:
strictly abide by the VRRP protocol. The following conditions will prevent Keepalived from starting: 1. There is no VIP address. 2. Unicast neighbors. 3. There are IPv6 addresses in VRRP version 2. Need to comment out here
Insert picture description here

2) Configure vrrp_instance

Insert picture description here

3) Configure virtual_server

Insert picture description here

2.2.3 After the modification is completed, save and exit and start the keepalived service

systemctl start keepalived

2.3 Modify the keepalived configuration file on Server1

2.3.1 Modify command

vim /etc/keepalived/keepalived.conf 

2.3.2 The revised content is as follows:

1) Comment out vrrp_strict on line 14, the comment symbol is!

The meaning of the vrrp_strict parameter is:
strictly abide by the VRRP protocol. The following conditions will prevent Keepalived from starting: 1. There is no VIP address. 2. Unicast neighbors. 3. There are IPv6 addresses in VRRP version 2. Need to comment out here
Insert picture description here

2) Configure vrrp_instance

Insert picture description here

3) Configure virtual_server

Insert picture description here

2.3.3 After the modification is completed, save and exit and start the keepalived service

systemctl start keepalived

3. Verify the configuration

3.1 Is the VIP configured successfully on server1

command:ip add
Insert picture description here

3.2 Verify VIP drift

3.2.1 Shut down the mysql service on server1,

[root@host-135 ~]# systemctl stop mariadb

3.2.2 Check VIP drift success on server2

Insert picture description here

3.3 Preemption mode verification

3.3.1 Recover mysql service and keepalived service on server1

[root@host-135 ~]# systemctl start mariadb
[root@host-135 ~]# systemctl start keepalived

3.3.2 Checking the success of VIP preemption

Insert picture description here

3.4 Detailed information can be viewed in the trace log

command:tailf /var/log/messages

3.4.1 server1 enters the master state

Insert picture description here

3.4.2 server2 enters the backup state

Insert picture description here

3.4.3 After the MySQL service on server1 is stopped, server2 preempts as master

Insert picture description here

3.4.3 After the MySQL service and keepalived service on server1 are restored, server1 is preempted as master again

Insert picture description here
And server2 is restored to backup state
Insert picture description here

4. Keepalived non-preemptive mode configuration

4.1 Modify the keepalived configuration file on Server1

4.2.1 Modify command

vim /etc/keepalived/keepalived.conf 

4.2.2 The revised content is as follows:

Modify the status of server1 to BACKUP, and add a line of parameter nopreempt to
Insert picture description here
save and exit after the modification is complete

4.2.3 Restart the keepalived service

systemctl restart keepalived

4.2 Modify the keepalived configuration file on Server2

4.2.1 Modify command

vim /etc/keepalived/keepalived.conf 

4.2.2 The revised content is as follows:

Just add another line of parameter nopreempt
Insert picture description here
and save and exit after the modification is complete

4.2.3 Restart the keepalived service

systemctl restart keepalived

4.3 Verification

4.3.1 Verify that the VIP setting on the 135 host is successful

Insert picture description here

4.3.2 Verify VIP drift

Stop the mysql service on the 135 host

[root@host-135 ~]# systemctl stop mariadb

Check drift success on 136 host

Insert picture description here

4.3.3 Non-preemptive mode verification

1) Restore mysql service and keepalived service on 135 host

[root@host-135 ~]# systemctl start mariadb keepalived

2) Viewing VIP on 135 host will not drift back

Insert picture description here

3) Stopping the mysql service on the 136 host and VIP drifting

[root@host-136 ~]# systemctl stop mariadb

4) Viewing VIP on 135 host will drift back again

Insert picture description here

Guess you like

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