At Transloadit, we use HAProxy "The Reliable, High Performance TCP/HTTP Load Balancer", so that we can offer different services on one port. For instance, depending on the hostname, a request to port 80 can be routed to either Node.js (in case of api.transloadit.com) or Nginx (in case of www.transloadit.com). HAProxy has been good to us and setting it up was a breeze. But getting HAProxy to log on Ubuntu Lucid has proven harder than I thought. All of the tutorials I found either didn't cover logging or contained deprecated information. Google suddenly stopped being my friend.
HAProxy Wants to Log
For performance and maintenance reasons, HAProxy doesn't log directly to files. Instead, it wants to log to a syslog server. This is a separate Linux daemon with which most servers are already equipped. HAProxy, however, requires it to listen on UDP port 514 and that is usually not enabled.
A syslog server receives log entries, decides which ones are interesting and writes those to disk in a highly optimized manner. These aspect can all be configured to your liking.
If we look at the top of your current
/etc/haproxy/haproxy.cfg file, we may find something like:
global maxconn 10000 ulimit-n 65536 log 127.0.0.1 local0 log 127.0.0.1 local1 notice
As you can see,
127.0.0.1 is where it will try to find a syslog server to log to.
On Ubuntu Lucid, the default syslog daemon is rsyslogd,
so let's make that one accept HAProxy log entries.
Rsyslogd Welcomes HAProxy
The majority of Google results that cover logging with HAProxy told me to change the
/etc/default/rsyslog file, but
that file is now completely ignored under the new upstart system.
Moreover, even if you make HAProxy adhere to the default file (yep, I tried), it will force rsyslogd into compatibility mode. That is not only a shame, but also unnecessary as it turns out.
By using the following config lines:
$ModLoad imudp $UDPServerRun 514
rsyslogd will open up its UDP port.
Where to put these lines, you say? Well, if you are only using the UDP syslog port for the HAProxy service, you can put/uncomment the lot in just
# .. otherwise consider putting these two in /etc/rsyslog.conf instead: $ModLoad imudp $UDPServerRun 514 # ..and in any case, put these two in /etc/rsyslog.d/haproxy.conf: local0.* -/var/log/haproxy_0.log local1.* -/var/log/haproxy_1.log
Now do a quick:
And you're done. Check for HAProxy logs in:
tail -f /var/log/haproxy*.log
And don't forget to tweak the debug level in
Share your Transloadit project to earn $300
We love seeing how our community uses Transloadit. Tweet @transloadit to get your proposal approved, share what you’ve built in the form of a blog post or a tutorial on your website, and earn a $300 Gift certificate of your choice as well as a full year of the Startup Plan, at no cost after you publish.
Follow us on Twitter:Follow @transloadit
We're SO STOKED to announce the Transloadit Community Plan! 🎉🎉🎉 Unlimited uploading, importing and exporting, 5GB of encoding/month, and access to 50 different file conversion features for all.— 🤖 Transloadit (@transloadit) July 2, 2020
Best part? It's free. Forever. 🤑 Find out more https://t.co/zXWLi3Xa0G pic.twitter.com/DlY5xz1mPG