脚踏实地云 mysql-proxy做客户端连接转发【外网访问内网mysql】

功能
用于外网客户端连接内网的MySQL,将此工具安装在中转服务器上。
软件版本
mysql-proxy-0.8.1-linux-rhel5-x86-64bit.tar.gz
简单的配置过程
解压后有5个目录
bin  include  lib  libexec  share
进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=<host:port>                             listening address:port of the admin-server (default: :4041)
  --admin-username=<string>                               username to allow to log in
  --admin-password=<string>                               password to allow to log in
  --admin-lua-script=<filename>                           script to execute by the admin plugin
 
proxy-module
  -P, --proxy-address=<host:port>                         listening address:port of the proxy-server (default: :4040)
  -r, --proxy-read-only-backend-addresses=<host:port>     address:port of the remote slave-server (default: not set)
  -b, --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
  -s, --proxy-lua-script=<file>                           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=<file>                                  configuration file
  --verbose-shutdown                                      Always log the exit code when shutting down
  --daemon                                                Start in daemon-mode
  --user=<user>                                           Run mysql-proxy as user
  --basedir=<absolute path>                               Base directory to prepend to relative paths in the config
  --pid-file=<file>                                       PID file in case we are started as daemon
  --plugin-dir=<path>                                     path to the plugins
  --plugins=<name>                                        plugins to load
  --log-level=(error|warning|info|message|debug)          log all messages of level ... or higher
  --log-file=<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
应用
./mysql-proxy --admin-username='root'  --admin-password='12345' --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服务器地址和端口、服务模式
测试
# 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)等,更多功能以后再研究。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值