一个朋友要用Nginx代理MySQL(MySQL局域网),不用VPN,不用NAT映射... Nginx版本:1.9.x(持tcp的负载均衡,nginx_tcp_proxy_module(姚伟斌阿里团队也可以实现)) Nginx官方模块:ngx_stream_core_module --with-stream_ssl_module(ssl协议支持,比如MySQL ssl) 官网:http://nginx.org/en/docs/stream/ngx_stream_core_module.html 1、查看现有编译 --user=nginx--group=nginx--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module--with-http_realip_module--with-http_flv_module--with-http_mp4_module--with-http_gzip_static_module 2、重新编译: --user=nginx--group=nginx--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module--with-http_realip_module--with-http_flv_module--with-http_mp4_module--with-http_gzip_static_module--with-stream--with-stream_ssl_module 注意:--with-stream --with-stream_ssl_module 3、配置、检测、重启nginx: 配置: stream{ upstreammysql{ zonemyapp164k; serverlocalhost:3306weight=1max_fails=3fail_timeout=30s; #server192.168.1.221:3306weight=1max_fails=2fail_timeout=30s; } server{ listen2188; proxy_connect_timeout1s; proxy_timeout3s; proxy_passmysql; } } 检测: [root@autoCentos67X64conf]#nginx-t nginx:theconfigurationfile/usr/local/nginx/conf/nginx.confsyntaxisok nginx:configurationfile/usr/local/nginx/conf/nginx.conftestissuccessful [root@autoCentos67X64conf]# 启动: [root@autoCentos67X64conf]#netstat-atupn|grepnginx tcp000.0.0.0:21880.0.0.0:*LISTEN2359/nginx [root@autoCentos67X64conf]# 4、验证:(转载请保留:renzhiyuan.blog.51cto.com) [root@log~]#mysql-uroot-prenzhiyuan-h192.168.1.11-P2188 WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis3 Serverversion:5.6.21-logMySQLCommunityServer(GPL) Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|