CentOS 6.8搭建mysql-proxy实现读写分离

柔情痞子 提交于 2020-02-26 01:19:00

CentOS 6.8搭建mysql-proxy实现读写分离:

下载网址:
http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-Proxy

注:
1、10.0.1.2为mysql-proxy服务器ip
2、效果是1个写,2个读

tar zxfv mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz -C /space

mv /space/mysql-proxy-0.8.5-linux-el6-x86-64bit /space/mysql-proxy

mkdir /space/mysql-proxy/logs

cp -rv /space/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua /space/mysql-proxy/

vi /space/mysql-proxy/rw-splitting.lua

if not proxy.global.config.rwsplit then
proxy.global.config.rwsplit = {
min_idle_connections = 1, (默认为4,即超过4个才会进行读写分离)
max_idle_connections = 1, (默认为8)

            is_debug = false
    }

end

:wq

vi /space/mysql-proxy/mysql-proxy.cnf

[mysql-proxy]

proxy-address=10.0.1.2:4040
proxy-backend-addresses=10.0.1.3
proxy-read-only-backend-addresses=10.0.1.4
proxy-read-only-backend-addresses=10.0.1.5
proxy-lua-script=/space/mysql-proxy/rw-splitting.lua
log-file=/space/mysql-proxy/logs/mysql-proxy.log
log-level=info
daemon=true

:wq

chmod 0660 /space/mysql-proxy/mysql-proxy.cnf

/space/mysql-proxy/bin/mysql-proxy --defaults-file=/space/mysql-proxy/mysql-proxy.cnf

ps -ef | grep mysql-proxy

netstat -nplt | grep 4040

关服务可通过kill -9 进程号

客户端访问:

mysql -h 10.0.1.2 -P 4040 -u aa -p'xxxx'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!