CentOS 6.8搭建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'