赞
踩
Module ngx_stream_upstream_module
nginx的upstream模块,主要完成网络数据的接收、处理和转发,是做负载均衡的关键。下面介绍几种常见的负载分配算法。
Nginx TCP和UDP负载均衡 - osc_g6d2xdbw的个人空间 - OSCHINA - 中文开源技术交流社区
TCP and UDP Load Balancing | NGINX Plus
Nginx支持TCP端口转发_Viman的运维专栏-CSDN博客_nginx tcp转发
vim /etc/nginx/nginx.conf
- user nginx;
- worker_processes 1;
- error_log /var/log/nginx/error.log warn;
- pid /var/run/nginx.pid;
- events {
- worker_connections 1024;
- }
- http {
- .................
- }
-
- # tcp层转发的配置文件夹
-
- include /etc/nginx/tcp.d/*.conf;
vim /etc/nginx/tcp.d/6379.conf
- stream {
- # 添加socket转发的代理
- upstream socket_proxy {
- hash $remote_addr consistent;
- # 转发的目的地址和端口
- server 192.168.1.100:9000 weight=5 max_fails=3 fail_timeout=30s;
- }
-
- # 提供转发的服务,即访问localhost:9001,会跳转至代理socket_proxy指定的转发地址
- server {
- listen 9001;
- proxy_connect_timeout 1s;
- proxy_timeout 3s;
- proxy_pass socket_proxy;
- }
- }
重启nginx,
nginx -t 验证语法错误.
nginx -s reload
多个端口时
- i2# cat /etc/nginx/tcp.d/6379.conf
- stream {
- # user root;
- upstream socket_proxy {
- hash $remote_addr consistent;
- # server 192.168.111.141:6666 weight=5 max_fails=3 fail_timeout=30s;
- server app1-svc.vm-root.svc:6666 weight=5 max_fails=3 fail_timeout=30s;
- }
- server {
- listen 6666;
- proxy_connect_timeout 1s;
- proxy_timeout 3s;
- proxy_pass socket_proxy;
- # proxy_bind $remote_addr transparent;
- #proxy_bind 192.168.111.140:6666 transparent;
- # proxy_bind app1-svc.vm-root.svc transparent;
- }
- upstream socket_proxy_redis {
- hash $remote_addr consistent;
- # server 192.168.111.141:6666 weight=5 max_fails=3 fail_timeout=30s;
- server app1-svc.vm-root.svc:6379 weight=5 max_fails=3 fail_timeout=30s;
- }
- server {
- listen 6379;
- proxy_connect_timeout 1s;
- proxy_timeout 3s;
- proxy_pass socket_proxy_redis;
- }
- }
- root@ubuntu:/home/anji2#
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。