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

MySQL middleware Atlas realizes the separation of read and write

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

0 Atlas architecture introduction

Atlas is a middleware developed by Qihoo360, which is located in the middle layer of Client and MySQL Server. It can be used as read-write separation, sub-library and sub-table middleware.

To MySQL Server, Atlas is like a Client, while to Client, Atlas is a DB server.

0 experimental structure

OS: CentOS 6.5 64bit

MySQL version: 5.6.30

Master:192.168.1.185

Slave:192.168.1.186

Proxy (Atlas): 192.168.1.187

Client: 192.168.1.192

0 MySQL part:

(master-slave establishment steps are outlined)

Create a master / slave account with addition, deletion, modification and query:

GRANT SELECT, INSERT, UPDATE, DELETE ON *. * TO 'dev'@'192.168.1.187' IDENTIFIED BY' dev';FLUSH PRIVILEGES

SET GLOBAL log_output='TABLE' can be set from the library

SET GLOBAL general_log=on

Create a test table on master:

Master > CREATE TABLE test.a (id int)

Query OK, 0 rows affected (0.03 sec)

Then go to the client (192.168.1.192) to try to initiate a request for adding, deleting, modifying and searching Atlas (192.168.1.187):

A php script is written here to simulate the request:

You can install php-related dependencies here through yum install-y php php-mysql.

After executing this php script, you can check the general log of master (192.168.1.185) and slave library (192.168.1.186), respectively:

Master > SELECT user_host, argument

-> FROM mysql.general_log

-> WHERE user_host='dev [dev] @ [192.168.1.187]'

+-+

| | user_host | argument |

+-+

| | dev [dev] @ [192.168.1.187] | INSERT INTO test.a SELECT 1 |

| | dev [dev] @ [192.168.1.187] | UPDATE test.a SET id=222 WHERE id=1 |

| | dev [dev] @ [192.168.1.187] | DELETE FROM test.a WHERE id=222 |

| | dev [dev] @ [192.168.1.187] | INSERT INTO test.a SELECT 123456 |

+-+

4 rows in set (0.00 sec)

Slave > SELECT user_host, argument

-> FROM mysql.general_log

-> WHERE user_host='dev [dev] @ [192.168.1.187]'

+-+

| | user_host | argument |

+-+

| | dev [dev] @ [192.168.1.187] | SELECT count (1) FROM test.a |

+-+

1 rows in set (0.00 sec)

Finally, check whether the data of the test.a table after running the php script is as expected:

Slave > SELECT * FROM test.a;+-+ | id | +-+ | 123456 | +-+ 1 row in set (sec)

Of course, it was obviously in line with expectations.

Obviously Atlas, as proxy, has submitted the write request to master (192.168.1.185) and the read request to slave (192.168.1.186).

For clients and developers, you only need to obtain an Atlas server address, port, user name, and password to use read-write separation.

Atlas can also implement sub-table function, and you can flip through Atlas Home here.

0 reference documentation:

Https://github.com/Qihoo360/Atlas/releases

Https://github.com/Qihoo360/Atlas/wiki

Author's official account on Wechat (continuously updated)

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