【nginx】用stream模块实现TCP端口转发

一、实验目的

将本机的6033端口转发至本机3306

 

二、安装

# yum  -y install  maridb*  nginx

 

 三、配置

设置selinux为宽松模式

# setenforce 0

# sed -i 's/^SELINUX=.*/SELINUX=permissive/g'   /etc/selinux/config

 

# systemct start maridb

# systemct enable maridb 

# mysql_secure_installation

 

# vim  /etc/nginx/nginx.conf

####################################################

# For more information on configuration, see:

#   * Official English Documentation: http://nginx.org/en/docs/

#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {

    worker_connections 1024;

}

stream {

    proxy_timeout 30m;

    server {

        listen 192.168.1.104:6033;

        proxy_pass 127.0.0.1:3306;

    }

}

######################################################

 

# systemctl  start nginx

# systemctl  enable nginx 

# systemctl  status  nginx

 

四、测试

#  mysql  -u root  -p"MySQL@123"

#  mysql  -u root -P 6033 -p"MySQL@123"

 

五、参考

 

nginx启用stream日志配置文件

https://www.cnblogs.com/cheyunhua/p/8823496.html

利用nginx的stream模块实现内网端口的转发代理

https://blog.51cto.com/icenycmh/2117844

Module ngx_stream_core_module

http://nginx.org/en/docs/stream/ngx_stream_core_module.html

Nginx基于TCP/UDP端口的四层负载均衡(stream模块)配置梳理

https://cloud.tencent.com/developer/article/1027563

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值