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

Detailed explanation of primary keys and transactions in MySQL

Table of contents 1. Comments on MySQL primary ke...

View the dependent libraries of so or executable programs under linux

View the dependent libraries of so or executable ...

WeChat applet implements the Record function

This article shares the specific code for the WeC...

How to use React slots

Table of contents need Core Idea Two ways to impl...

display:grid in CSS3, an introduction to grid layout

1. Grid layout (grid): It divides the web page in...

SSH port forwarding to achieve intranet penetration

The machines in our LAN can access the external n...

Explore VMware ESXI CLI common commands

Table of contents 【Common commands】 [Summary of c...

Introduction to the usage of common XHTML tags

There are many tags in XHTML, but only a few are ...

Detailed explanation of mysql download and installation process

1: Download MySql Official website download addre...

How to install ZSH terminal in CentOS 7.x

1. Install basic components First, execute the yu...

How to install nginx in centos7

Install the required environment 1. gcc installat...

Solve the problem of secure_file_priv null

Add secure_file_priv = ' '; then run cmd ...