一:mysql主从数据库的配置
要求:配置主
从复制: server2 主 172.25.28.2
server3 从 172.25.28.3
二:安装配置mysql-proxy
[root@server1 /]# tar zxf mysql-proxy-0.8.5-linux-el6-x86-64bit -C /usr/local/
[root@server1 local]# ln -s mysql-proxy-0.8.5-linux-el6-x86-64bit/ mysql-proxy ##简化路径
[root@server1 local]# mkdir /usr/local/mysql-proxy/conf
[root@server1 local]# mkdir /usr/local/mysql-proxy/log
[root@server1 local]# vim mysql-proxy/conf/mysql-proxy.conf ##编译配置文件
[mysql-proxy]
daemon=true #打入后台
user=root #
keepalive=true
plugins=proxy,admin
log-level=info #日志级别
log-file=/usr/local/mysql-proxy/log/mysql-proxy.log ##proxy日志地址
proxy-address=172.25.28.1:3306 #本机ip地址
proxy-backend-addresses=172.25.28.2:3306 ##backend主 注意addresses
proxy-read-only-backend-addresses=172.25.28.3:3306 ##backend从
proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua ##lua脚本地址
admin-address=172.25.28.1:4041 ##proxy的管理用户adminiphe端口
admin-username=admin
admin-password=westos
admin-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua #admin的lua脚本地址;
更改lua脚本
[root@server1 local]# vim /usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
使其快速进入读写分离状态
-- connection pool
if not proxy.global.config.rwsplit then
proxy.global.config.rwsplit = {
min_idle_connections = 1, ##最小连接数
max_idle_connections = 2, ##最大连接数后实现读写分离
is_debug = false
}
开启proxy控制
[root@server1 local]# /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/mysql-proxy.conf
查看日志状态:
[root@server1 mysql-proxy]# /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/mysql-proxy.conf
[root@server1 mysql-proxy]#cat log/mysql-proxy.log
2017-10-21 13:15:54: (message) chassis-unix-daemon.c:136