HAProxy

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
基于域名访问控制

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值