作/译者:叶金荣(Email: ),来源:http://imysql.cn,转载请注明作/译者和出处,并且不能用于商业用途,违者必究。
1. 安装
[@s1.yejr.com ~]# tar zxf mysql-proxy-0.6.0-linux-rhas4-x86.tar.gz
[@s1.yejr.com ~]# cd mysql-proxy-0.6.0-linux-rhas4-x86 #可以看到有2个目录
[@s1.yejr.com mysql-proxy-0.6.0-linux-rhas4-x86]# ls sbin share
[@s1.yejr.com mysql-proxy-0.6.0-linux-rhas4-x86]# mv sbin/mysql-proxy /usr/local/sbin/
[@s1.yejr.com mysql-proxy-0.6.0-linux-rhas4-x86]# ls share mysql-proxy tutorial-constants.lua tutorial-packets.lua tutorial-rewrite.lua tutorial-warnings.lua tutorial-basic.lua tutorial-inject.lua tutorial-query-time.lua tutorial-states.lua #将lua脚本放到/usr/local/share下,以备他用 [@s1.yejr.com mysql-proxy-0.6.0-linux-rhas4-x86]# mv share/mysql-proxy /usr/local/share/ #删除符号连接等垃圾代码 [@s1.yejr.com mysql-proxy-0.6.0-linux-rhas4-x86]# strip /usr/local/sbin/mysql-proxy
2. 启动
[@s1.yejr.com ~]# vi /etc/init.d/mysql-proxy
#!/bin/sh
export LUA_PATH=/usr/local/share/mysql-proxy/?.lua
mode=$1 if [ -z "$mode" ] ;
then mode="start" fi case $mode in 'start')
mysql-proxy --daemon /
--admin-address=:4401 /
--proxy-address=:3307 /
--proxy-backend-addresses=:3306 /
--proxy-read-only-backend-addresses=192.168.133.232:3306 /
--proxy-read-only-backend-addresses=10.10.74.61:3306 /
--proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua
;; 'stop') killall mysql-proxy ;; 'restart') if $0 stop ; then $0 start else echo "retart failed!!!" exit 1 fi ;; esac exit 0
现在解释一下启动脚本: 完整的参数可以运行以下命令查看:
mysql-proxy --help-all
运行以下命令启动/停止/重启mysql proxy:
[@s1.yejr.com ~]# /etc/init.d/mysql-proxy start [@s1.yejr.com ~]# /etc/init.d/mysql-proxy stop [@s1.yejr.com ~]# /etc/init.d/mysql-proxy restart
3. 试用
[@s1.yejr.com ~]# mysql -h127.0.0.1 -uroot -P3307 mysql> show processlist; +-------+------+----------------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +-------+------+----------------+------+---------+------+-------+------------------+ | 30052 | root | localhost:9656 | NULL | Query | 0 | NULL | show processlist | +-------+------+----------------+------+---------+------+-------+------------------+
可以看到,产生了一个新连接。 用sysbench测试一下,看会不会挂掉:
[@s1.yejr.com ~]# sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 / --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-db=test prepare [@s1.yejr.com ~]# sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 / --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-db=test run ......... ......... Threads fairness: events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 23.0387/0.00
还好,没给大家丢脸,剩下的测试自己完成吧 :)
4. 其他
min_idle_connections = 1 max_idle_connections = 3
blug修正: (责任编辑:IT) |