一、haproxy介绍
HAProxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代 理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理。HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的web服务器不被暴露到网络上。
二、haproxy安装
1、下载地址 http://pkgs.fedoraproject.org/repo/pkgs/haproxy/
2、编译安装
make install PREFIX=/usr/local/haproxy
三、启动与管理haproxy
1、启动 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
2、重启服务 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg -st cat /usr/local/haproxy/log/haproxy.pid
3、停止服务 killall haproxy
四、负载均衡配置
192.168.126.141 web1
192.168.126.142 web2
192.168.126.145 haproxy
haproxy.cfg配置
global
log 127.0.0.1 local2
maxconn 1000
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
timeout connect 5000
timeout client 50000
timeout server 50000
listen stats
bind 0.0.0.0:1080
mode http
option httplog
maxconn 10
stats refresh 30s
stats uri /stats
stats realm XingCloud\ Haproxy
stats auth admin:admin
stats auth Frank:Frank
stats hide-version
stats admin if TRUE
frontend http-in
bind *:80
mode http
log global
option httpclose
option logasap
option dontlognull
capture request header Host len 20
capture request header Referer len 60
default_backend servers
backend servers
balance roundrobin
server server1 192.168.126.141:80 check maxconn 2000
server server2 192.168.126.142:80 check maxconn 2000