• Uncategorized
  • 0

centos7 keepalived+mysql mutual master and slave high availability cluster

Hits: 0

1. MySQL master- slave [architecture]

1.1 Experimental environment

1.1.1 Both server systems are [centos7]

1.1.2 Server ip assignment

MySQL Server1 : 192.168.153.135
MySQL Server2 : 192.168.153.136

1.1.3 Before the experiment, the server turned off the firewall and selinux

Turn off the firewall command:

systemctl stop firewalld

Close selinux command:

set force  0

1.1.4 Specific configuration: centos7 is the same as centos6

Centos7 installation database client name is: mariadb, server name is: mariadb-server

yum -y install mariadb-server mariadb

Reference link >> /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 amendments are as follows:

1) Comment out vrrp_strict on line 14 with the comment !

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

2) Configure vrrp_instance

3) Configure virtual_server

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 amendments are as follows:

1) Comment out vrrp_strict on line 14 with the comment !

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

2) Configure vrrp_instance

3) Configure virtual_server

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 Whether the VIP configuration is successful on server1

Order:ip add

3.2 Verify VIP Drift

3.2.1 Close the mysql service on server1,

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

3.2.2 Check VIP Drift Successfully on Server2

3.3 Preemptive Mode Verification

3.3.1 Restore the mysql service and keepalived service on server1

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

3.3.2 Check VIP Preemption Success

3.4 Detailed information can be tracked by log viewing

Order:tailf /var/log/messages

3.4.1 server1 enters master state

3.4.2 server2 enters backup state

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

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

And server2 is restored to the backup state

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 amendments are as follows:

Change the status of server1 to BACKUP, and add a line of parameter nopreempt
After modification, save and exit

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 amendments are as follows:

Just add another line of parameter nopreempt
to 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 settings on the 135 host are successful

4.3.2 Verify VIP Drift

Stop the mysql service on the 135 host

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

Check the drift success on the 136 host

4.3.3 Non-Preemptive Mode Verification

1) Restore the mysql service and keepalived service on the 135 host

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

2) Viewing VIP on 135 hosts will not drift back

3) Stop the mysql service VIP on host 136 and drift

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

4) Viewing VIP on 135 host will drift back again

You may also like...

Leave a Reply

Your email address will not be published.