使用 Nginx 转发 Oracle 端口

问题背景
某客户V3环境应用服务器想要连通V2环境Oracle数据库进行数据存储,解决办法是在V2环境搭建一台带nginx的ECS用来端口转发。

原理图:
_20180401214328

环境
• OS: Centos
• Nginx: 1.12.1

编译安装Nginx
从1.9.0开始,nginx就支持对TCP的转发,而到了1.9.13时,UDP转发也支持了。提供此功能的模块为ngx_stream_core。不过Nginx默认没有开启此模块,所以需要手动安装。

cd /usr/local/src
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --with-stream --without-http
make && make install

配置Nginx
TCP转发
目标:通过3000端口访问本机Mysql(其中mysql使用yum安装,默认配置文件)
/usr/local/nginx/conf/nginx.conf配置如下:

user  nobody;
worker_processes  auto;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

stream {
    upstream cloudsocket {
       hash $remote_addr consistent;
       server 192.168.0.7:1521 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 3000;#公网机器监听端口
       proxy_connect_timeout 1s;
       proxy_timeout 3s;
       proxy_pass cloudsocket;
    }
}

首先,先通过1521端口访问oracle:

222

然后,启动Nginx:
333

最后使用3000端口访问mysql:

安装过程中可能遇到的问题
安装nginx的时候遇到如下问题:

1.    Configuration summary  
2.      + using system PCRE library  
3.      + OpenSSL library is not used  
4.      + using builtin md5 code  
5.      + sha1 library is not found  
6.      + using system zlib library

出现以上问题的原因是,在安装nginx的时候没有指定openssl的解压路径。正确的做法如下:

./configure --prefix=/usr/local/nginx  --with-openssl=/usr/local/openssl-1.0.1j --with-http_ssl_module

如果pcre和zlib出现类似的问题,指定路径就可。

--with-pcre=/usr/local/pcre-7.7 --with-zlib=/usr/local/zlib-1.2.3 --with-http_stub_status_module

该架构存在的问题以及解决方式
该架构虽然解决了 V3环境 无法直接连通V2环境,但是通过代理转发,也存在一定问题,例如单点故障问题,若代理服务器负载过高,会影响整个架构的运行。
解决方式是,在代理服务器层增加SLB负载均衡,可在一定程度上解决此问题。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值