Differences
This shows you the differences between two versions of the page.
tech:others:haproxy [2015/04/11 06:44] |
tech:others:haproxy [2015/04/11 06:44] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== haproxy ====== | ||
+ | ===== Install ===== | ||
+ | * Download haproxy and change directory to download directory | ||
+ | * Run make and make install as root | ||
+ | ==== Make ==== | ||
+ | To choose TARGET run | ||
+ | <code bash> | ||
+ | uname -a | ||
+ | </code> | ||
+ | Output: | ||
+ | <code> | ||
+ | Linux somehost 2.6.32-358.11.1.el6.x86_64 #1 SMP Wed May 15 10:48:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux | ||
+ | </code> | ||
+ | Considering the above was kernel 2.6, using TARGET as below. | ||
+ | |||
+ | <code bash> | ||
+ | make TARGET=linux2628 USE_PCRE=1 USE_LIBCRYPT=1 USE_LINUX_SPLICE=1 USE_LINUX_TPROXY=1 | ||
+ | </code> | ||
+ | Some options listed may not work - feel free to remove them such as ''USE_PCRE=1'' | ||
+ | |||
+ | ==== Make Install ==== | ||
+ | <code bash> | ||
+ | make install | ||
+ | </code> | ||
+ | haproxy typically gets installed at ''/usr/local/sbin/haproxy'' | ||
+ | |||
+ | ===== Configuration ===== | ||
+ | To configure, create a configuration file at chosen location. Preferred: /etc/haproxy/haproxy.cfg | ||
+ | * Load balance on port 8000 | ||
+ | * Sticky sessions between multiple servers (someserver1 & someserver2) | ||
+ | * Add administration (port 7999) | ||
+ | |||
+ | <code> | ||
+ | global | ||
+ | daemon | ||
+ | maxconn 4096 | ||
+ | |||
+ | defaults | ||
+ | mode http | ||
+ | timeout connect 5000ms | ||
+ | timeout client 50000ms | ||
+ | timeout server 50000ms | ||
+ | |||
+ | frontend http-in | ||
+ | bind *:8000 | ||
+ | default_backend servers | ||
+ | |||
+ | backend servers | ||
+ | retries 2 | ||
+ | fullconn 4096 | ||
+ | balance roundrobin | ||
+ | cookie SERVERID insert indirect nocache | ||
+ | server server01 someserver1:8080 check cookie s01 | ||
+ | server server02 someserver1:8081 check cookie s02 | ||
+ | server server03 someserver1:8082 check cookie s03 | ||
+ | server server04 someserver2:8090 check cookie s04 | ||
+ | server server05 someserver2:8091 check cookie s05 | ||
+ | server server06 someserver2:8092 check cookie s06 | ||
+ | |||
+ | listen stats :7999 | ||
+ | mode http | ||
+ | stats enable | ||
+ | stats hide-version | ||
+ | stats realm Haproxy\ Statistics | ||
+ | stats uri / | ||
+ | </code> | ||
+ | |||
+ | ===== Start ===== | ||
+ | Simple way to start is as below. This runs as a daemon, since daemon is specified in the configuration. If not, add option -D. | ||
+ | <code bash> | ||
+ | haproxy -f /etc/haproxy/haproxy.cfg | ||
+ | </code> | ||
+ | |||
+ | ===== Logging ===== | ||
+ | ==== Update /etc/rsyslog.conf and related ==== | ||
+ | Edit /etc/rsyslog.conf and uncomment: | ||
+ | <code> | ||
+ | $ModLoad imudp | ||
+ | $UDPServerRun 514 | ||
+ | </code> | ||
+ | |||
+ | Edit /etc/rsyslog.d/haproxy.conf and append line: | ||
+ | <code> | ||
+ | local2.* /var/log/haproxy.log | ||
+ | </code> | ||
+ | |||
+ | Restart rsyslog: | ||
+ | <code> | ||
+ | service rsyslog restart | ||
+ | </code> | ||
+ | |||
+ | Change permissions on log file: | ||
+ | <code> | ||
+ | chmod o+r /var/log/haproxy.log | ||
+ | chmod g+r /var/log/haproxy.log | ||
+ | </code> | ||
+ | |||
+ | ==== Update /etc/haproxy/haproxy.cfg ==== | ||
+ | Edit /etc/haproxy/haproxy.cfg:\\ | ||
+ | |||
+ | Add line in ''global section'': | ||
+ | <code> | ||
+ | log 127.0.0.1 local2 | ||
+ | </code> | ||
+ | |||
+ | Add lines to ''frontend http-in'' section: | ||
+ | <code> | ||
+ | option httplog | ||
+ | log global | ||
+ | </code> | ||
+ | |||
+ | Restart haproxy | ||
+ | |||
+ | |||
+ | ==== Logging Resources ==== | ||
+ | * https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux_OpenStack_Platform/3/html/Installation_and_Configuration_Guide/Configuring_the_rsyslog_Server.html | ||
+ | * https://transloadit.com/blog/2010/08/haproxy-logging/ | ||
+ | * http://www.percona.com/blog/2014/10/03/haproxy-give-me-some-logs-on-centos-6-5/ | ||
+ | * http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#8 | ||