1.检查程序依赖lua语言环境
[root@localhost ~]# rpm -qa |grep lua
lua-5.1.4-4.1.el6.x86_64
2.安装proxy软件包
[root@localhost ~]# tar -zxvf mysql-proxy-0.8.3-linux-rhel5-x86-64bit.tar.gz //解压软件
[root@localhost ~]# mv mysql-proxy-0.8.3-linux-rhel5-x86-64bit /usr/local/mysqlproxy
//习惯性把软件放到/usr/local下
/usr/local/mysqlproxy/share/doc/mysql-proxy
3.利用proxy脚本实现读写分离
[root@localhost mysql-proxy]# chmod a+x rw-splitting.lua //给读写分离脚本可执行权限
/usr/local/mysqlproxy/bin
[root@localhost bin]# ./mysql-proxy -P 192.168.1.33:3306 -r 192.168.1.32:3306 -b 192.168.1.31:3306 -s /usr/local/mysqlproxy/share/doc/mysql-proxy/rw-splitting.lua --keepalive &
//运行脚本P指定代理监听ip和端口,r指定读服务器ip和端口,b指定写服务器ip和端口,s指定脚本路径,keepalaive使此后台进程崩溃后自动重启该后台进程
[root@localhost bin]# mysql -h192.168.1.33 -udaili -p123456
//验证,默认小于等于4时只分发给写服务器,但只要大于4后以后的请求都可以读写分离
本文出自 “sleepcat” 博客,请务必保留此出处http://sw5720.blog.51cto.com/8812314/1437674