[centos7]haproxy安装及配置

一、下载安装
http://pkgs.fedoraproject.org/repo/pkgs/haproxy/

tar xvzf haproxy-1.5.8.tar.gz
cd haproxy-1.5.8
uname -a //查看linux内核版本
make TARGET=linux26 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy

二、配置haproxy

vim /usr/local/haproxy/haproxy.cfg
global
maxconn 5120
chroot /usr/local/haproxy
uid 99
gid 99
daemon
quiet
nbproc 2
pidfile /usr/local/haproxy/haproxy.pid
defaults
log global
mode http
option httplog
option dontlognull
log 127.0.0.1 local3
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000

listen webinfo :1080
mode http
balance roundrobin
option httpclose
option forwardfor
server phpinfo1 127.0.0.1:1337 check weight 1 minconn 1 maxconn 3 check inter 40000
server phpinfo2 127.0.0.1:80 check weight 1 minconn 1 maxconn 3 check inter 40000

listen webmb :1081
mode http
balance roundrobin
option httpclose
option forwardfor
server webmb1 127.0.0.1:1337 weight 1 minconn 1 maxconn 3 check inter 40000
server webmb2 127.0.0.1:10000 weight 1 minconn 1 maxconn 3 check inter 40000

listen stats :8888
mode http
transparent
stats uri / haproxy-stats
stats realm Haproxy \ statistic
stats auth admin:admin

三,启动haproxy

#启动haproxy
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg

#查看是否启动
[zhangy@BlackGhost haproxy]$ ps -e|grep haproxy
1829 ? 00:00:00 haproxy
1830 ? 00:00:00 haproxy

四,压力测试

[root@BlackGhost haproxy]# /usr/local/bin/webbench -c 100 -t 30 http://localhost:1080/phpinfo.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://localhost:1080/phpinfo.php
100 clients, running 30 sec.

Speed=26508 pages/min, 20929384 bytes/sec.
Requests: 13254 susceed, 0 failed.

说明:haproxy监听的端口是1080,代理192.168.18.2:10000,127.0.0.1:10000

统计监听的是8888端口 http://localhost:8888/haproxy-stats

发表评论

电子邮件地址不会被公开。 必填项已用*标注