HAProxy 是一款提供高可用性、负载均衡以及基于TCP(第四层)和HTTP(第七层)应用的代理软件,支持虚拟主机,它是免费、快速并且可靠的一种解决方案
HAProxy 实现了一种事件驱动、单一进程模型,此模型支持非常大的并发连接数。多进程或多线程模型受内存限制 、系统调度器限制以及无处不在的锁限制,很少能处理数千并发连接
HAProxy 支持连接拒绝 : 因为维护一个连接的打开的开销是很低的,有时我们很需要限制攻击蠕虫(attack bots),也就是说限制它们的连接打开从而限制它们的危害
HAProxy 支持全透明代理(已具备硬件防火墙的典型特点): 可以用客户端IP地址或者任何其他地址来连接后端服务器.
HAProxy 特别适用于那些负载特大的 web 站点, 这些站点通常又需要会话保持或七层处理。HAProxy 运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的 web 服务器不被暴露到网络上。
实验具体操作
实验条件
一台Haproxy服务器,二台Apache后端服务器,一台测试机,共4台主机
实验环境
Redhat7.3版本下实验,关闭防火墙及selinux
Haproxy服务器 主机名server1 ip:192.168.0.1/24
Apache服务器1 主机名server2 ip:192.168.0.2/24
Apache服务器2 主机名server3 ip:192.168.0.3/24
客户测试端 主机名client ip:192.168.0.250/24
实验目标
使用haproxy搭建web群集,实现负载均衡和高可用
实验要求
1、分别在web1和web2上搭建apache
2、安装和配置haproxy
3、在客户端测试负载均衡
实验步骤
server1
安装haproxy
yum install -y haproxy
开启
systemctl start haproxy
查看配置文件
rpm -qc haproxy
/etc/haproxy/haproxy.cfg
编辑
vim /etc/haproxy/haproxy.cfg
82 server web1 192.168.0.2:80 check
83 server web2 192.168.0.3:80 check
重启
systemctl restart haproxy
server2
下载apache
yum install -y httpd
开启
systemctl start httpd
编辑
vim /var/www/html/index.html
server2.example.com
重启
systemctl restart httpd
server3
下载apache
yum install -y httpd
开启
systemctl start httpd
编辑
vim /var/www/html/index.html
server3.example.com
重启
systemctl restart httpd
客户测试端
测试
curl 192.168.0.1
server2.example.com(server2)
curl 192.168.0.1
server3.example.com(server3)