实在没想到自己在x86_64 GNU/Linux 下编译安装MySQL-Proxy这么复杂,碰到的问题太多了!
MySQL-Proxy 的介绍:
http://forge.mysql.com/wiki/MySQL_Proxy
http://www.oreillynet.com/pub/a/databases/2007/07/12/getting-started-with-mysql-proxy.html
http://www.infoq.com/news/2007/10/mysqlproxyrwsplitting
Linux 编译安装参考这里 就那两下,没啥复杂的,注意以下参数啥的就可以了
MySQL-Proxy下载:
wget http://dev.mysql.com/get/Downloads/MySQL-Proxy/mysql-proxy-0.6.1.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
安装:./configure
碰到无法找到mysql.h 这很正常,我的MySQL是自己手工安装的找不到配置文件
查帮助:./configure –with-mysql=/usr/local/mysql/bin/mysql_config
这样指名我安装的MySQL配置文件在什么地方
最后报需要Lua包,Faint啊
下载:wget http://www.lua.org/ftp/lua-5.1.tar.gz
Lua安装碰到很多问题,不像网上说得这么轻松 这哪是make linux 然后make linux install 这么简单啊
首先发现这一行:gcc -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline -lhistory -lncurses
报错:/usr/bin/ld: cannot find -lncurses
这了无数解决办法都没用,太痛苦了!一怒之下干掉这些配置,变成这样:
gcc -o lua lua.o liblua.a -lm -Wl,-E -ldl (居然通过了,后面使用也没初选啥问题,人品好 )
这样编译就通过了 可能这些相关功能还没用上吧
接着(这回不报找不到Lua lib了 嘿嘿)
可是报无法找到libevent可恶啊,这位老大就放弃自己编译,直接下载二进制包了
我接着google libevent,然后:wget http://www.monkey.org/~provos/libevent-1.4.1-beta.tar.gz
按照前面一样编译安装libevent
然后接着编译MySQL-Proxy:LUA_CFLAGS=”-I/usr/local/include” LUA_LIBS=”-L/usr/local/lib -llua -ldl” LDFLAGS=”-lm” ./configure –with-mysql=/usr/local/mysql/bin/mysql_config
这回整个世界终于安静了
然后安装就可以使用了!
还可以参考这里:http://www.uplooking.com/bbs/redirect.php?tid=49&goto=lastpost
mysql-5.1和Mysql-proxy的安装
centos4.5/rhel4.5
2、mysql-5.1的安装
mysql-5.1刚出来rc版,原先持续好久的beta版
# wget http://mysql.cdpa.nsysu.edu.tw/D … ql-5.1.22-rc.tar.gz
# tar zxf mysql-5.1.22-rc.tar.gz
# cd mysql-5.1.22-rc
# ./configure –prefix=/usr/local/mysql-5.1.22 –with-charset=utf8 –with-extra-charsets=all –with-big-tables –with-comment –with-mysqld-ldflags=-all-static –enable-assembler –disable-shared –with-pthread
# make && make install
# ln -s /usr/local/mysql-5.1.22 /usr/local/mysql
# cd /usr/local/mysql
# mkdir etc ; cp share/mysql/my-large.cnf etc/my.cnf
# useradd mysql -s /sbin/nologin
# chown -R mysql.mysql .
# su -m mysql -c ‘./bin/mysql_install_db’ //安装授权表
# su -m mysql -c ‘./bin/mysqld_safe &’ //启动mysql服务
# /usr/local/mysql/bin/mysql //进入msyql
下载安装Lua 5.1
# wget http://www.lua.org/ftp/lua-5.1.2.tar.gz
# tar zxf lua-5.1.2.tar.gz && cd lua-5.1.2 && make linux install
centos4.5本身的glib是2.4的,glib升级非常麻烦,mysql-proxy 0.6.0源码的配置无法通过。
# tar zxf mysql-proxy-0.6.0.tar.gz && cd mysql-proxy-0.6.0
# LUA_CFLAGS=”-I/usr/local/include” LUA_LIBS=”-L/usr/local/lib -llua -ldl” LDFLAGS=”-lm” ./configure –prefix=/usr/local/mysql-proxy –with-mysql=/usr/local/mysql-5.1.22/bin/mysql_config
checking for LUA… yes
checking for GLIB… Requested ‘glib-2.0 >= 2.6.0′ but version of GLib is 2.4.7
configure: error: Package requirements (glib-2.0 >= 2.6.0) were not met:
# wget http://mysql.cdpa.nsysu.edu.tw/D … ux-rhas4-x86.tar.gz
# tar mysql-proxy-0.6.0-linux-rhas4-x86.tar.gz
# cp mysql-proxy-0.6.0-linux-rhas4-x86/sbin/mysql-proxy /usr/local/mysql/bin
# /usr/local/mysql/bin/mysql-proxy & //在后台启动,默认启动时4040和4041端口
# /usr/local/mysql/bin/mysql -P4040 //一样能进入mysql
–proxy-address= 代理的ip:port,默认是0.0.0.0:4040
–proxy-read-only-backend-addresses= 代理的只读连接ip:port 默认0.0.0.0:4042(试了一下好像没有作用)
–proxy-backend-addresses= db server的地址,默认是127.0.0.1:3306,可以指定多个来做failover和load balance
–proxy-profiling enable profiling of queries (没试)
–proxy-fix-bug-25371 fix bug #25371 (mysqld > 5.1.12) for older libmysql versions (没试)
–proxy-lua-script= lua脚本文件
分别在192.168.1.122和192.168.189上安装mysql5.1数据库,启动并添加一个用户
mysql>grant all privileges on test.* to abc@’%’ identified by ’123456′;
create table hehe(id int(5),hehe char(255));
在192.168.1.189的test数据库建立一个表hehe
create table hehe(id int(5),name char(255));
在192.168.1.104启动mysql-proxy
# LUA_PATH=”/usr/local/share/mysql-proxy/?.lua” /usr/local/mysql/bin/mysql-proxy –proxy-read-only-backend-addresses=192.168.1.189:3306 –proxy-backend-addresses=192.168.1.122:3306 –proxy-lua-script=share/mysql-proxy/rw-splitting.lua &
# mysql -uabc -p123456 -h192.168.1.104 -P4040 test
mysql> desc hehe;
mysql> create table jiji(id int(5),name char(255));
总结:这个mysql数据库前端代理能对用户的mysql操作进行读写分离,对程序是透明的,减少了开发上的难度。