使用MySQL Proxy和MySQL Replication实现读写分离

使用MySQL Proxy和MySQL Replication实现读写分离

MySQL Replication可以将master的数据复制分布到多个slave上,然后可以利用slave来分担master的读压力。那么对于前台应用来说,就要考虑如何将读的压力分布到多个slave上。如果每个应用都需要来实现读写分离的算法,一则成本太高,二来如果slave增加更多的机器,应用就要随之修改。明显的,如果在应用和数据库间加一个专门用于实现读写分离的中间层,则整个系统的架构拥有更好的扩展性。MySQL Proxy就是这么一个中间层代理,简单的说,MySQL Proxy就是一个连接池,负责将前台应用的连接请求转发给后台的数据库,并且通过使用lua脚本,可以实现复杂的连接控制和过滤,从而实现读写分离和负载平衡。对于应用来说,MySQL Proxy是完全透明的,应用则只需要连接到MySQL Proxy的监听端口即可。当然,这样proxy机器可能成为单点失效,但完全可以使用多个proxy机器做为冗余,在应用服务器的连接池配置中配置到多个proxy的连接参数即可。

MySQL read write splitting


MySQL Proxy是2007年6月由Jan Kneschke发布的一个项目,基于GPL,目前还处于Alpha测试阶段,最新版本0.6.1,可以从这里下载。使用MySQL Proxy需要MySQL 5.0.x以上版本,详细的安装使用手册可以参考MySQL 5.1手册第27章

mysql-proxy --help-all
Usage:
  mysql-proxy.exe [OPTION...] - MySQL Proxy

Help Options:
  -?, --help     Show help options
  --help-all      Show all help options
  --help-admin    Show options for the admin-module
  --help-proxy    Show options for the proxy-module

admin module
  --admin-address=<host:port>   listening address:port of internal admin-server (default:4041)

proxy-module
  --proxy-address=<host:port>   listening address:port of the proxy-server (default:4040)
  --proxy-read-only-backend-addresses=<host:port>  address:port of the remote slave-server (default: not set)
  --proxy-backend-addresses=<host:port>   address:port of the remote backend-servers (default: 127.0.0.1:3306)
  --proxy-skip-profiling  disables profiling of queries (default: enabled)
  --proxy-fix-bug-25371  fix bug #25371 (mysqld > 5.1.12) for older libmysql versions
  --proxy-lua-script=<file>   filename of the lua script (default: not set)
  --no-proxy     Don't start proxy-server

Application Options:
  -V, --version      Show version
  --daemon        Start in daemon-mode
  --pid-file=<file>    PID file in case we are started as daemon

bookmark

本文网址:http://www.ningoo.net/html/2008/using_mysql_proxy_for_read_write_splitting.html

如果您喜欢我的Blog,欢迎订阅到Google | 收藏到Del.icio.us | 推荐到鲜果

相关文章 随机文章

本文Tags: ,

没有评论


(Required)
(Required, will not be published)