L7ロードバランサ。アプリケーション層のHTTPやSMTP等が対象。
対するL4ロードバランサはネットワーク層のTCP/UDP等が対象
haproxy -f /path/to/haproxy.conf -sf [既に動いているhaproxyのpid]
vim /etc/haproxy/haproxy.cfg
----
listen mysql-slave
disabled
----
service haproxy reloadyum install socat --enablerepo=rpmforge wget --no-check-certificate -O /usr/share/munin/plugins/haproxy_dwn_ "https://github.com/p01nt/haproxy_munin/raw/master/haproxy_dwn_" perl -p -i -e 's#/tmp/haproxy#/var/lib/haproxy/stats#i' "/usr/share/munin/plugins/haproxy_dwn_" chmod 755 /usr/share/munin/plugins/haproxy_dwn_ ln -s /usr/share/munin/plugins/haproxy_dwn_ /etc/munin/plugins/haproxy_dwn_memcache cat > /etc/munin/plugin-conf.d/haproxy <<EOF [haproxy_*] user root group root EOF service munin-node restart
munin-run haproxy_dwn_memcache memcache1_dwn.value 2 memcache1_dwntime.value 138
yum install haproxy --enablerepo=epel
cd /usr/src/redhat/ wget "http://download.fedora.redhat.com/pub/epel/6/SRPMS/haproxy-1.4.18-1.el6.src.rpm" rpm -ivh --nomd5 haproxy-1.4.18-1.el6.src.rpm yum install pcre-devel rpmbuild -ba SPECS/haproxy.spec rpm -ivh RPMS/i386/haproxy-1.4.18-1.i386.rpm
"-r"オプションを追加 vim /etc/sysconfig/syslog ---- SYSLOGD_OPTIONS="-m 0 -r" ---- "local2.none"と"local2.* /var/log/haproxy.log"を追加 vim /etc/syslog.conf ---- *.info;mail.none;authpriv.none;cron.none;local0.none;local2.none /var/log/messages local2.* /var/log/haproxy.log ---- service syslog restart
global
log 127.0.0.1 local1 notice
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 10000
user haproxy
group haproxy
daemon
quiet # Do not display any message during startup.
stats socket /var/lib/haproxy/stats
defaults
mode tcp
log global
retries 3
timeout connect 10s
timeout client 1m
timeout server 1m
listen http
disabled
bind 0.0.0.0:80
mode http
option httpchk GET /check.html HTTP/1.0
option log-health-checks
option forwardfor # Enable insertion of the X-Forwarded-For header to requests sent to servers.
option redispatch # Enable or disable session redistribution in case of connection failure.
option httplog # Enable logging of HTTP request, session state and timers.
# option httpclose # KeepAlive Off
balance roundrobin
server http01 host01:80 check inter 5s fall 2
server http02 host02:80 check inter 5s fall 2
listen mysql-master
# disabled
bind 0.0.0.0:3306
mode tcp
option mysql-check
balance roundrobin
server mysql01 host01:3306 check port 3306
listen mysql-slave
# disabled
bind 0.0.0.0:3307
mode tcp
option mysql-check
balance roundrobin
server mysql02 host02:3306 check port 3306
server mysql03 host03:3306 check port 3306
listen memcache
disabled
bind 0.0.0.0:11211
mode tcp
balance source
server memcache01 host01:11211 check port 11211
server memcache02 host02:11211 check port 11211