从官方网站:http://www.haproxy.org 下载最新版本。
wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz
tar zcvf haproxy-1.3.20.tar.gz
cd haproxy-1.3.20
make TARGET=linux26 PREFIX=/usr/local/haprpxy
make install PREFIX=/usr/local/haproxy
cd /usr/local
groupadd haproxy
useradd -g haproxy haproxy
chown -R haproxy:haproxy haproxy
进入haproxy,编辑配置haproxy.cfg
cd haproxy
vi haproxy.cfg
global
user haproxy #所属运行的用户uid
group haproxy #所属运行的用户组
chroot /usr/local/haproxy
daemon
quiet
nbproc 4
maxconn 40000
log 127.0.0.1 local0 notice #日志文件的输出定向
spread-checks 2
defaults
timeout server 15s
timeout connect 15s
timeout client 120s
timeout http-request 15s
timeout queue 15s
option httpchk GET /index.html
option httpchk GET /
http-check disable-on-404
option httpclose
option forwardfor
frontend abc.com
mode http #所处理的类别
maxconn 1000000
bind :80
default_backend www.abc.com
option forwardfor
backend www.abc.com
balance roundrobin #负载均衡算法
mode http
cookie SLB insert indirect
stats uri /abc
option abortonclose
option forwardfor
server web1 192.168.0.101:80 check cookie web1 rise 2 fall 3 #后端的主机 IP &权衡
server web2 192.168.0.102:80 check cookie web2 rise 2 fall 3 #后端的主机 IP &权衡
启动服务:
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
重启服务:
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg -st `cat /usr/local/haproxy/logs/haproxy.pid` (没有换行)
停止服务:
killall haproxy
转载请注明:LINUX服务器运维架构技术分享 » haproxy 安装配置调优