1. MySQL master-slave configuration
MySQL Server1: 192.168.153.130
MySQL Server2: 192.168.153.131
Modify the configuration file of MySQL Server1 and add the following content
[root@localhost ~]# vim /etc/my.cnf
Modify the configuration file of MySQL Server2 and add the following content
[root@localhost ~]# vim /etc/my.cnf
Enter MySQL Server1, authorize MySQL Server2, and refresh the authorization table.
View the master status of MySQL Server1 and
enter MySQL Server2, turn off the replication function of the slave server, configure the slave server, and establish a connection with the master database. Then turn on the replication function of the slave server and
check the status of the replication function of the MySQL Server2 slave service. Double Yes means success.
Enter MySQL Server2, authorize MySQL Server1, and refresh the authorization table.
View the master status of MySQL Server2
Enter MySQL Server1, turn off the replication function of the slave server, configure the slave server, establish a connection with the master database, and then turn on the replication function of the slave server.
Check the status of the replication function of the MySQL Server1 slave service. Double Yes means success.
Verification:
Create a database on Server1, which can be seen
on Server2. Create a database on Server2, which can be seen on Server1.
2.keepalived configuration
Preemption mode
Install the keepalived software on both Server1 and Server2
Modify the keepalived configuration file of Server1
Modify the keepalived configuration file
of Server2 Verify the result on Server1:
View the log on Server2 Verify the result:
Stop the MySQL service on Server1:
View the active and standby on Server2 Successfully switched
to start MySQL and keepalived services on Server1
Check the success of preemption on Server1
Non-preemptive mode
Only one line of parameters is required in the configuration file, and the other parts are the same as the preemption mode