nginx udp proxy and load balancing

参考:
 
[root@promote sbin]# ./nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
 
[root@promote conf]# cat nginx.conf
user root;
worker_processes auto;
error_log   logs/error.log error;
#error_log   logs/error.log info;
pid        logs/nginx.pid;
worker_rlimit_nofile 655350;
 
events
{
    use epoll;
    worker_connections 65535;
    multi_accept on;
    accept_mutex on;
}
stream {
    upstream agent {
        hash $remote_addr consistent;
        server 192.168.30.103:8004 max_fails=5 fail_timeout=30s;
        server 192.168.30.104:8004 max_fails=5 fail_timeout=30s;
        server 192.168.30.105:8004 max_fails=5 fail_timeout=30s;
    }
 
        server {
        listen 8004 udp;
        proxy_timeout 30s;
        proxy_responses 0;
        proxy_buffer_size 4096k;
        proxy_bind $remote_addr:$remote_port transparent;
        #proxy_bind $remote_addr transparent;      #获取真实源IP?
        proxy_pass agent;
    }
 
    log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
 
    access_log /usr/local/nginx/logs/tcp-access.log proxy ;
    open_log_file_cache off;
    #include /usr/local/nginx/conf/servers/*.stream;
    #include /usr/local/nginx/conf/*.conf;
}
 
 
抓包:# tcpdump udp -i eno3 port 8004
 
 
Sets the number of datagrams expected from the proxied server in response to a client datagram if the UDP protocol is used. The number serves as a hint for session termination. By default, the number of datagrams is not limited.
 
如果使用UDP协议,则根据客户端数据报的响应,设置来自proxied服务器的datagram的数量。这个数字作为会话终止的提示。默认情况下,datagram的数量并不受限制。
 
 
测试结果:
用于udp转发无法同时兼顾tcp的转发请求。proxy_responses 设置为1的时候,测试存在转发的报文数量存在丢失的情况。将其设置为0,同时增加了 proxy_buffer_size ,测试基本正常。
 
 

转载于:https://www.cnblogs.com/wplvqj/p/10536580.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值