Mysql-proxy for read-write separation

Source: Internet
Author: User
Tags lua

Mysql-proxy for read-write separation

Need to configure Master-slave synchronization: Five steps to complete MySQL master-slave replication

主服务器Master:192.168.179.146从服务器Slave:192.168.179.147调度服务器MySQL-Proxy:192.168.179.142
Download Mysql-proxy

The implementation of read-write separation is implemented with LUA scripting, now mysql-proxy inside is integrated, no need to install

Download: https://downloads.mysql.com/archives/proxy/Download the corresponding version

I'm taking CentOS6 64-bit Server for example

Installing Mysql-proxy

My side to facilitate the use of the wget command to download, and then copy to/usr/local/and modify the directory named Mysql-proxy.

wget https://cdn.mysql.com/archives/mysql-proxy/mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz tar zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-32bit.tar.gzmv mysql-proxy-0.8.5-linux-glibc2.3-x86-32bit /usr/local/mysql-proxy
Configure Mysql-proxy

Create the directory where the Mysql-proxy scripts and log files reside, and bring your own management scripts to the test.

cd /usr/local/mysql-proxymkdir lua  #创建脚本存放目录mkdir logs #创建日志目录cp share/doc/mysql-proxy/rw-splitting.lua ./lua  #复制读写分离配置文件cp share/doc/mysql-proxy/admin-sql.lua ./lua     #复制管理脚本
Create mysql-proxy configuration file vim/etc/mysql-proxy.cnf #创建配置文件
[mysql-proxy]user=root            #运行mysql-proxy用户admin-username=lin3615    #主从mysql共有的用户admin-password=123456     #用户的密码proxy-address=192.168.179.142:4040     #mysql-proxy运行ip和端口(默认端口4040)proxy-read-only-backend-addresses=192.168.179.147     #指定后端从slave读取数据(默认端口3306)proxy-backend-addresses=192.168.179.146                      #指定后端主master写入数据(默认端口3306)proxy-lua-script=/usr/local/mysql-proxy/lua/rw-splitting.lua #指定读写分离配置文件位置admin-lua-script=/usr/local/mysql-proxy/lua/admin-sql.lua  #指定管理脚本log-file=/usr/local/mysql-proxy/logs/mysql-proxy.log           #日志位置log-level=info      #定义log日志级别,由高到低分别有(error|warning|info|message|debug)daemon=true      #以守护进程方式运行keepalive=true   #mysql-proxy崩溃时,尝试重启

: Wq #保存退出!
chmod 660/etc/mysql-porxy.cnf

To modify a read-write detach configuration file Vim/usr/local/mysql-proxy/lua/rw-splitting.lua
if not proxy.global.config.rwsplit then    proxy.global.config.rwsplit = {        min_idle_connections = 1, #默认超过4个连接数时,才开始读写分离,改为1        max_idle_connections = 1, #默认8,改为1        is_debug = false }end
Start Mysql-proxy
/usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/etc/mysql-proxy.cnf  #指定我们创建的/etc/mysql-proxy.cnf配置文件启动netstat -tupln | grep 4040   #已经启动killall -9 mysql-proxy           #关闭mysql-proxy使用
Test read/write separation
在主服务器创建proxy用户用于mysql-proxy使用,从服务器也会同步这个操作mysql> grant all on *.* to ‘lin3615‘@‘192.168.179.142‘ identified by ‘123456‘;使用客户端连接mysql-proxymysql -u lin3615 -h 192.168.179.142 -P 4040 -p123456

Mysql-proxy for read-write separation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.