haproxy 负载均衡
参考文档
1 http://www.cnblogs.com/MacoLee/p/5853413.html
2 http://www.cnblogs.com/breezey/p/4680418.html
解压 haproxy 安装包 进入目录
tar -zxvf haproxy-1.5.19.tar.gz
haproxy-1.5.19
mkdir /usr/local/haproxy
make TARGET=linux2628 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
TARGET=linux26 #内核版本,使用uname -r查看内核,如:2.6.18-371.el5,此时该参数就为linux26;kernel 大于2.6.28的用:TARGET=linux2628
ARCH=x86_64 #系统位数
PREFIX=/usr/local/haprpxy #/usr/local/haprpxy为haprpxy安装路径
mkdir conf
vim conf/haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 1000
#uid 99
user www
group www
#gid 99
daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
timeout connect 5000
timeout client 50000
timeout server 50000
listen admin_stats
bind 0.0.0.0:1080 #设置Frontend和Backend的组合体,监控组的名称,按需要自定义名称
mode http #http的7层模式
option httplog #采用http日志格式
#log 127.0.0.1 local0 err #错误日志记录
maxconn 10 #默认的最大连接数
stats refresh 30s #统计页面自动刷新时间
stats uri /stats #统计页面url
stats realm XingCloud\ Haproxy #统计页面密码框上提示文本
stats auth admin:admin #设置监控页面的用户和密码:admin,可以设置多个用户名
stats auth Frank:Frank #设置监控页面的用户和密码:Frank
stats hide-version #隐藏统计页面上HAProxy的版本信息
stats admin if TRUE #设置手工启动/禁用,后端服务器(haproxy-1.4.9以后版本)
errorfile 403 /usr/local/haproxy/errorfiles/403.http
errorfile 500 /usr/local/haproxy/errorfiles/500.http
errorfile 502 /usr/local/haproxy/errorfiles/502.http
errorfile 503 /usr/local/haproxy/errorfiles/503.http
errorfile 504 /usr/local/haproxy/errorfiles/504.http
listen web 0.0.0.0:80
mode http
#cookie SERVERID insert indirect nocache
cookie SERVERID
balance roundrobin
#option httpchk
server app1_1 192.168.10.155:80 cookie app1inst1 check inter 2000 rise 2 fall 5
server app1_2 192.168.10.16:80 cookie app1inst2 check inter 2000 rise 2 fall 5
启动
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
访问 http://192.168.10.150:1080/stats 查看各负载状态
浙公网安备 33010602011771号