Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1863338
  • 博文数量: 117
  • 博客积分: 2559
  • 博客等级: 少校
  • 技术积分: 4385
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-13 20:08
个人简介

作为初学者,要想取得进步,成为高手,首先应该了解自己的不足之处.

文章分类

全部博文(117)

文章存档

2014年(1)

2013年(25)

2012年(13)

2011年(77)

2010年(1)

分类: Mysql/postgreSQL

2011-05-23 13:36:19

功能

用于外网客户端连接内网的MySQL,将此工具安装在中转服务器上。

软件版本

mysql-proxy-0.8.1-linux-rhel5-x86-64bit.tar.gz

简单的配置过程

  1. 解压后有5个目录

bin  include  lib  libexec  share

  1. bin目录,查看mysql_proxy的使用帮助

[root@ora01 bin]# ./mysql-proxy --help-all

Usage:

  mysql-proxy [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=                             listening address:port of the admin-server (default: :4041)

  --admin-username=                               username to allow to log in

  --admin-password=                               password to allow to log in

  --admin-lua-script=                           script to execute by the admin plugin

 

proxy-module

  -P, --proxy-address=                         listening address:port of the proxy-server (default: :4040)

  -r, --proxy-read-only-backend-addresses=     address:port of the remote slave-server (default: not set)

  -b, --proxy-backend-addresses=               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

  -s, --proxy-lua-script=                           filename of the lua script (default: not set)

  --no-proxy                                              don't start the proxy-module (default: enabled)

  --proxy-pool-no-change-user                             don't use CHANGE_USER to reset the connection coming from the pool (default: enabled)

 

Application Options:

  -V, --version                                           Show version

  --defaults-file=                                  configuration file

  --verbose-shutdown                                      Always log the exit code when shutting down

  --daemon                                                Start in daemon-mode

  --user=                                           Run mysql-proxy as user

  --basedir=                               Base directory to prepend to relative paths in the config

  --pid-file=                                       PID file in case we are started as daemon

  --plugin-dir=                                     path to the plugins

  --plugins=                                        plugins to load

  --log-level=(error|warning|info|message|debug)          log all messages of level ... or higher

  --log-file=                                       log all messages in a file

  --log-use-syslog                                        log all messages to syslog

  --log-backtrace-on-crash                                try to invoke debugger on crash

  --keepalive                                             try to restart the proxy if it crashed

  --max-open-files                                        maximum number of open files (ulimit -n)

  --event-threads                                         number of event-handling threads (default: 1)

  --lua-path=<...>                                        set the LUA_PATH

  --lua-cpath=<...>                                       set the LUA_CPATH

  1. 应用

./mysql-proxy --admin-username=root  --admin-password='' --admin-lua-script=/opt/mysql-proxy-0.8.1-linux-rhel5-x86-64bit/lib/mysql-proxy/lua/admin.lua --proxy-backend-addresses=192.168.60.134:3306 --daemon

参数说明:

指定MySQL的用户名和密码、执行mysql-proxy工具的脚本、mysql服务器地址和端口、服务模式

  1. 测试

# netstat -tunlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  

tcp        0      0 0.0.0.0:4040                0.0.0.0:*                   LISTEN      29237/mysql-proxy  

tcp        0      0 0.0.0.0:4041                0.0.0.0:*                   LISTEN      29237/mysql-proxy  

4040端口是默认的代理端口,客户端连接的时候直接指向此端口

4041是默认的管理模块端口

总结:现在就可以连接中转服务器的4040端口,访问内网的MySQL服务器。除了可以进行连接的转发外,还可以进行查询的监控、过滤、分析、负载均衡(Load Balance)、失败漂移(Failover)等,更多功能以后再研究。

阅读(3773) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~