• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to enable logging of haproxy in rsyslog

October 16, 2013 by Sharad Chhetri 11 Comments

After installing the HAproxy 1.4 in CentOS 6.4 bydefault logging of haproxy was not enable.To enable the logging of HAProxy you have to enable it in rsyslog(In CentOS 6.4 minimal installation,rsyslog version 5.2 is shipped).

To setup logging in HAproxy,follow the given below steps

Step 1: In Global Section of haproxy.cfg put the value log 127.0.0.1 local0 .Like given below

global
        log 127.0.0.1   local0

Step 2: Create new haproxy configuration file in /etc/rsyslog.d . Here we are keeping the log in localhost or in other words we should say HAproxy server

Note:

  • local0.=info -/var/log/haproxy.log defines the http log will be saved in haproxy.log
  • local0.notice -/var/log/haproxy-status.log defines the Server status like start,stop,restart,down,up etc. will be saved in haproxy-status.log
  • UDPServerRun 514 means opening UDP port no. 514 to listen haproxy messages
    vi /etc/rsyslog.d/haproxy.conf
    
    $ModLoad imudp
    $UDPServerRun 514 
    $template Haproxy,"%msg%n"
    local0.=info -/var/log/haproxy.log;Haproxy
    local0.notice -/var/log/haproxy-status.log;Haproxy
    ### keep logs in localhost ##
    local0.* ~ 
    

    Step 3: Now restart the HAproxy service

    /etc/init.d/haproxy restart
    

    After restarting the haproxy service two logs will be created itself i.e haproxy.log and haproxy-status.log

    Step 4: Check your logrotae file for haproxy also so that logs keep on rotating and compress itself. If bydefault it is not present in /etc/logrotate.d directory then create a new file called haproxy and paste the given below code.

    Here I am keeping the logs upto 120 days hence rotate 120 and daily is written in file.

    cat /etc/logrotate.d/haproxy
    
    /var/log/haproxy.log {
        missingok
        notifempty
        sharedscripts
        rotate 120
        daily
        compress
        postrotate
            reload rsyslog >/dev/null 2>&1 || true
        endscript
    }
    
    

    Share this:

    • Twitter
    • Facebook
    • More
    • Print
    • Email
    • LinkedIn
    • Reddit
    • Tumblr
    • Pinterest
    • Pocket
    • Telegram
    • WhatsApp
    • Mastodon

    Related posts:

    1. Install and configure rsyslog Centralized logging server in CentOS 6.5
    2. How to install and configure HAProxy 1.4.24 in CentOS 6
    3. How to enable logging in Postgresql 9.2 and 9.1
    4. Keep logs of user after sudo su – : Secondary Logging
    5. Secondary Logging : Save All Users History Command Output As Log
    6. Enable ethernet in RHEL 6.0 and CentOS 6.0 : Tested In Virtual Box and VMware
    7. Linux enable or disable multiple swap space
    8. Enable verbose mode while gem install of package
    9. Enable php5-imap on Ubuntu 14.04 LTS
    10. How to enable direct ssh to EC2 linux instance without keypair file
  • Filed Under: Linux Tagged With: haproxy, loadbalancer, logging, rsyslog

    Reader Interactions

    Comments

    1. kiduk says

      October 17, 2016 at 5:05 am

      postrotate
      reload rsyslog >/dev/null 2>&1 || true

      Dont you mean reload haproxy?

      Reply
      • scottsome says

        November 24, 2018 at 7:01 pm

        Nope. rsyslogd is the process writing the log, not haproxy.

        Reply
    2. Mahesh says

      May 13, 2016 at 8:11 am

      Along with HAProxy we would neet to restart rsyslog daemon also.

      [root@localhost ~ ]# /etc/init.d/rsyslog restart

      Reply
    3. Gary says

      February 8, 2016 at 10:35 am

      Great article thank you!

      As per
      https://www.percona.com/blog/2014/10/03/haproxy-give-me-some-logs-on-centos-6-5/

      Works perfectly, had to restart rsyslog to get the logs showing; I’m not sure if that’s specific to my distro, had me tearing my hair out ๐Ÿ™‚

      Reply
    4. Gerard says

      March 12, 2015 at 8:46 am

      On Debian (& alikes) the syslog configrutation needs a

      $UDPServerAddress 127.0.0.1

      before the “$UDPServerRun 514 ”

      and rsyslogd has to be started with the options “-c2 -r514” (the -r is not even in the man pages)

      Reply
    5. Mahesh Sawaiker says

      March 9, 2015 at 1:28 pm

      Awesome post, just what i needed. Thanks!!

      Reply
      • sharad chhetri says

        March 9, 2015 at 3:20 pm

        Thankyou Mahesh,

        Regards
        Sharad

        Reply
    6. Gerard says

      December 31, 2014 at 10:11 am

      reload rsyslog >/dev/null 2>&1 || true

      Why do you make sure nobody will ever notice if this command fails – which it does?

      Reply
      • sharad chhetri says

        December 31, 2014 at 1:14 pm

        Hello Gerard,

        The post is old, may I know which OS version you are using.

        Regards
        Sharad

        Reply
        • sharad chhetri says

          March 13, 2015 at 2:38 am

          Thankyou Gerard,

          Your suggestion is good.

          Regards
          Sharad

          Reply
    7. rc says

      February 13, 2014 at 11:24 pm

      Helpful. Thanks.

      Reply

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Primary Sidebar

    Our Social Media Presence

    • Facebook
    • GitHub
    • Twitter

    Linux Command

    What is Linux Internal And External Command

    Linux Basic Commands With Examples For Every Beginner

    tr command to convert lines to space , tab and vertical tab

    smbpasswd command not found on CentOS 7 and RHEL 7

    Solution : semanage command not found

    Unix / Linux : How to print duplicate lines from file

    More Posts from this Category

    You Might Like These Articles!

    simplecodesyntax wordpress plugin

    SimpleCodeSyntax : My Another WordPress Plugin

    Install Nginx

    How To Install Nginx On Ubuntu 22.04 LTS

    Install Latest Git package in Ubuntu Operating System

    How To Always Install Latest Git Package In Ubuntu Operating System

    Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

    Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

    libfuse

    dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

    Failed to open/create the internal network

    VirtualBox Error: Failed to open/create the internal network

    Always Useful Tips And Tricks

    Protect from w00tw00t.at.blackhats.romanian.anti-sec

    How to change smtp port number 25 in postfix

    error command ‘gcc’ failed with exit status 1 in Ubuntu

    4 Different commands to find system uptime in linux

    set and unset line number in file with vi editor

    GNU Screen

    The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form

    Explore 90+ Article On "Linux Tips And Tricks"

    Copyright © 2023 ยท
    The material in this site cannot be republished either online or offline, without our permission.
    Proudly Blogging From Bharat.

    • Contact
    • About Me
    • My WordPress plugins
    • Privacy Policy