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

Using mysql-proxy to achieve read-write separation

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

Share

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

Mysql-proxy implements MySQL read-write separation installation and configuration of mysql-proxy using binary format

Mysql-proxy itself cannot separate read and write, which depends on lua, so first check whether lua is installed. If not, you can install it using yum install.

~] # rpm-Q lualua-5.1.4-4.1.el6.x86_64

Create a system user

Useradd-r mysql-proxy

Extract the package to create a link file

Tar zxf mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz-C / usr/local/ln-s mysql-proxy-0.8.5-linux-el6-x86-64bit/ mysql-proxy

Export binary program

~] # vim / etc/profile.d/mysql-proxy.sh content is: export PATH=/usr/loca/mysql-proxy/bin/:$PATH~] # source / etc/profile.d/mysql-proxy.sh

View mysql-proxy usage

~] # mysql-proxy-- the more important options for help-all# are the following-- daemon # Let mysql-proxy work in the background-- user= # specify the owner of the mysql-proxy process-- proxy-backend-addresses= # backend server-- proxy-read-only-backend-addresses= # read-only backend server-- log-level= (error | warning | info | message | debug) # specify the log level-- log-file= # specify the log file Path-- plugins= # name of the plug-in to load The plug-in path is in / usr/local/mysql-proxy/lib/mysql-proxy/plugins, where there is a plug-in for libadmin.so, which can be used to manage back-end servers, and plug-ins for libproxy.so, and enable the function of proxy-- keepalive # if proxy crashes, it will try to restart the lua script file specified by proxy--proxy-lua-script= #, and the lua script path is at / usr/local/mysql-proxy/share/doc/mysql-proxy Under this path, there is a lua script file rw-splitting.lua--defaults-file # that implements the separation of read and write to specify the configuration file path.

Enable mysql-proxy

~] # mysql-proxy-- daemon\ >-- user=mysql-proxy\ >-- log-level=debug\ >-- log-file=/var/log/mysql-proxy.log\ >-- plugins=proxy\ >-- plugins=admin\ >-- proxy-backend-addresses=172.25.78.2:3306\ >-- proxy-read-only-backend-addresses=172.25.78.3:3306\ >-- keepalive=true\ >-- proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw -splitting.lua\ >-- admin-username=admin\ >-- admin-password=adminpass\ >-- admin-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua to view enabled ports] # netstat-tan | grep: 40tcp 0 0 0 admin-password=adminpass 4040 0 0 0 v * LISTEN tcp 0 0 0 .0 4041 0.0.0.0 LISTEN#4041 is the port of the admin management interface 4040 is the port connection test of mysql-proxy

Connect to the management interface on the proxy server (172.25.78.4) to see which back-end servers are available

Mysql-uadmin-padminpass-h272.25.78.4-- port=4041MySQL [(none)] > SELECT * FROM backends +-+ | backend_ndx | address | state | type | uuid | connected_clients | +-+- -+ | 1 | 172.25.78.2 NULL 3306 | unknown | rw | NULL | 0 | 2 | 172.25.78.3 NULL 3306 | unknown | ro | NULL | 0 | +-+-+

Add test users on the master node and the slave node

MariaDB [(none)] > GRANT SELECT,INSERT,UPDATE ON *. * TO 'test'@'172.25.78.%' IDENTIFIED BY' testpass'

Test on the client side

~] # mysql-utest-ptestpass-h272.25.78.4-P4040MariaDB [(none)] > SHOW DATABASES +-+ | Database | +-+ | information_schema | | MYDB | | S_SC_C | | db_user | | discuz | | dvwa | | hello | | mysql | | performance_schema | | test | | testdb | +-+ MariaDB [(none)] > USE S_SC_C | MariaDB [S_SC_C] > INSERT INTO Scrip1 (sname,sdept) VALUES ('Happy grammatical AA'); MariaDB [S_SC_C] > SELECT * FROM Signor1 +-+ | sid | sname | sdept | +-+ | 1 | HELLO | A | 2 | HE | A | 3 | H | AA | +-+

View on master

MariaDB [S_SC_C] > SELECT * FROM Stru1 +-+ | sid | sname | sdept | +-+ | 1 | HELLO | A | 2 | HE | A | 3 | H | AA | +-+ View MariaDB [S_SC_C] > SELECT * FROM Stain1 on slave +-+ | sid | sname | sdept | +-+ | 1 | HELLO | A | 2 | HE | A | 3 | H | AA | +-+

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