Nginx --with-stream 数据库访问代理

说明

安装配置nginx,支持oracle数据库的访问。 oracle做dataguard,当主库异常,备库切换为主库时,nginx指向切换后的主库,上层应用不需更改数据库连接字符串。

服务器环境

CentOS 7

安装Nginx

按照官网说明进行安装
https://nginx.org/en/linux_packages.html

Install the prerequisites:

yum install yum-utils

To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

To install nginx, run the following command:

yum install nginx

配置 Stream

参考Nginx安装并配置stream详细教程(https://blog.csdn.net/qq_42703181/article/details/119422790)

查看并记录 nginx 配置参数

[root@oracle-nginx ~]# nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

下载nginx包

yum install weget
cd /opt
wget https://nginx.org/download/nginx-1.24.0.tar.gz
tar -zxvf nginx-1.24.0.tar.gz && cd nginx-1.24.0
mv /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx  /etc/nginx.bak 

安装依赖项

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++   openssl-devel cmakepcre-develnanowget  gcc gcc-c++ ncurses-devel per redhat-rpm-config.noarch

对记录下来的nginx 配置参数 增加 --with-stream

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'  --with-stream 

make 一下

make

验证与nginx文件cp

/opt/nginx-1.24.0/objs/nginx -t
/opt/nginx-1.24.0/objs/nginx -v

cp /opt/nginx-1.24.0/objs/nginx  /usr/sbin/ 

启动Nginx

systemctl  start nginx

Nginx状态查询

systemctl status nginx.service

Oracle 访问配置

防火墙开启端口

firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --zone=public --add-port=7777/tcp --permanent
systemctl start firewalld.service
[root@oracle-nginx nginx-1.24.0]# firewall-cmd --reload
success
[root@oracle-nginx nginx-1.24.0]# firewall-cmd --list-ports

/etc/nginx/nginx.conf 配置更新

stream {    
    
    # 主库
    upstream oracle_primary {   
        server 192.168.18.66:1521; 
    }
    
    server {
        listen       8888;
        proxy_connect_timeout 60s;
        proxy_timeout 60s;
        proxy_pass oracle_primary;
    }
   
    
    # 备库
    upstream oracle_standby {   
        server 192.168.18.88:1521 ;  
    }
    
    server {
        listen       7777;#  
        #proxy_connect_timeout 60s;
        #proxy_timeout 60s;
        proxy_pass oracle_standby;
    }
}

Nginx重载

nginx -s reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx是一种高性能的Web服务器和反向代理服务器软件,可以在Linux、Windows、UNIX等操作系统上运行。它以其稳定性、高并发性和低内存消耗而受到广泛关注和使用。 nginx 1.18是nginx的一个版本,其中包含了一系列的新特性和改进。这个版本引入了新的HTTP/2服务器推送功能,提供了更好的性能和可扩展性。同时,该版本还增加了对TLS 1.3的支持,加强了传输层安全性。此外,nginx 1.18还改进了负载均衡算法,提高了对后端服务器的请求分发效率。总之,nginx 1.18在性能、安全性和功能上都有所提升,是一个值得使用的版本。 nginx-mod-stream是一个nginx模块,用于处理TCP/UDP流量。它提供了一系列的功能,如四层(网络层)和七层(应用层)的负载均衡、流量分片、数据重定向等。通过使用nginx-mod-stream,我们可以在一个单独的nginx服务器上同时处理HTTP和TCP/UDP流量,增加了服务器的灵活性和可扩展性。 通过将nginx 1.18和nginx-mod-stream结合使用,我们可以构建一个强大的、高性能的网络架构。nginx 1.18提供了优秀的HTTP服务和反向代理能力,而nginx-mod-stream则提供了处理TCP/UDP流量的功能。这样可以让我们的应用程序更加灵活,在一个服务器上同时处理不同类型的流量,提高服务器的利用率和性能。因此,nginx 1.18和nginx-mod-stream是两个重要的组件,能够帮助我们构建高效的网络架构。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值