Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of mysql Cluster: implementation of one Master and multiple Slave Architecture

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Experimental environment:

1. Three CentOS 7 servers

2. Mysql5.7.26 (all three are installed through yum)

Server list

7.100.222.111master47.103.211.5slave147.103.98.221slave2

If you have not already installed mysql, please see the installation tutorial: mysql installation

I. Overview:

Architecture diagram:

This kind of architecture is commonly used in start-ups, and it is also convenient for further expansion.

Features:

1. It can relieve the pressure of reading.

2. Low cost, quick and convenient deployment

3. Separation of reading and writing

4. It can also reduce the pressure of reading the library by increasing the number of users in time.

5. Single point of failure of the main library

6. Data consistency problem (caused by synchronization delay)

7. Once the host is down, write operations cannot be performed.

Second, set up clusters

1. Modify the configuration file

Modify the configuration file on each of the three servers using the following command

$vim / etc/my.cnf

Add the following to the / etc/my.cnf mysql configuration files for each of the three servers:

Masetrslave1slave2

Server-id=1

# enable binlog log in the main database

Log-bin=/var/lib/mysql/mysql-bin

Server-id=2server-id=3

2. Create a replication user in the main library

Under the mysql command, enter the following command to create a user slave library (slave) to copy the master library (master)

Mysql > grant replication slave on *. * to 'test'@'%' identified by' 123456employees make query OK, 0 rows affected (0.00 sec) mysql > flush privileges;Query OK, 0 rows affected (0.00 sec)

3. Associate the master library with the slave library

Use the following command to check the status of the main library (master)

Mysql > show master status

Output the following information, of course yours can be different from mine

Mysql > show master status +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +- -+ | mysql-bin.000002 | 5141037 | +-+- -+ 1 row in set (0.00 sec)

You can see the above results. Here, you only need to look at File and Position. The other two are whitelist and blacklist, which means which databases are synchronized and which are not synchronized. You can set them according to your needs. Record the information of the first two fields ().

Operate the following commands on the two slave libraries (slave) respectively:

Mysql > change master to master_host='47.100.222.111', master_port=3306, master_user='test', master_password='123456', master_log_file='mysql-bin.000002', master_log_pos=5141037; mysql > flush privileges; mysql > slave start

After execution, continue to execute the following statement on the slave library:

Mysql > show slave status\ G

Output the following information:

* * 1. Row *

Slave_IO_State: Waiting for master to send event

Master_Host: 47.100.225.121

Master_User: helper

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000002

Read_Master_Log_Pos: 5141037

Relay_Log_File: slave1-relay-bin.000003

Relay_Log_Pos: 5140628

Relay_Master_Log_File: mysql-bin.000002

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

-the following are omitted

If both Slave_IO_Running: and Slave_SQL_Running: are YES, then the configuration is successful.

At this point, the construction of one master and two slaves is completed, and the installation of one master and multiple slaves is similar. You can create a database or a table on the main library, and the slave library will copy it.

The above is the mysql cluster introduced by the editor to realize the detailed interpretation and integration of the one-master and multi-slave architecture. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report