Nginx stream(TCP/UDP)负载均衡

Posted 丹西

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx stream(TCP/UDP)负载均衡相关的知识,希望对你有一定的参考价值。

Nginx-1.11.6编译安装


nginx编译安装,(平台:ubuntu 14.04);
sudo apt-get install zlib1g-dev
sudo apt-get install libpcre++-dev
sudo apt-get install openssl

然后configure: --with-stream 支持TCP/UDP负载均衡
cd nginx-1.11.6/
./configure --with-stream --prefix=/home/trait/nginx
make & make install

Nginx stream UDP负载均衡配置


nginx udp负载均衡配置:
[email protected]:/home/trait/nginx/sbin# cat ../conf/nginx.conf

#user  nobody;
worker_processes  1;

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

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

stream {
    
    upstream dns {
       server 192.168.111.99:10086;
       server 192.168.111.100:10086;
    }

    server {
        listen 192.168.111.98:10086 udp;
        proxy_responses 1;
        proxy_timeout 20s;
        proxy_bind $server_addr:$remote_port;
        proxy_pass dns;
    }
}

以上是关于Nginx stream(TCP/UDP)负载均衡的主要内容,如果未能解决你的问题,请参考以下文章

Nginx stream 配置代理(Nginx TCP/UDP 负载均衡)

使用nginx做 tcp/udp 负载均衡

Nginx TCP代理和负载均衡

Nginx之数据流代理stream模块简介和使用

Nginx作为负载均衡服务介绍

使用nginx 4层转发 stream模块实现dnsmasq负载均衡