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

Read-write separation of Mysql database

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

Share

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

First, the database operations are separated from reads and writes, so that the master server with the role of master is mainly used to perform write operations, which can greatly reduce the overload of the main server caused by read operations. Read it to slave. For multiple read servers, the pressure of read operations should also be spread among different slave servers. Generally speaking, read-write separation and read load balancing of multiple slave servers are also two different problems that need to be solved separately. First, read and write are separated, and then read operations are distributed evenly among slave servers)

There is not much difference between redis and memcache, and it also has more data types, persistence, master-slave replication, clustering and other functions.

(for example, the inventory query must be carried out on the main database, if from the library may be oversold. Therefore, not all queries have to be read-write separate. Therefore, it is more flexible for developers to judge for themselves)

Read-write separation can also be done through the database middle tier (such as mysql proxy, maxscale, one proxy, proxySQL, etc.):

Through the parsing of sql statements in the middle tier, if it is a select operation, it is sent to the slave server for processing, and non-select operations are all sent to the master server for processing. The sql of stored procedures, which can not be parsed by calling syntax, can only be done by the master database server. Since a large part of the stored procedure is probably just query processing, this undoubtedly increases the load on the primary database server. Although it is convenient to use the middle tier, there is a price to pay)

(since read-write separation is carried out automatically through the middle tier, and the middle layer cannot distinguish which are delay-sensitive and which are not, it is impossible to automatically assign delay-sensitive queries to the main library for execution. In order to achieve these functions, prompt keywords are added to the query statement, and the increase of prompts has to modify the original program, thus losing the advantage of transparency to the program.)

Commonly used load balancing methods for reading servers:

For database servers, read load and write load are two completely different issues, so read load and write load should be treated separately, because writes can only be done on master, while reads can be done on master or slave. Therefore, it is easier to deal with read load than write load.

(lvs works on layer 4 of the network protocol. It only distributes traffic and does not parse the contents of the packet. It has high performance and low consumption of memory and cpu. Of course, since it does not parse the data, it does not know the specific content of sql in the packet, so naturally it cannot do read-write separation.)

(lvs only distributes requests, and traffic does not flow out from itself, so there is no traffic consumption, which ensures that io performance will not be affected by heavy traffic.)

The master-slave copy process will not be posted.

Install lvs management tools on both .100 and .101 servers:

Load the ipvs module (all three servers participating in the lvs cluster will be installed):

Lvs script writing:

First take a look at the script on slave (.101 server):

(note that this script must have executable permissions.)

Execute the script:

View:

It is also performed on .102:

View:

Keepalived configuration on .100:

View the check_slave script:

.

Create an lvs operable account on .100:

It is not finished to be continued.

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