配置HAProxy负载平衡集群
网络拓扑图
client: 172.16.0.10
haproxy:172.16.0.5
web1: 172.16.0.100
web2: 172.16.0.200
1.在调度器上面:
1.1安装软件包haproxy
[[email protected] ~]# yum -y install gcc
[[email protected] ~]# yum -y install pcrepcre-devel
[[email protected] haproxy-1.4.24]# tar -zxvfhaproxy-1.4.24.tar.gz
[[email protected] haproxy-1.4.24]# cdhaproxy-1.4.24
[[email protected] haproxy-1.4.24]# uname -r
2.6.32-431.el6.x86_64
[[email protected] haproxy-1.4.24]# cat README
[[email protected]]# make TARGET=linux2632 USE_PCRE=1 PREFIX=/usr/local/haproxy install
[[email protected] haproxy-1.4.24]# cd examples/
[[email protected] examples]# cp haproxy.init/etc/init.d/haproxy
[[email protected] examples]# chmod +x/etc/init.d/haproxy
[[email protected] examples]# mkdir /etc/haproxy
[[email protected] examples]# cp haproxy.cfg/etc/haproxy/
[[email protected] examples]# ln -s/usr/local/haproxy/sbin/haproxy /usr/sbin/
1.2修改配置文件
[[email protected] haproxy]# vim/etc/haproxy/haproxy.cfg
27listen webs 172.16.0.5:80
28 cookie SERVERID rewrite
29 balance roundrobin
30 server ser_1 172.16.0.100:80cookie app1inst1 check inter 2000 rise 2 fall 3
31 server ser_2 172.16.0.200 :80cookieapp1inst2 check inter 2000 rise 2 fall3
Defaults
............
21 option redispatch
79 # errorfile 503 /etc/haproxy/errors/503.http
[[email protected] haproxy]# mkdir/usr/share/haproxy
[[email protected] ~]# /etc/init.d/haproxy start
客户端测试:
[[email protected] ~]# elinks --dumphttp://172.16.0.5
172.16.0.100
[[email protected] ~]# elinks --dumphttp://172.16.0.5
172.168.0.200
1.3生成监控页面
[[email protected] ~]# vim /etc/haproxy/haproxy.cfg
Defaults
.............
26 stats uri /admin
27 stats auth admin:123456
28 stats refresh 5s
[[email protected] ~]# /etc/init.d/haproxy restart
客户端测试:
客户端使用浏览器访问监控页面:
#firefox http://172.16.0.5/admin
用户名admin,密码123