Haproxy + keepalived load balancing custom-made log

Benefits of tailoring the output log

All user requests through the load balancer, thus collecting log in here than collected in the real back-end server logs then aggregated much more effective.

work goals

 record user access log: haproxy produce.
 Record keepalived log: keepalived start running, for debugging.

overall plan

  •  use a separate partition to store the log. Because less keepalived contents of the log can be shared storage space haproxy log. For example, my project, with / data / logs as the storage path log (/ data is best to use a separate partition or disk), haproxy log name haproxy.log, keepalived log name keepalived.log. Ruoguo reserves the log and requirements, need to archive and rotary.
  •  system log and log haproxy separate, unique records - poor configuration program, will cause the system to log and log haproxy duplicate records, take up a lot of disk space, once associated with the system partition is filled, the whole load balancing will fail .

Components involved in custom log

 system log service rsyslog.
 load balancing haproxy.
 availability keepalived.

Technical realization

Select the backup machine to do first configuration from the load balancer, the benefits of doing so will not affect the existing business. Then create good storage directory / data / logs, make sure that this directory to create and write to the file.

  •  System log configuration: modified for /etc/rsyslog.conf file, a complete content as follows (remove the comment lines and blank lines):
    $ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
    $ModLoad imjournal # provides access to the systemd journal
    $ModLoad imklog # reads kernel messages (the same are read from journald)
    $ModLoad immark  # provides --MARK-- message capability
    $ModLoad imudp
    $UDPServerRun 514
    $WorkDirectory /var/lib/rsyslog
    $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
    $IncludeConfig /etc/rsyslog.d/*.conf
    $OmitLocalLogging on
    $IMJournalStateFile imjournal.state
    mail.none;authpriv.none;cron.none                /var/log/messages
    authpriv.*                                              /var/log/secure
    mail.*                                                  -/var/log/maillog
    cron.*                                                  /var/log/cron
    *.emerg                                                 :omusrmsg:*
    uucp,news.crit                                          /var/log/spooler
    local7.*                                                /var/log/boot.log
    local3.* /data/logs/haproxy.log
    local4.* /data/logs/keepalived.log

IMPORTANT :
mail.none; authpriv.none; cron.none / var / log / messages deleted this line field "* .info;", if not removed, will be in / var / log / messages and file / data / logs / haproxy.log duplicate records access logs.

The last two lines manually added to it, especially the last line of "local4. * /Data/logs/keepalived.log", is matched to the requirements of keepalived log, or can not work.

  •  Configuration keepalived: no need to modify the configuration file keepalived.conf, just in time to start the service by adding the option "-S 4" on the line. Well, I know how to add this option is it? Executing instructions keepalived --help, see output term "-S, --log-facility = [ 0-7] Set syslog facility to LOG_LOCAL [0-7]", when the front configured rsyslog, defines "the local4. " Therefore keepalived start adding service options "-S 4". Keepalived start command is as follows.
    /usr/local/keepalived/sbin/keepalived -D -d -S 4
    For simplicity and versatility (applicable to all kinds
    nix), I have it written directly to the file /etc/rc.local.
  •  configuration haproxy, the log output setting. Add a line block set "log 127.0.0.1 local3" global main configuration file.

  •  start the related services:
     start rsyslog: service rsyslog restart;
     start haproxy: there keepalived is running, as long as the command killall -9 haproxyto kill the process, haproxy keepalived will automatically restart.
     start /usr/local/keepalived/sbin/keepalived -D -d -S 4keepalived: .

Authentication Configuration

Switch to the log storage directory / data / logs /, to see if there are two log file generation.
Haproxy + keepalived load balancing custom-made log
Manually bind a physical load balancer ip address, and then visit a host name of the load balancer set the browser to see whether a new log file /data/logs/haproxy.log of rows. If, as expected, then the next step.
Haproxy + keepalived load balancing custom-made log
Restart or temporarily turn off the primary load balancing system, all requests to set up drift and keepalived haproxy logs onto the system, /data/logs/haproxy.log case of generating a command to view the log tail -f, if the scrolling if spinning machine , dizzying, then it's done.

Finally, in the same way to the main load-balancing set up log.

Guess you like

Origin blog.51cto.com/sery/2465991