MySQL数据库之mysql-proxy做客户端连接转发【外网访问内网mysql】
小标 2018-08-17 来源 : 阅读 3698 评论 0

摘要:本文主要向大家介绍了MySQL数据库之mysql-proxy做客户端连接转发【外网访问内网mysql】 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。

本文主要向大家介绍了MySQL数据库之mysql-proxy做客户端连接转发【外网访问内网mysql】 ,通过具体的内容向大家展现,希望对大家学习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=                             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
应用
./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)等,更多功能以后再研究。

本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 2 不喜欢 | 2
看完这篇文章有何感觉?已经有4人表态,50%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程