MySQL 5.7 cluster configuration steps

MySQL 5.7 cluster configuration steps

The MySQL version targeted this time is 5.7. First, install MySQL on server A and server B respectively. You can install it through yum or download it through wget and compile and install it directly. There are many ways to install it, but you must ensure that it is successful.

1. Modify the my.cnf file of server A

vim /etc/my.cnf

And add the following content:

server-id=1
auto_increment_offset=1
auto_increment_increment=2
gtid_mode=on
enforce_gtid_consistency=on
log-bin=mysql-bin

2. Modify the my.cnf file of server B

vim /etc/my.cnf

And add the following content:

server-id=2
auto_increment_offset=1
auto_increment_increment=2
gtid_mode=on
enforce_gtid_consistency=on
log-bin=mysql-bin

3. Create a replication user on MySQL server A for access by server B

create user B@'IP' identified by 'password';
grant replication slave on *.* to B@'server IP';

4. Create a replication user for access from server A in MySQL on server B

create user A@'IP' identified by 'password';
grant replication slave on *.* to A@'password';

5. Execute the master-slave configuration on MySQL on server B, and make A the master and B the slave

change master to master_host='IP', master_user='B', master_password='?Tp&clsr38i', master_port=3306, master_auto_position=1;

start slave;

show slave status;

6. Execute the master-slave configuration on MySQL on server A, and make B the master and A the slave

change master to master_host='IP', master_user='A', master_password='?Tp&clsr38i', master_port=3306, master_auto_position=1;

start slave;

show slave status;

Then test, create a new database and corresponding data table in MySQL on server A, and MySQL on server B will be synchronized to ensure that the database and data table are consistent.

7. Nginx Configuration

Nginx configures the MySQL cluster access URL to ensure that microservice applications connect to the same URL.
The MySQL configuration in Nginx is as follows:

stream {
  upstream mysql_proxy{
    hash $remote_addr consistent;
    server A server IP:3306 weight=1 max_fails=3 fail_timeout=10s;
	  server B server IP:3306 weight=1 max_fails=3 fail_timeout=10s;
  }
  server {
    listen 3306; # Database server listening port proxy_connect_timeout 10s;
    proxy_timeout 300s; 
    proxy_pass mysql_proxy;
  }
}

Special Note:

It is not recommended to set the MySQL port to 3306 or 3389 in a production environment.

The above are the details of the steps for configuring a MySQL 5.7 cluster. For more information about MySQL cluster configuration, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to build a MySQL PXC cluster
  • MySQL high availability cluster deployment and failover implementation
  • Implementation of Docker deployment of MySQL cluster
  • Detailed steps for installing MySQL using cluster rpm
  • Detailed explanation of MySQL cluster: one master and multiple slaves architecture implementation
  • How to deploy MySQL 5.7 & 8.0 master-slave cluster using Docker
  • Detailed explanation of galera-cluster deployment in cluster mode of MySQL
  • Example of how to build a Mysql cluster with docker
  • MySQL Cluster Basic Deployment Tutorial
  • How to build a MySQL high-availability and high-performance cluster

<<:  Application of Beautiful Style Sheets in XHTML+CSS Web Page Creation

>>:  Implementation of vertical centering with unknown height in CSS

Recommend

Several common ways to deploy Tomcat projects [tested]

1 / Copy the web project files directly to the we...

The implementation process of ECharts multi-chart linkage function

When there is a lot of data to be displayed, the ...

How to implement import and export mysql database commands under linux

1. Export the database using the mysqldump comman...

Examples of using html unordered list tags and ordered list tags

1. Upper and lower list tags: <dl>..</dl...

MySQL database basic syntax and operation

MySQL database basic syntax DDL Operations Create...

Solution for Vue routing this.route.push jump page not refreshing

Vue routing this.route.push jump page does not re...

What is ssh port forwarding? What's the use?

Table of contents Preface 1. Local port forwardin...

Color matching techniques and effect display for beauty and styling websites

Color is one of the most important elements for a...

Solution to MySql service disappearance for unknown reasons

Solution to MySql service disappearance for unkno...

How to uninstall MySQL 8.0 version under Linux

1. Shut down MySQL [root@localhost /]# service my...

Docker installs Elasticsearch7.6 cluster and sets password

Starting from Elasticsearch 6.8, free users are a...

Example of pre-rendering method for Vue single page application

Table of contents Preface vue-cli 2.0 version vue...

Share 8 MySQL pitfalls that you have to mention

MySQL is easy to install, fast and has rich funct...