CentOS 5.5 x86_64 编译安装 mysql-proxy 0.8.0
1. 安装依赖包
yum install autoconf.x86_64 automake.x86_64 libtool.x86_64 flex.x86_64 pkgconfig.x86_64 mysql-devel.x86_64
yum install -y readline.x86_64 readline-devel.x86_64 ncurses.x86_64 ncurses-devel.x86_64
yum install python-pycurl.x86_64 libevent.x86_64 libevent-devel.x86_64
rpm -ivh ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/x86_64/python-crypto-2.0.1-4.el5.2.x86_64.rpm
rpm -ivh ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/i386/python-paramiko-1.7.6-1.el5.noarch.rpm
rpm -ivh ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/x86_64/bzr-2.1.1-4.el5.x86_64.rpm
wget
tar zvfx glib-2.16.1.tar.gz
cd glib-2.16.1
./configure
make
make install
wget
tar zvfx lua-5.1.4.tar.gz
cd lua-5.1.4
vi src/Makefile
#要在此文件CFLAGS打头一行加上-fPIC ,否则在下一步编译mysql-proxy时会报错:
/usr/bin/ld: /usr/local/lib/liblua.a(lapi.o):
relocation R_X86_64_32 against `luaO_nilobject_' can not be used when making a shared object;
recompile with -fPIC
/usr/local/lib/liblua.a: could not read symbols: Bad value
接下来,
make linux
make install
cp etc/lua.pc /usr/local/lib/pkgconfig/
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
2. 安装mysql-proxy
可以使用bzr版本管理系统下载mysql-proxy,也可以自己单独下载:
wget
tar -zxvf mysql-proxy-0.8.0.tar.gz
cd mysql-proxy-0.8.0/
./configure --with-lua --with-mysql=/usr/local/mysql/bin/mysql_config
make
make install
验证一下 :
mysql-proxy -V
mysql-proxy 0.8.0
glib2: 2.16.1
libevent: 1.4.13-stable
lua: Lua 5.1.4
LUA_PATH: /usr/local/lib/mysql-proxy/lua/?.lua
LUA_CPATH: /usr/local/lib/mysql-proxy/lua/?.so
== plugins ==
admin: 0.7.0
proxy: 0.7.0
3. 启动脚本 adm_mysql_proxy.sh
#!/bin/sh
##export PATH=/usr/local/bin/:$PATH
export LUA_PATH=/usr/local/lib/mysql-proxy/lua/?.lua
ulimit -n 4096
mode=$1
if [ -z "$mode" ] ; then
mode="start"
fi
case $mode in
'start')
mysql-proxy --daemon \
--admin-address=:4401 \
--admin-username='root' \
--admin-password='123456' \
--proxy-address=:4406 \
--keepalive \
--log-backtrace-on-crash \
--log-file=/var/log/mysql-proxy.log \
--admin-lua-script=/usr/local/share/doc/mysql-proxy/rw-splitting.lua \
--proxy-read-only-backend-addresses=127.0.0.1:3308 \
--proxy-backend-addresses=127.0.0.1:3306 \
--max-open-files=4096 \
--proxy-lua-script=/usr/local/share/doc/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
4. 启动 adm_mysql_proxy.sh start
问题: chassis-limits.c:81: could not raise RLIMIT_NOFILE to xxx
ulimit=4096
问题: mysql-proxy退出:
2011-05-10 15:07:29: (critical) proxy-plugin.c.1130: I have no server backend, closing connection
2011-05-10 15:07:29: (critical) network-mysqld.c.1293: plugin_call(CON_STATE_READ_QUERY) failed
[disconnect_client] 127.0.0.1:53523
到这一步,mysql代理只能做到读写分离,并没有做到负载均衡, 出现上述错误时,修改 rw-splitting.lua 的连接参数可以适当缓解,另外启动参数--keepalive会启动2个mysql-proxy进程用于crash时另一个继续提供服务.
性能:
8G服务器,主,从,代理全在一起跑.使用mysqlslap测试,100-500并发响应速度和稳定性不是很理想.
mysql-proxy进程由始至终占用的cpu和内存都很少, 内存<6M
有待发掘.
阅读(3443) | 评论(0) | 转发(0) |