HAProxy 提供高可用性、负载均衡以及基于 TCP 和 HTTP 应用的代理,支持虚拟主机,
它是免费、快速并且可靠的一种解决方案。HAProxy 特别适用于那些负载特大的 web 站
点,这些站点通常又 需要会话保持或七层处理。HAProxy 运行在当前的硬件上,完全可以
支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架
构中,同时可以保护你的 web 服务器不被暴露到网络上.
haproxy 配置中分成五部分内容,分别如下:
1、global:参数是进程级的,通常是和操作系统相关。这些参数一般只设置一次,如果配
置无误,就不需要再次进行修改
2、defaults:配置默认参数,这些参数可以被用到 frontend,backend,Listen 组件
3、frontend:接收请求的前端虚拟节点,Frontend 可以更加规则直接指定具体使用后端
的 backend
4、backend:后端服务集群的配置,是真实服务器,一个 Backend 对应一个或者多个实
体服务器
5、Listen Fronted 和 backend 的组合体
一、安装 HAProxy
1.自己搞安装包 haproxy-1.4.22.tar.gz
2.tar -zxvf haproxy-1.5.8.tar.gz
3.安装
[root@server1 mnt]# ls
haproxy-1.4.22.tar.gz
[root@server1 mnt]#
[root@server1 mnt]# tar zxf haproxy-1.4.22.tar.gz
[root@server1 mnt]# ls
haproxy-1.4.22 haproxy-1.4.22.tar.gz
[root@server1 mnt]# yum install rpm-build
[root@server1 ~]# rpmbuild ~
[root@server1 ~]# cp /mnt/haproxy-1.4.22.tar.gz /root/rpmbuild/SOURCES/
[root@server1 mnt]# cd haproxy-1.4.22
[root@server1 haproxy-1.4.22]# ls
CHANGELOG ebtree LICENSE Makefile.osx src TODO
contrib examples Makefile README SUBVERS VERDATE
doc include Makefile.bsd ROADMAP tests VERSIONdoc
[root@server1 haproxy-1.4.22]# cd examples
[root@server1 examples]# ls
acl-content-sw.cfg haproxy.cfg
auth.cfg haproxy.init
build.cfg haproxy.spec
check haproxy.vim
check.conf init.haproxy
config.rc.haproxy init.haproxy.flx0
content-sw-sample.cfg linux-2.4.21-40.EL-custom.dif
cttproxy-src.cfg option-http_proxy.cfg
debug2ansi rc.highsock
debug2html stats_haproxy.sh
debugfind tarpit.cfg
errorfiles test-section-kw.cfg
examples.cfg url-switching.cfg
haproxy-1.1.21-flx.1.pkg
[root@server1 examples]# rpmbuild -bb haproxy.spec
[root@server1 examples]# cd /root/rpmbuild/RPMS/x86_64/
[root@server1 x86_64]# ls
haproxy-1.4.22-1.x86_64.rpm haproxy-debuginfo-1.4.22-1.x86_64.rpm
[root@server1 x86_64]# yum install * -y
配置:
启动服务:
[root@server1 share]# /etc/init.d/haproxy start
Starting haproxy: [ OK ]
测试:
访问 http://www.westos.com 测试负载
手动刷新
访问 haproxy 监控页面:http://172.25.254.1/status