On this page
HAProxy Logging in Ubuntu Lucid. But getting HAProxy to log on Ubuntu Lucid was harder than I thought. All of the tutorials I found either didn't cover logging,. Now we have to create the file 'check.txt' (this file can be empty) within the document root of the first vhost. Touch /var/www/haproxy/check.txt Afterwards the configuration of the web servers is completed - restart the web servers. Haproxy logs can be enabled by adding the following in config file haproxy.cfg log 127.0.0.1 local0 The logs can be pushed into a separate file by creating a file in /etc/rsyslog.d.
- Setting Up A High-Availability Load Balancer (With Failover and Session Support) With HAProxy/Heartbeat On Fedora 8
- 1 Preparation
- 2 HTTP1 & HTTP2
- You should also update the log path in /etc/logrotate.d/haproxy to the new path. So that it will rotate and compress logfile in newly configured path using gzip. Then restart rsyslog.service. Sudo systemctl restart rsyslog.service Now haproxy.log.* file will be in /var/log/haproxy/ directory.
- One can see how HAProxy is working using Services -> HAProxy -> Stats or Stats FS (full screen). One can also navigate to Status -> HAProxy Stats for the full screen view. Step 5 – Enable HAProxy stats. HAProxy has a nice function to see how the proxy is performing. It can also tell you if health checks are failing. If they are, check Step 3 to fix.
- I have some question about log level in haproxy. Using haproxy, on the backend there is a database. I need to log errors in a separate file, but cant understand how to do that.
Setting Up A High-Availability Load Balancer (With Failover and Session Support) With HAProxy/Heartbeat On Fedora 8
Version 1.0
Author: Oliver Meyer <o [dot] meyer [at] projektfarm [dot] de>
This document describes how to set up a two-node load balancer in an active/passive configuration with HAProxy and heartbeat on Fedora 8. The load balancer acts between the user and two (or more) Apache web servers that hold the same content. The load balancer passes the requests to the web servers and it also checks their health. If one of them is down, all requests will automatically be redirected to the remaining web server(s). In addition to that, the two load balancer nodes monitor each other using heartbeat. If the master fails, the slave becomes the master - users won't notice any disruption of the service. HAProxy is session-aware - you can use it with any web application that makes use of sessions like forums, shopping carts, etc.
From the HAProxy web site: 'HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net.'
This howto is a practical guide without any warranty - it doesn't cover the theoretical backgrounds. There are many ways to set up such a system - this is the way I chose.
1 Preparation
For this howto I set up four Fedora 8 systems (minimal installation without gui etc.) with the following configuration:
1.1 Load Balancer 1
Hostname: lb1.example.com
IP: 192.168.0.110
Shared IP: 192.168.0.120
1.2 Load Balancer 2
Hostname: lb2.example.com
IP: 192.168.0.111
Shared IP: 192.168.0.120
1.3 Web Server 1
Hostname: http1.example.com
IP: 192.168.0.112
1.4 Web Server 2
Hostname: http2.example.com
IP: 192.168.0.113
1.5 Overview
+-----------------+
| 192.168.0.120 |
| Shared IP |
+--------+--------+
|
+----------------------+
| |
+--------+--------+ +--------+--------+
| 192.168.0.110 | | 192.168.0.111 |
| Load Balancer 1 | | Load Balancer 2 |
+--------+--------+ +--------+--------+
+--------+--------+ +--------+--------+
| 192.168.0.112 | | 192.168.0.113 |
| Web Server 1 | | Web Server 2 |
+-----------------+ +-----------------+
2 HTTP1 & HTTP2
2.1 Firewall Configuration
In order that the webservers are accessible from outside you have to open the corresponding ports on both web servers.
Haproxy Log Level
Set HTTP & HTTPS as trusted service as shown on the screenshot below and save the settings.
2.2 Apache Configuration
HAProxy will work as a transparent proxy - so the user's IP address will be passed in the field 'X-Forwarded-For' to the web servers. In order that the web servers will log the user's IP address and not the IP addresses of the load balancers we have to modify the log format within the apache configuration file on both web servers.
Haproxy Log File Empty File
Search the Lines that begin with 'LogFormat' ...
... and replace '%h' with '%{X-Forwarded-For}i'. The content should look like this:
We'll configure HAProxy to check the web servers' health by continuously requesting the file 'check.txt' from the web servers. To keep the logs small, we'll customize the first vhost on each web server (HAProxy will use the web servers' IP adresses to request the file - so the first vhost will answer the request) to ensure that the access to 'check.txt' won't be logged. In this example the vhosts are configured in '/etc/httpd/conf.d/vhosts.conf'.
Add the following line to the configuration of your first vhost ...
... and add the exception (env=!dontlog) to the line for the CustomLog. For example, the configuration for the first vhost could look like this:
Haproxy Log Location
Now we have to create the file 'check.txt' (this file can be empty) within the document root of the first vhost.
Afterwards the configuration of the web servers is completed - restart the web servers.