实现负载均衡常用的Web服务器软件有Nginx、HAProxy、LVS、Apache
HAProxy与LVS、Nginx的比较LVS性能最好,但是搭建相对复杂
Nginx的upstream模块支持集群功能,但是对集群节点健康检查功能不强,性能没有Haproxy好。
http://www.haproxy.org/ #社区版地址
官网描述:HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for very high traffic web sites and powers quite a number of the world‘s most visited ones.
HAProxy是一种免费,非常快速且可靠的解决方案,可为基于TCP和HTTP的应用程序提供 高可用性, 负载平衡和代理。它特别适合于流量非常高的网站,并为世界上许多访问量最大的网站提供支持。
使用Haproxy搭建Web群集
Haproxy服务器 CentOS 8.3 IP:10.0.0.162
apache服务器1 CentsOS 8.3 IP:10.0.0.163
apache服务器2 CentOS 8.3 IP:10.0.0.164
开始具体操作,两台apache 服务器已经配置成,访问各自的IP地址正常出现web页面。
配置Haproxy服务器 10.0.0.162
安装 Haproxy,启动Haproxy 服务
编辑配置文件 /etc/haproxy/haproxy.cfg
Haproxy配置文件通常分为五个部分,但有些部分并不是必须的
global 全局配置段 进程,安全配置,性能调整,Debug参数
defaults 默认配置段 为frontend, listen, backend提供默认配置
frontend ACL配置段 用于设置接收用户请求的前端虚拟节点,并根据ACL规则直接指定要使用的后端backend
backend 真实集群配置段 |
实验认证访问效果
访问10.0.0.162 切换 会发现不同的网站页面 说明已经实现了负载均衡.
原文:https://www.cnblogs.com/liuyakai/p/14612147.html