使用 nginx 进行 UDP 转发

UDP forwarding with nginx

我有一个主系统日志服务器,它从多个来源接收系统日志,我想将这些日志发送到 Graylog 集群。为了帮助集群跟上(在一些慢速虚拟机上),我需要能够将消息负载平衡到 Graylog,因为有时它们来自端点的大量块(有些每 10 秒突发发送 5k 日志)。

我正在尝试使用 nginx 作为 syslog 消息的负载平衡器,但我似乎无法让它工作,这似乎是因为 nginx 正在寻找来自 Graylog 服务器的响应。使用 UDP,它不会得到响应。至少这是我认为正在发生的事情。

我得到的错误是:

2016/12/01 11:27:59 [error] 2816#2816: *210325 no live upstreams while connecting 
  to upstream, udp client: 10.0.1.1, server: 0.0.0.0:11016, 
  upstream: "juniper_close_stream_backend", bytes from/to client:932/0, 
  bytes from/to upstream:0/0

作为我的 nginx.conf 中此规则的示例,它看起来像:

stream {
    server {
        listen 11016 udp;
        proxy_pass juniper_close_stream_backend;
    }
    upstream juniper_close_stream_backend {
        server 10.0.1.2:11016;
        server 10.0.1.3:11016;
        server 10.0.1.4:11016;
    }
}

在这种情况下,我的系统日志框是 10.0.1.1,我的下游 Graylog 框是 10.0.1.[2-4]。我看到所有这些错误消息。

有什么线索吗?当我在 Graylog 框上 运行 tcpdump 时,我看到来自负载均衡器的流量,这意味着它正在工作。但我认为 nginx 正在等待响应并给我一个错误。

所以这似乎确实是解决方案(在我上面的注释中)。

如果使用上面的示例,您希望它看起来像:

 stream {
     server {
         listen 11016 udp;
         proxy_pass juniper_close_stream_backend;
         proxy_responses 0;
     }
 }

这告诉 nginx 不要期待响应,它不需要来自 UDP 的响应。我不知道为什么他们 examples 在讨论完全由 UDP 驱动的 DNS 时不显示此信息。