负载均衡
是一种服务或基于硬件设备等实现的高可用反向代理技术,负载均 衡将特定的业务(web服务、网络流量等)分担给指定的一个或多个后端特定的服务器或设备,从而提高了 公司业务的并发处理能力、保证了业务的高可用性、方便了业务后期的水平动态扩展
负载均衡类型
四层负载均衡
支持四层负载均衡的有lvs,haproxy,nginx。
四层是指OSI 七层网络模型中的传输层(Transport Layer),其核心是基于IP 地址和端口号进行负载均衡决策
四层负载均衡的工作原理是:
- 接收客户端发送的数据包,解析其中的源 IP、目标 IP、源端口、目标端口等传输层信息。
- 根据预设的负载均衡算法(如轮询、加权轮询、IP 哈希等),将请求转发到后端服务器集群中的某一台服务器。
- 转发过程中可能会修改数据包的目标 IP 和端口,使请求最终到达选定的后端服务器。
七层负载均衡
支持七层负载均衡的有haproxy,nginx。
七层负载均衡中的 “七层” 指的是OSI 七层网络模型中的应用层(Application Layer),它是在传输层(四层)基础上,进一步深入到应用层协议的细节进行负载均衡决策,核心是基于应用层数据(如 HTTP 头部、URL、Cookie 等) 实现请求分发。
四层负载均衡和七层负载均衡的区别:
1.四层负载均衡工作在 OSI 模型的传输层(第四层),只根据数据包的IP 地址和端口号做转发决策,不解析应用层内容。
七层负载均衡工作在应用层(第七层),会深入解析应用层协议的具体内容,基于这些应用层数据做更精细的分流。
2.四层更侧重 “快速转发”:性能更高,但策略简单:轮询、IP 哈希。
七层更侧重 “智能决策”:可以基于应用层信息实现复杂策略,比如按 URL 路径分流(静态资源到 CDN,动态请求到应用服务器)、用 Cookie 保持用户会话,甚至修改 HTTP 头、拦截恶意请求(类似简单 WAF),但性能略低于四层。
3.四层适合高并发、低延迟场景,比如游戏服务器、视频直播、数据库或 Redis 的负载均衡,因为它转发速度快,能扛住大流量。
七层适合 Web 应用、微服务等需要精细管控的场景,比如电商网站按不同页面路径分流,或者需要保持用户登录状态的业务。
实际架构中,两者经常配合使用,比如用四层做入口流量的高并发转发,后端再用七层做应用层的精细化分流,兼顾性能和灵活性。
haproxy
简介
HAProxy 是一款高性能、开源的负载均衡器与反向代理服务器,主要用于在多个后端服务器之间分发网络流量,提升服务的可用性、扩展性和可靠性。它支持多种协议和场景,广泛应用于高并发的 Web 服务、微服务架构等场景。
HAProxy 广泛应用于 Web 服务、微服务架构、数据库集群等场景,常与 Nginx、Keepalived 等工具配合使用,构建高可用的服务架构。
haproxy的环境搭建
软件基本配置
#安装
haproxy ~]# dnf install haproxy -y
#查看版本
[root@haproxy ~]# haproxy -v
HAProxy version 2.4.22-f8e3218 2023/02/14 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2026.
Known bugs: http://www.haproxy.org/bugs/bugs-2.4.22.html
Running on: Linux 5.14.0-427.13.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 10
10:29:16 EDT 2024 x86_64
#haproxy软件基本信息位置
软件安装包: haproxy-2.4.22-3.el9_3.x86_64.rpm
启动文件: /lib/systemd/system/haproxy.service
主配置目录: /etc/haproxy/
主配置文件: /etc/haproxy/haproxy.cfg
子配置目录: /etc/haproxy/conf.d
haproxy.cfg由两大部分组成:global,proxies
global:全局配置段
global
log 127.0.0.1 local2 #定义全局的syslog服务器;日志服务器需要开启UDP协
议,最多可以定义两个
chroot /var/lib/haproxy #锁定运行目录
pidfile /var/run/haproxy.pid #指定pid文件
maxconn 100000 #指定最大连接数
user haproxy #指定haproxy的运行用户
group haproxy #指定haproxy的运行组
daemon #指定haproxy以守护进程方式运行
# turn on stats unix socket
stats socket /var/lib/haproxy/stats #指定haproxy的套接字文件
nbproc 2 #指定haproxy的work进程数量,默认是1个
cpu-map 1 0 #指定第一个work绑定第一个cpu核心
cpu-map 2 1 #指定第二个work绑定第二个cpu核心
nbthread 2 #指定haproxy的线程数量,默认每个进程一个线
程,此参数与nbproc互斥
maxsslconn 100000 #每个haproxy进程ssl最大连接数,用于haproxy
配置了证书的场景下
maxconnrate 100 #指定每个客户端每秒建立连接的最大数量
proxies:代理配置段
defaults
mode http #HAProxy实例使用的连接协议
log global #指定日志地址和记录日志条目的
syslog/rsyslog日志设备
#此处的 global表示使用 global配置段中
设定的log值。
option httplog #日志记录选项,httplog表示记录与 HTTP
会话相关的各种属性值
#包括 HTTP请求、会话状态、连接数、源地
址以及连接时间等
option dontlognull #dontlognull表示不记录空会话连接日志
option http-server-close #等待客户端完整HTTP请求的时间,此处为等
待10s。
option forwardfor except 127.0.0.0/8 #透传客户端真实IP至后端web服务器
#在apache配置文件中加入:<br>%{XForwarded-For}i
#后在webserver中看日志即可看到地址透传
信息
option redispatch #当server Id对应的服务器挂掉后,强制定
向到其他健康的服务器,重新派发
option http-keep-alive #开启与客户端的会话保持
retries 3 #连接后端服务器失败次数
3.3.2.3 Proxies配置-frontend
frontend 配置参数:
frontend 配置示例:
timeout http-request 10s #等待客户端请求完全被接收和处理的最长时
间
timeout queue 1m #设置删除连接和客户端收到503或服务不可
用等提示信息前的等待时间
timeout connect 120s #设置等待服务器连接成功的时间
timeout client 600s #设置允许客户端处于非活动状态,即既不发
送数据也不接收数据的时间
timeout server 600s #设置服务器超时时间,即允许服务器处于既
不接收也不发送数据的非活动时间
timeout http-keep-alive 60s #session 会话保持超时时间,此时间段内
会转发到相同的后端服务器
timeout check 10s #指定后端服务器健康检查的超时时间
maxconn 3000
default-server inter 1000 weight 3
socat 工具
对服务器动态权重和其它状态可以利用 socat工具进行调整,Socat 的主要特点就是在两个数据流之间建立双向 通道,且支持众多协议和链接方式。如 IP、TCP、 UDP、IPv6、Socket文件等
针对多进程处理方法
haproxy ~]# vim /etc/haproxy/haproxy.cfg
...上面内容省略...
stats socket /var/lib/haproxy/stats1 mode 600 level admin process 1
stats socket /var/lib/haproxy/stats2 mode 600 level admin process 2
nbproc 2
cpu-map 1 0
cpu-map 2 1
...上面内容省略...
这样每个进程就会有单独的sock文件来进行单独管理
[root@haproxy ~]# ll /var/lib/haproxy/
总用量 0
srw------- 1 root root 0 8月 8 13:43 stats
srw------- 1 root root 0 8月 8 13:46 stats1
srw------- 1 root root 0 8月 8 13:46 stats2
haproxy的状态界面
haproxy ~]# vim /etc/haproxy/haproxy.cfg
...上面内容省略...
listen stats
mode http
bind 0.0.0.0:8888
stats enable
log global
stats uri /haproxy-status
stats auth cll:cll
...下面内容省略...
haproxy的算法
#静态
static-rr--------->tcp/http
first------------->tcp/http
#动态
roundrobin-------->tcp/http
leastconn--------->tcp/http
#以下静态和动态取决于hash_type是否consistent
source------------>tcp/http
Uri--------------->http
url_param--------->http
hdr--------------->http
静态算法
1.static-rr——基于权重的轮询调度
不支持运行时利用socat进行权重的动态调整
不支持端服务器慢启动
其后端主机数量没有限制,相当于LVS中的 wrr
vim /etc/haproxy/haproxy.cfg
listen webcluster
bind *:80
mode http
balance static-rr
server web1 192.168.183.10:80 check inter 5s fall 3 weight 2
server web2 192.168.183.20:80 check inter 5s fall 3 weight 1
2.first
根据服务器在列表中的位置,自上而下进行调度
其只会当第一台服务器的连接数达到上限,新请求才会分配给下一台服务
其会忽略服务器的权重设置,不支持用socat进行动态修改权重,可以设置0和1,可以设置其它值但无效
[root@cll ~]# vim /etc/haproxy/haproxy.cfg
listen webcluster
bind *:80
mode http
balance first
server web1 192.168.183.10:80 maxconn 3 check inter 5s fall 3 rise 5
server web2 192.168.183.20:80 check inter 5s fall 3 rise 5
[root@cll ~]# systemctl restart haproxy.service
动态算法
1.roundrobin
基于权重的轮询动态调度算法,
支持权重的运行时调整,不同于lvs中的rr轮训模式,
HAProxy中的roundrobin支持慢启动(新加的服务器会逐渐增加转发数),
其每个后端backend中最多支持4095个real server,
支持对real server权重动态调整,
roundrobin为默认调度算法,此算法使用广泛
[root@cll ~]# vim /etc/haproxy/haproxy.cfg
listen webcluster
bind *:80
mode http
#balance static-rr
#balance first
balance roundrobin
server web1 192.168.183.10:80 check inter 5s fall 3 rise 5 weight 1
server web2 192.168.183.20:80 check inter 5s fall 3 rise 5 weight 1
[root@cll ~]# systemctl restart haproxy.service
动态调整权重
[root@cll ~]# echo "set weight webcluster/web1 2" | socat stdio /var/lib/haproxy/stats
[root@cll ~]# echo "get weight webcluster/web1" | socat stdio /var/lib/haproxy/stats
2 (initial 1)
[root@cll ~]# echo "get weight webcluster/web2" | socat stdio /var/lib/haproxy/stats
1 (initial 1)
2.leastconn
leastconn加权的最少连接的动态
支持权重的运行时调整和慢启动
比较适合长连接的场景使用,比如:MySQL等场景。
[root@cll ~]# vim /etc/haproxy/haproxy.cfg
listen webcluster
bind *:80
mode http
#balance static-rr
#balance first
#balance roundrobin
balance leastconn
server web1 192.168.183.10:80 check inter 5s fall 3 rise 5 weight 1
server web2 192.168.183.20:80 check inter 5s fall 3 rise 5 weight 1
[root@cll ~]# systemctl restart haproxy.service
其他算法
1.source
基于用户源地址hash并将请求转发到后端服务器,同一个源地址请求将被转发到同一个后端服务器。
适用于session会话保持但不支持
cookie和缓存的场景源地址有两种转发客户端请求到后端服务器的服务器选取计算方式,分别是取模法
和一致性hash
[root@cll ~]# vim /etc/haproxy/haproxy.cfg
listen webcluster
bind *:80
mode http
#balance static-rr
#balance first
#balance roundrobin
#balance leastconn
balance source
server web1 192.168.183.10:80 check inter 5s fall 3 rise 5 weight 1
server web2 192.168.183.20:80 check inter 5s fall 3 rise 5 weight 1
[root@cll ~]# systemctl restart haproxy.service
map-base取模法
listen webserver_80
bind 172.25.254.100:80
mode http
balance source
server webserver1 192.168.0.101:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.0.102:80 weight 1 check inter 3s fall 3 rise 5
对source地址进行hash计算,再基于服务器总权重的取模,最终结果决定将此请求转发至对应的后端服务器。
是静态的,即不支持在线调整权重,不支持慢启动
一致性hash
listen webserver_80
bind 172.25.254.100:80
mode http
balance source
hash-type consistent
server webserver1 192.168.0.101:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.0.102:80 weight 1 check inter 3s fall 3 rise 5
是动态的,支持使用 socat等工具进行在线权重调整,支持慢启动
2.uri
基于对用户请求的URI的左半部分或整个uri做hash,再将hash结果对总权重进行取模后根据最终结果将请求转发到后端指定服务器
适用于后端是缓存服务器场景
uri 取模法配置示例
listen webserver_80
bind 192.168.183.100:80
mode http
balance uri
server webserver1 192.168.183.10:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.183.20:80 weight 1 check inter 3s fall 3 rise 5
uri 一致性hash配置示例
listen webserver_80
bind 192.168.183.100:80
mode http
balance uri
hash-type consistent
server webserver1 192.168.183.10:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.182.20:80 weight 1 check inter 3s fall 3 rise 5
测试
root@rs1 ~]# echo RS1 192.168.183.10 index1 > /var/www/html/index1.html
[root@rs1 ~]# echo RS1 192.168.183.10 index2 > /var/www/html/index2.html
[root@rs1 ~]# echo RS1 192.168.183.10 index3 > /var/www/html/index3.html
[root@rs2 ~]# echo RS1 192.168.183.20 index1 > /var/www/html/index1.html
[root@rs2 ~]# echo RS1 192.168.183.20 index2 > /var/www/html/index2.html
[root@rs2 ~]# echo RS1 192.168.183.20 index3 > /var/www/html/index3.html
[root@node10 ~]# curl 192.168.183.100/index.html
RS2 server - 192.168.183.20
[root@node10 ~]# curl 192.168.183.100/index1.html
RS1 192.168.183.10 index1
3.url_para
url_param对用户请求的url中的 params 部分中的一个参数key对应的value值作hash计算,并由服务器总权重相除以后派发至某挑出的服务器,后端搜索同一个数据会被调度到同一个服务器,多用与电商通常用于追踪用户,以确保来自同一个用户的请求始终发往同一个real server
#假设:
url = http://www.timinglee.com/foo/bar/index.php?key=value
#则:
host = "www.timinglee.com"
url_param = "key=value"
url_param取模法
listen webserver_80
bind 192.168.183.100:80
mode http
balance url_param name,userid #支持对多个url_param hash
server webserver1 192.168.183.10:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.183.20:80 weight 1 check inter 3s fall 3 rise 5
url_param一致性
listen webserver_80
bind 192.168.183.100:80
mode http
balance url_param name,userid #支持对多个url_param hash
hash-type consistent
server webserver1 192.168.183.10:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.183.20:80 weight 1 check inter 3s fall 3 rise 5
4.hdr
针对用户每个http头部(header)请求中的指定信息做hash,
此处由 name 指定的http首部将会被取出并做hash计算,
然后由服务器总权重取模以后派发至某挑出的服务器,如果无有效值,则会使用默认的轮询调度
hdr取模法
listen webserver_80
bind 172.25.254.100:80
mode http
balance hdr(User-Agent)
server webserver1 192.168.183.10:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.183.20:80 weight 1 check inter 3s fall 3 rise 5
一致性hash
listen webserver_80
bind 192.168.183.100:80
mode http
balance hdr(User-Agent)
hash-type consistent
server webserver1 192.168.183.10:80 weight 1 check inter 3s fall 3 rise 5
server webserver2 192.168.183.20:80 weight 1 check inter 3s fall 3 rise 5
高级功能
基于cookie的会话保持
cookie value:为当前server指定cookie值,实现基于cookie的会话黏性,相对于基于 source 地址hash
调度算法对客户端的粒度更精准,但同时也加大了haproxy负载,目前此模式使用较少, 已经被session
共享服务器代替
注意:不支持 tcp mode,使用 http mode
测试
[root@cll ~]# vim /etc/haproxy/haproxy.cfg
listen webcluster
bind *:80
option forwardfor
mode http
#balance static-rr
#balance first
balance roundrobin
#balance leastconn
#balance source
cookie WEBCOOKIE insert nocache indirect
server web1 192.168.183.10:80 cookie web1 weight 1 check inter 3s fall 3 rise 5
server web2 192.168.183.20:80 cookie web2 weight 1 check inter 3s fall 3 rise 5
[root@cll ~]# systemctl restart haproxy.service
HAProxy状态页
通过web界面,显示当前HAProxy的运行状态
[root@cll ~]# vim /etc/haproxy/haproxy.cfg
listen webcluster
bind 0.0.0.0:8888
mode http
stats enable
log global
stats uri /status
stats auth cll:cll
server web1 192.168.183.10:80 cookie web1 weight 1 check inter 3s fall 3 rise 5
server web2 192.168.183.20:80 cookie web2 weight 1 check inter 3s fall 3 rise 5
[root@cll ~]# systemctl restart haproxy.service
浏览器访问:192.168.183.100:8888/status
账号密码:cll/cll
停掉其中一台nginx服务。
重启服务,刷新。
IP透传
四层ip透传
未开启:
在访问haproxy后查看nginx日志
开启:
修改haproxy主机的配置文件
haproxy ~]# vim /etc/haproxy/haproxy.cfg
...上面内容省略...
listen webserver_80
bind 172.25.254.100:80
mode tcp
balance roundrobin
server webserver1 192.168.0.101:80 send-proxy weight 1 check inter 3s fall 3
rise 5
realserver配置文件
#nginx 配置:在访问日志中通过变量$proxy_protocol_addr 记录透传过来的客户端IP
[root@rs1 ~]# vim /etc/nginx/nginx.conf
。。。内容省略。。。
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request"'
' "$proxy_protocol_addr"'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
。。。内容省略。。。
server {
5.3.3 七层IP透传
当haproxy工作在七层的时候,也可以透传客户端真实IP至后端服务器
5.3.3.1 HAProxy配置
在由haproxy发往后端主机的请求报文中添加“X-Forwarded-For"首部,其值为前端客户端的地址;用于
向后端主发送真实的客户端IP
示例:
listen 80 proxy_protocol; #启用此项,将无法直接访问此网站,只能通过四层代理
访问
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
。。。内容省略。。。
}
}
在访问haproxy后查看nginx日志
七层IP透传
修改haproxy主机的配置文件
haproxy ~]# vim /etc/haproxy/haproxy.cfg
...上面内容省略...
listen webserver_80
option forwardfor
bind 172.25.254.100:80
mode http
balance roundrobin
server webserver1 192.168.0.101:80 send-proxy weight 1 check inter 3s fall 3
rise 5
server webserver1 192.168.0.102:80 weight 1 check inter 3s fall 3 rise 5
realserver的nginx配置文件
log_format main '"$proxy_add_x_forwarded_for" - $remote_user [$time_local]
"$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
ACL
域名匹配
haproxy ~]# vim /etc/haproxy/haproxy.cfg
...上面内容省略...
frontend testacl
bind :80
mode http
########### ACL settings #######################
acl web_host hdr_dom(host) www.timinglee.org
########### host ###########################
use_backend timinglee_host if web_host
########### default server ###################
default_backend default_webserver
backend timinglee_host
mode http
server web1 192.168.0.101:80 check weight 1 inter 3s fall 3 rise 5
server web2 192.168.0.102:80 check weight 1 inter 3s fall 3 rise 5
backend default_webserver
mode http
server web1 172.25.254.10:80 check weight 1 inter 3s fall 3 rise 5
...上面内容省略...
测试结果
#在浏览器所在主机中做地址解析
[root@node10 html]# vim /etc/hosts
172.25.254.100 www.timinglee.org
#测试结果
[root@node10 html]# curl www.timinglee.org
RS1 192.168.0.101
[root@node10 html]# curl www.timinglee.org
RS2 server - 192.168.0.102
[root@node10 html]# curl 172.25.254.100
default web server node10
haproxy错误页面
在haproxy中自定义错误界面
[root@cll ~]# vim /haproxy/errorpages/503page.http
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html;charset=UTF-8
<html><body><h1>什么动物生气最安静</h1>
大猩猩!!
</body></html>
[root@cll ~]# vim /etc/haproxy/haproxy.cf
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
errorfile 503 /haproxy/errorpages/503page.http
[root@cll ~]# systemctl restart haproxy.service
关掉realserver的nginx服务,再去验证
pPppppppp
haproxy四层负载
确保realserver上已存在数据库
[root@cll ~]#yum install mariadb-server.x86_64 -y
[root@cll ~]# systemctl start mariadb.service
[root@cll ~]# mysql
#修改数据库id
---------------------------------------------
vim /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
[mysqld]
server-id=2
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
----------------------------------------------
#192.168.183.10
MariaDB [(none)]> select @@server_id
-> ;
+-------------+
| @@server_id |
+-------------+
| 1 |
+-------------+
1 row in set (0.000 sec)
#192.168.183.20
MariaDB [(none)]> select @@server_id;
+-------------+
| @@server_id |
+-------------+
| 2 |
+-------------+
1 row in set (0.000 sec)
在haproxy中写配置
frontend mysql_port
bind :3306
mode tcp
use_backend mysql_rs
backend mysql_rs
mode tcp
balance leastconn
server mysql1 192.168.183.10:3306 check
server mysql2 192.168.183.20:3306 check
在realserver中
[root@cll ~]# mysql -e "grant all on *.* to cll@'%' identified by 'cll';"
[root@cll ~]# mysql -e "grant all on *.* to cll@'%' identified by 'cll';"
测试
在192.168.183.100中测试:
[root@cll ~]# mysql -ucll -pcll -h 192.168.183.10 -e "show variables like 'hostname'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| hostname | cll |
+---------------+-------+
[root@cll ~]# mysql -ucll -pcll -h 192.168.183.20 -e "show variables like 'hostname'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| hostname | cll |
+---------------+-------+
[root@cll ~]# mysql -ucll -pcll -h 192.168.183.10 -e "select @@server_id"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 1 |
+-------------+
[root@cll ~]# mysql -ucll -pcll -h 192.168.183.20 -e "select @@server_id"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 2 |
+-------------+
在client中访问192.168.183.100
C:\Users\cll12>mysql -ucll -pcll -h192.168.183.100 -e "select @@server_id"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 1 |
+-------------+
C:\Users\cll12>mysql -ucll -pcll -h192.168.183.100 -e "select @@server_id"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
| 2 |
+-------------+
HAProxy https 实现
证书制作
制作证书
[root@cll certs]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/haproxy/certs/timinglee.org.key -x509 -days 365 -out /etc/haproxy/certs/timinglee.org.crt
[root@cll ~]# cd /etc/haproxy/certs/
[root@cll certs]# ll
total 12
-rw-r--r-- 1 root root 1350 Jul 20 16:26 timinglee.org.crt
-rw------- 1 root root 1704 Jul 20 16:26 timinglee.org.key
-rw-r--r-- 1 root root 3054 Jul 20 16:26 timinglee.pem
[root@cll certs]# ls
timinglee.org.crt timinglee.org.key timinglee.pem
将证书内容放到一个文件里面---》timinglee.pem
在haproxy中编写https配置文件
frontend webserver
bind *:80
redirect scheme https if !{ ssl_fc }
mode http
use_backend webcluster
frontend webserver-https
bind *:443 ssl crt /etc/haproxy/certs/timinglee.pem
mode http
use_backend webcluster
backend webcluster
mode http
balance roundrobin
server web1 192.168.183.10:80 check inter 3s fall 3 rise 5
server web2 192.168.183.20:80 check inter 3s fall 3 rise 5
测试