HAProxy 是一款免费、高性能的开源软件,专为提供高可用性、TCP/HTTP 负载均衡及代理服务而设计。
核心特性:
-
高可用性:自动健康检查与故障切换,确保系统连续运行。
-
负载均衡:支持轮询、最少连接等多种算法,优化资源分配。
-
卓越性能:高效数据转发,低延迟,高并发处理能力。
-
协议支持:全面支持 TCP 与 HTTP 协议,实现精细路由。
-
安全防护:提供连接速率限制、ACL 等基础安全功能。
典型应用:
-
大型网站:提升响应速度与吞吐量,保障高可用。
-
Web 应用集群:实现应用横向扩展与负载均衡。
-
微服务架构:作为 API 网关,负责请求路由与服务发现。
配置管理:
通过文本配置文件定义前端与后端参数,并可通过命令行工具及第三方监控系统进行管理与优化。
实验环境
四台主机:Haproxy,webserver1,webserver2,测试机
所需软件:nginx,Haproxy
1、分别添加地址
在服务器1、2上安装nginx
[root@webserver1 ~]# dnf install nginx -y
[root@webserver2 ~]# dnf install nginx -y
nginx共享文件中写入
[root@webserver1 ~]# echo webserver1 - 172.25.254.10 > /usr/share/nginx/html/index.html
[root@webserver1 ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@webserver2 ~]# echo webserver2 - 172.25.254.20 > /usr/share/nginx/html/index.html
[root@webserver2 ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
2、在主机haproxy上安装haproxy
[root@haproxy ~]# dnf install haproxy -y
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service
3、curl检测

全局配置
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service
[root@haproxy ~]# pstree -p | grep haproxy


定义修改日志文件,开启udp
vim /etc/rsyslog.conf

haproxy代理配置
server配置[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg

使用backup实现sorry server
systemctl stop nginx.service
[root@haproxy ~]# dnf install httpd -y
[root@haproxy ~]# vim /etc/httpd/conf/httpd.conf
[root@haproxy ~]# systemctl enable --now httpd
[root@haproxy ~]# echo sorry 内容 > /var/www/html/index.html
可以向特定的网页文件写入文本内容
四层IP透传
核心命令:
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service
再使用send-porxy编辑server2
[root@webserver2 ~]# vim /etc/nginx/nginx.conf
[root@webserver2 ~]# systemctl restart nginx.service


ACL
基于域名访问控制


3950

被折叠的 条评论
为什么被折叠?



