Lanyi Cloud: Centos7 deploys MySQL8+keepalived dual master hot standby high availability

The steps to deploy MySQL 8 and Keepalived on CentOS 7 to achieve dual-master hot standby high availability are as follows:

  1. Install MySQL 8:

    • Execute the following command in the terminal to install the official Yum repository of MySQL 8:

      wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
      sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
    • Install MySQL server:

      sudo yum install mysql-server
    • Configure MySQL, including setting passwords and other security settings.
    • Start the MySQL service:

      sudo systemctl start mysqld
    • Run the MySQL security script and make necessary security configurations:

      sudo mysql_secure_installation
  2. Install Keepalived:

    • Execute the following command in the terminal to install Keepalived:

      sudo yum install keepalived
    • Configure Keepalived, including virtual IP (VIP) settings and writing of monitoring scripts.
  3. Configure MySQL master-slave replication:

    • On the main MySQL server, edit the MySQL configuration file (my.cnf) and enable binary log and GTID (global transaction identification):

      server_id = 1
      log_bin = /var/lib/mysql/mysql-bin.log
      gtid_mode = ON
      enforce_gtid_consistency = ON
    • On the MySQL master server, create a user for replication and grant the appropriate permissions:

      CREATE USER 'replication_user'@'%' IDENTIFIED BY 'password';
      GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%';
      FLUSH PRIVILEGES;
    • On the MySQL master server, view and record the binary log file name and location:

      SHOW MASTER STATUS;
    • On the MySQL slave server, edit the MySQL configuration file and set the connection information and replication parameters of the master server:

      server_id = 2
      gtid_mode = ON
      enforce_gtid_consistency = ON
      log_bin = /var/lib/mysql/mysql-bin.log
      relay_log = /var/lib/mysql/mysql-relay-bin.log
    • On the MySQL slave server, start the replication process and connect to the master server:

      CHANGE MASTER TO MASTER_HOST='主服务器IP地址', MASTER_USER='replication_user', MASTER_PASSWORD='password', MASTER_AUTO_POSITION=1;
      START SLAVE;
    • Verify that master-slave replication is running properly:

      SHOW SLAVE STATUS;
  4. Configure Keepalived’s active and backup modes:

    • Edit the Keepalived configuration file (/etc/keepalived/keepalived.conf) and set the relevant configurations of the virtual IP and monitoring script.
    • Start the Keepalived service on the master server:

      sudo systemctl start keepalived
    • Start the Keepalived service on the standby server:

      sudo systemctl start keepalived

Through the above steps, you can deploy MySQL 8 and Keepalived on CentOS 7 to achieve a dual-active hot standby high-availability environment. Please note that additional configuration and adjustments may be required depending on your specific needs and environment. It is recommended to refer to the official documentation or installation guide of MySQL and Keepalived for more detailed information and guidance.

Guess you like

Origin blog.csdn.net/tiansyun/article/details/132917926