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

NetEase's separation of reading and writing in cetus

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

Share

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

I. brief introduction

Cetus is the middleware of relational database MySQL developed by C language, which mainly provides a comprehensive database access agent function. The Cetus connection mode is basically compatible with MySQL, and the application can access the database through Cetus almost without modification, which realizes the horizontal expansion and high availability of the database layer.

Cetus is an excellent middleware designed by multi-department coordination and cooperation led by NetEase Lede expert and technical team.

For details, please refer to the official website: https://github.com/Lede-Inc/cetus

This paper is mainly based on the practice of reading and writing separation.

Second, the construction of the separation of reading and writing

1. Installation dependency

Yum install cmake gcc glib2-devel flex libevent-devel mysql-devel gperftools-libs-y

2. Download the source code

Git clone https://github.com/Lede-Inc/cetus.git

3. Compile and install

1. Create a separate directory build under the home directory of the source code, and go to this directory to mkdir build/cd build/2 and compile: compile with cmake, with the following instructions: cmake.. /-DCMAKE_BUILD_TYPE=Debug-DCMAKE_INSTALL_PREFIX=/data/cetus/cetus_install-DSIMPLE_PARSER=ON3, install: execute make install to install make install

4. Configuration file

Cd / data/cetus/cetus_install/conf/cp XXX.json.example XXX.jsoncp XXX.conf.example XXX.confvi XXX.jsonvi XXX.conf this article mainly configures two files, users.json and proxy.conf1, cp users.json.example users.json & & vim users.json {"users": [{"user": "root", "client_pwd": "123", based on read-write separation. "server_pwd": "123456"}]} 2, cp proxy.conf.example proxy.conf & & vim proxy.conf [cetus] # For mode-switchdaemon = true# Loaded Pluginsplugins=proxy,admin# Proxy Configuration For eaxmlpe: MySQL master and salve host ip are both 192.0.0.1proxy-address=127.0.0.1:6001proxy-backend-addresses=192.168.142.48:5700proxy-read-only-backend-addresses=192.168.142.49:5700# Admin Configurationadmin-address=127.0.0.1:7001admin-username=adminadmin-password=admin# Backend Configuration, use test db and username createddefault-db=testdefault-username=root# File and Log Configuration, put log in / data and marked by proxy port / data/cetus needs to be created manually and has rw authority for cetus os userpid-file = cetus6001.pidplugin-dir=lib/cetus/pluginslog-file=cetus_6001.loglog-level=debug# support the MGRgroup-replication-mode = 1

5. Start

. / bin/cetus-defaults-file=conf/proxy.conf-conf-dir=/data/cetus/cetus_install/conf/

6. Log in on the command line

1. Application port usr/local/mysql-5.7.18/bin/mysql-- prompt= "proxy >"-- comments-uroot-p123-h227.0.0.1-P6001proxy > select version () +-+ | version () | +-+ | 5.7.18-log | +-+ 1 row in set (0.00 sec) 2, management port / usr/local/mysql-5.7.18/bin/mysql-- prompt= "admin >"-- comments-uadmin-padmin-h227.0.0.1-P7001admin > select * from backends +-+ | backend_ndx | address | | state | type | slave delay | uuid | idle_conns | used_conns | total_conns | +-- | +-+ | 1 | 192.168.142.48 NULL 5700 | up | rw | NULL | NULL | 2 | 0 | 2 | 2 | 192.168.142.49 NULL 5700 | up | ro | 0 | NULL | 2 | 0 | 2 | +- -+ 2 rows in set (0.00 sec) 3. Read-write Separation Test of MGR

Deployment environment

MGR environment 192.168.142.48 for MGR master node 192.168.142.49 configure proxy-backend-addresses=192.168.142.48:5700 read node configuration proxy-read-only-backend-addresses=192.168.142.49:57001 for MGR slave node write node, test read:

1.1. Master-slave group replication is normal.

Proxy > select sleep (15) from T1 where astat1

The corresponding read request process appears on 192.168.142.49

1.2. Master-slave group replication exception

192.168.142.49 stop group replication

Root@192.168.142.49 > STOP GROUP_REPLICATION

Proxy > select sleep (15) from T1 where astat1

The corresponding read request process appears on 192.168.142.48

2. Test writing:

2.1. Master-slave group replication is normal.

Proxy > insert into T1 select 6, sleep (15)

The corresponding write request process appears on 192.168.142.48

2.2. Master-slave group replication exception

192.168.142.49 stop group replication

Root@192.168.142.49 > STOP GROUP_REPLICATION

Proxy > insert into T1 select 7, sleep (15)

The corresponding write request process appears on 192.168.142.48

4. Read-write separation test of one master and two slaves

Deployment environment

192.168.142.48 for master node 192.168.142.49 for slave node 192.168.142.50 configure proxy-backend-addresses=192.168.142.48:5700 read node configuration proxy-read-only-backend-addresses=192.168.142.49:5700192.168.142.50:57001 for slave node write node, test read:

Proxy > select sleep (15) from T1 where astat1

The corresponding read request process appears on 192.168.142.49

Read the request again

Proxy > select sleep (15) from T1 where astat1

The corresponding read request process appears on 192.168.142.50

It can be found that the read request is evenly randomly assigned to two read nodes.

2. Test writing:

Proxy > insert into T1 select 2, sleep (15)

The corresponding write request process appears on 192.168.142.48

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