Transloadit

  • Demos
  • Docs & Help
  • Press
  • Pricing & Signup
hello@transloadit.comCall usBlogLogin

    HAProxy logging

    • Posted on 12. Aug 2010 at 08:26 UTC by Kevin van Zonneveld

    At transloadit we use HAProxy "The Reliable, High Performance TCP/HTTP Load Balancer" so that we can offer different services on 1 port. For instance, depending on the hostname, a requests to port 80 can be routed to either nodejs (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 was harder than I thought. All of the tutorials I found either didn't cover logging, or had deprecated information on it.
    Google suddenly stopped being my friend.

    HAProxy wants to log

    For performance & maintenance reasons HAProxy doesn't log directly to files. Instead it wants to log against a syslog server. This is a separate Linux daemon that most servers are equiped with already, but HAProxy requires it to listen on UDP port 514, and usually that's not enabled.

    A syslog server:

    • receives log entries
    • decides what's interesting
    • writes it to disk in a highly optimized way

    these aspect can all be configured by you.

    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 Unbuntu Lucid the default syslog daemon is rsyslogd, so let's make it accept HAProxy log entries.

    rsyslogd welcomes HAProxy

    Most google hits I found on logging with HAProxy told me to change the /etc/default/rsyslog file, but that's completely ignored with the new upstart system. And even if you make it adhere the defaults file (yep, I tried), it will make rsyslogd go down in compatibility mode. Which is not only a shame, but also unnecessary as it turns out.

    Using these config lines:

    $ModLoad imudp
    $UDPServerRun 514
    

    rsyslogd will open up it's UDP port.

    Where to put these lines you say? Well, if HAProxy is the only service you need the UDP syslog port for, you could put/uncomment the lot in just one /etc/rsyslog.d/haproxy.conf file:

    # .. 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:

    restart rsyslog
    

    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 /etc/haproxy/haproxy.cfg.

    Happy logging!

    --kvz

  • Our jQuery plugin is now open source!
  • Does your image scaling software suck?

Comments

Transloadit Product Blog

Subscribe and read about:

  • Bootstrapping a startup
  • Developing with node.js
  • New Features & Updates

You can also follow @transloadit on twitter and facebook:

Recent Blogposts

  • New resize strategy "fillcrop" and notification duration available
  • UK-based Rackspace auth and multi-url http import
  • We added the ability to retry notifications
  • YouTube Robot released!
  • New Pricing

Archive

  • February 2012 (2)
  • January 2012 (5)
  • December 2011 (2)
  • November 2011 (2)
  • October 2011 (0)
  • September 2011 (0)
  • August 2011 (1)
  • July 2011 (3)
  • June 2011 (2)
  • May 2011 (6)
  • April 2011 (2)
  • March 2011 (3)
  • February 2011 (0)
  • January 2011 (3)
  • December 2010 (3)
  • November 2010 (3)
  • October 2010 (1)
  • September 2010 (0)
  • August 2010 (1)
  • July 2010 (5)
  • About
  • Blog
  • Follow us on Facebook
  • Follow us on Twitter
  • Email
  • Imprint
  • Privacy policy
  • Terms of service