安装mysql-proxy分发请求
(一)安装依赖包
重要:让pkg-config找到自己编译的库在哪里
[root@xutest opt]#export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
lua-5.1
#tar zxvf lua-5.1.tar.gz
#cd lua-5.1
#sed -i 's#INSTALL_TOP= /usr/local#INSTALL_TOP= /usr/local/lua#' Makefile
#make posix && make install
cp etc/lua.pc /usr/local/lib/pkgconfig/
安装pkg-config:
tar zxvf pkg-config-0.23.tar.gz
cd pkg-config-0.23
./configure
#make && make install
确保PKG_CONFIG_PATH环境变量包含了相关的pkg-config配置文件路径:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
libevent-1.1a
#tar zxvf libevent-1.1a.tar.gz
#cd libevent-1.1a
#./configure --prefix=/usr/local/libevent
#make && make install
安装glib:
tar zxvf glib-2.20.0.tar.gz
cd glib-2.20.0
./configure
make
make install
check-0.8.4
tar zxvf check-0.8.4.tar.gz
cd check-0.8.4
./configure
make
make install
(二)安装mysql客户端
#tar zxvf mysql-5.1.35.tar.gz
#cd mysql-5.1.35
#./configure --prefix=/usr/local/mysql --without-server
#make && make install
(三)设置环境变量
export LUA_CFLAGS="-I/usr/local/lua/include" LUA_LIBS="-L/usr/local/lua/lib -llua -ldl" LDFLAGS="-L/usr/local/libevent/lib -lm"
export CPPFLAGS="-I/usr/local/libevent/include"
export CFLAGS="-I/usr/local/libevent/include"
(四)安装mysql-proxy
#tar xvf mysql-proxy-0.6.1.tar.gz
#cd mysql-proxy-0.6.1
#./configure --prefix=/usr/local/mysql-proxy --with-mysql=/usr/local/mysql --with-lua
#Make && Make install
(五)创建启动脚本
#!/bin/bash
LUA_PATH="/usr/local/mysql-proxy/share/mysql-proxy/?.lua" /usr/local/mysql-proxy/sbin/mysql-proxy —proxy-backend-addresses=172.24.0.23:3306 ----main
—proxy-read-only-backend-addresses=172.24.0.24:3306 —----slave
--proxy-lua-script=/usr/local/mysql-proxy/share/mysql-proxy/rw-splitting.lua >> /var/log/mysql-proxy.log &
#chmod a+x /usr/local/bin/mysql-proxy.sh
执行命令/usr/local/bin/mysql-proxy.sh启动服务
主要的命令行选项
--help-all显示所有的帮助选项
--admin-address=host:port 管理主机及端口,默认是4041
--proxy-address=host:port 代理服务器的监听地址及端口,默认4040
--proxy-read-only-address=host:port 只读连接时,代理服务器的监听地址及端口
--proxy-backend-addresses=host:port 连接真实服务器的地址及监听端口,默认是3306
--proxy-lua-script=file 指定lua脚本的名称
使用方法
mysql-proxy --proxy-backend-addresses=<master_ip> :3306/
--proxy-read-only-backend-addresses=<slave_ip1>:3306 /
--proxy-read-only-backend-addresses=<slave_ip2>:3306
测试
mysql-proxy -V
这样该ok了把,可能会报错类似于:
/etc/init.d/mysql-proxy start
2009-12-18 01:59:52: (warning) g_set_prgname() called multiple times
2009-12-18 01:59:52: (critical) chassis.c:981: could not raise RLIMIT_NOFILE to 8192, Invalid argument (22). Current limit still 13815894353589044224.
这个一个警告级别的错误,意思是MySQL Proxy在你的系统上不能把open files limit提升到8192,不过没关系的,MySQL Proxy依然好好的运行在你的电脑上.
$mysql -h127.0.0.1 -uroot -p -P3307
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 6
Server version: 5.1.40-blang-debug-log Source distribution
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql> show processlist;
+----+------+----------------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+----------------+------+---------+------+-------+------------------+
| 6 | root | localhost:3688 | NULL | Query | 0 | NULL | show processlist |
+----+------+----------------+------+---------+------+-------+------------------+
1 row in set (0.09 sec)
可以看到,产生了一个新连接。http://blog.csdn.net/xiao7ng/archive/2009/12/17/5026964.aspx
参考文档
http://hi.baidu.com/thinkinginlamp/blog/item/f96559821fbda8aa0cf4d200.html
http://hi.baidu.com/thinkinginlamp/blog/item/f96559821fbda8aa0cf4d200.html
http://hi.baidu.com/5651741/blog/item/402045b7396e8dfd30add11d.html
http://liudaoru.javaeye.com/blog/617987
http://blog.csdn.net/lgm252008/archive/2010/04/05/5452566.aspx
http://www.dbasky.net/archives/2009/07/mysql-proxy-mysql.html