Protocol support
Load balance syslog messages
Available since:
- HAProxy 2.9
- HAProxy ALOHA 16.0
- HAProxy Enterprise 2.9r1
Forwarding vs load balancing
This page describes how to load balance messages to multiple Syslog servers. If instead you would like to forward messages to a single, remote server, see Syslog forwarding.
You can load balance syslog traffic across a pool of backend servers by using a log backend. A log backend is a backend configuration section that specifies mode log.
Use a log backend in combination with a log-forward section to receive messages and load balance them across servers. To define a backend as a log backend:
- Specify
mode log. - Use the
balancedirective to specify the load balancing algorithm for a log backend. You can specify one ofroundrobin,random,log-hash, orsticky. - List the log servers that should receive log messages.
Log backends support common backend and server features but do not support the HTTP and TCP related features.
Buffer size for logs
To tune the buffer size of the implicit ring associated with the log backend, use the log-bufsize argument on a server line. A larger value for this setting will increase memory usage but can help to prevent loss of log messages.
Load balance syslog over UDP Jump to heading
To load balance syslog over UDP, the log-forward section must bind using the dgram-bind directive. In the backend section, the log server address must be prefixed with the udp@ string.
Example:
haproxylog-forward syslogdgram-bind :5144log backend@mylog-rrb local0backend mylog-rrbmode logbalance roundrobinserver log1 udp@172.31.42.75:3514server log2 udp@172.31.41.76:3514
haproxylog-forward syslogdgram-bind :5144log backend@mylog-rrb local0backend mylog-rrbmode logbalance roundrobinserver log1 udp@172.31.42.75:3514server log2 udp@172.31.41.76:3514
For this example, we’ve specified local0 on the log line, so be sure to configure your remote syslog servers to expect logs with the facility code local0. Below is an example portion of an rsyslog configuration that you could apply to save incoming messages to a file named example.log:
rsyslog.conftextlocal0.* /var/log/myapp/example.log
rsyslog.conftextlocal0.* /var/log/myapp/example.log
There is no way to enable a health check for a UDP syslog service. Instead, you can enable TCP checks or agent checks and configure your service to respond to those checks. See Health checks.
Load balance syslog over TCP Jump to heading
Load balancing syslog over TCP is more reliable than UDP and should work well for the majority of users. However, its performance is generally lower due to extra copies and queuing costs.
To load balance syslog over TCP, the log-forward section must bind using the bind directive.
Example:
haproxylog-forward syslogbind :5144log backend@mylog-rrb local0backend mylog-rrbmode logbalance roundrobinserver log1 172.31.42.75:3514server log2 172.31.41.76:3514
haproxylog-forward syslogbind :5144log backend@mylog-rrb local0backend mylog-rrbmode logbalance roundrobinserver log1 172.31.42.75:3514server log2 172.31.41.76:3514
For this example, we’ve specified local0 on the log line, so be sure to configure your remote syslog servers to expect logs with the facility code local0. Below is an example portion of an rsyslog configuration that you could apply to save incoming messages to a file named example.log:
rsyslog.conftextlocal0.* /var/log/myapp/example.log
rsyslog.conftextlocal0.* /var/log/myapp/example.log
You can enable health checks for the log servers in a TCP syslog service. See Health checks.
Assign weights to servers Jump to heading
Available since
- HAProxy 3.0
- HAProxy ALOHA 16.5
- HAProxy Enterprise 3.0r1
To send more traffic to some servers than other servers, assign weights to each server. A higher weight means more traffic will go to that server.
Example:
haproxybackend mylog-rrbmode logbalance roundrobinserver log1 udp@172.31.42.75:3514 weight 20server log2 udp@172.31.41.76:3514 weight 10
haproxybackend mylog-rrbmode logbalance roundrobinserver log1 udp@172.31.42.75:3514 weight 20server log2 udp@172.31.41.76:3514 weight 10
Here, the log1 server will receive twice as much traffic as the log2 server.
Change log parsing Jump to heading
This section applies to:
- HAProxy 3.2 and newer
- HAProxy Enterprise 3.2r1 and newer
As syslog messages pass through the load balancer, parsing and validation occurs. Add the following directives to the log-forward section if you want to change the default behavior:
| Directive | Description |
|---|---|
option assume-rfc6587-ntf |
Always assumes non-transparent framing, even if the frame lacks the expected < character. |
option dont-parse-log |
Relay syslog messages without attempting to parse or restructure them. Use this to accommodate clients that send syslog messages that don’t strictly conform to the RFC3164 and RFC5424 specifications. When you use this setting, also set format raw on the log directive to preserve the original message content. |
option host |
Set option host <strategy> where the strategy is replace, fill, keep, or append. This lets you preserve or change the HOSTNAME field on the syslog message. Changing HOSTNAME can help syslog servers to filter messages and write to the correct log file. |
See also Jump to heading
- To set the load balancer algorithm, see balance.
- To create a log forwarder proxy, see log forwarding.
- To specify the type of traffic, see mode reference.
- To set the relative weight of a server for load balancing purposes, see weight reference.
Do you have any suggestions on how we can improve the content of this page?