HAProxy

负载均衡

什么是负载均衡

负载均衡:Load Balance,简称LB,是一种卓越的技术方案,既可通过专业服务也可依托先进硬件设备实现,作为高可用性的反向代理机制,它巧妙地将繁重的业务负载(包括Web服务、网络流量等)均衡地分散至一个或多个精心选定的后端服务器上。这一过程不仅极大地提升了公司业务的并发处理能力,确保了服务在高峰时段依然稳定可靠,还为企业未来的业务扩展铺平了道路,实现了灵活的水平动态扩展能力,助力企业应对日益增长的业务需求。

为什么用负载均衡

HAProxy作为一款卓越的负载均衡解决方案,高效地将用户请求智能分发至多个服务器,显著提升系统整体可用性与性能。它灵活运用多种负载均衡算法(包括轮询、加权轮询及IP哈希等),实现请求分配的精准控制。此外,HAProxy还集成了会话保持、健康检查与SSL终止等关键功能,确保服务持续稳定运行与数据安全传输。不仅如此,其反向代理、SSL加速及HTTP压缩等特性,更是进一步增强了其作为全方位代理软件的强大能力。

Web服务器的动态水平扩展–>对用户无感知

增加业务并发访问及处理能力–>解决单服务器瓶颈问题

节约公网IP地址–>降低IT支出成本

隐藏内部服务器IP–>提高内部服务器安全性

配置简单–>固定格式的配置文件

功能丰富–>支持四层和七层,支持动态下线主机

性能较强–>并发数万甚至数十万

负载均衡的类型

硬件负载均衡

F5 美国F5网络公司 https://f5.com/zh

Netscaler 美国思杰公司 https://www.citrix.com.cn/products/citrix-adc/

Array 华耀 https://www.arraynetwaorks.com.cn/

AD-1000 深信服 http://www.sangfor.com.cn/

四层负载均衡

1.通过ip+port决定负载均衡的去向。

2.对流量请求进行NAT处理,转发至后台服务器。

3.记录tcp、udp流量分别是由哪台服务器处理,后续该请求连接的流量都通过该服务器处理。

4.支持四层的软件

lvs:重量级四层负载均衡器。

Nginx:轻量级四层负载均衡器,可缓存。(nginx四层是通过upstream模块)

Haproxy:模拟四层转发。

七层负载均衡

1.通过虚拟ur|或主机ip进行流量识别,根据应用层信息进行解析,决定是否需要进行负载均衡。

2.代理后台服务器与客户端建立连接,如nginx可代理前后端,与前端客户端tcp连接,与后端服务器建立 tcp连接

3.支持7层代理的软件:

Nginx:基于http协议(nginx七层是通过proxy_pass)

Haproxy:七层代理,会话保持、标记、路径转移等

四层和七层负载均衡的区别

四到七层负载均衡机制在分配后端服务器流量时,依据网络协议的不同层次信息进行决策。四层负载均衡聚焦于传输层(TCP/UDP),通过IP地址与端口号识别需处理的流量,进行NAT转换后转发至后端服务器,并维护TCP/UDP连接的持续性,确保同一连接的数据包始终发往同一服务器。而七层负载均衡则进一步深入至应用层,除了基于IP与端口,还考虑URL、浏览器类型、语言等应用层特性来优化负载分配,提供更精细化的流量管理。

在架构位置上,四层负载均衡作用于传输层及以下,以高效处理网络吞吐量;七层则深入应用层及以下,支持内容解析,识别更多上下文信息。从性能角度看,四层因无需解析报文内容而拥有更高的吞吐量;七层则凭借对应用层内容的理解,实现更智能的负载均衡决策。

原理上,四层负载均衡基于IP+端口进行决策,类似于路由器的转发机制;七层则依据虚拟URL或主机IP等应用层信息,类似于代理服务器的行为。在安全性方面,四层负载均衡对DDoS等攻击识别能力有限;七层则能防御如SYN Flood等针对应用层的攻击。

以TCP为例,四层负载均衡在接收到客户端的SYN请求时,即根据预设规则选择最佳服务器,并修改目标IP后转发,整个TCP连接过程由客户端与服务器直接建立,负载均衡器仅作为透明的转发节点存在,有时还需调整源地址以确保数据包正确返回。

haproxy简介

HAProxy是法国开发者威利塔罗(Willy Tarreau)在2000年使用C语言开发的一个开源软件,是一款具备高并发(万级以上)、高性能的TCP和HTTP负载均衡器。支持基于cookie的持久性,自动故障切换,支持正则表达式及web状态统计。

企业版网站:https://www.haproxy.com
社区版网站:http://www.haproxy.org
github:https://github.com/haprox

haproxy实验环境的部署

注:所有主机的防火墙均为关闭状态,否则会影响实验!

前提:所有主机的防火墙均为关闭状态

克隆三台虚拟机RHEL9.4。分别为haproxy、webserver1、webserver2三台主机

haproxy:网卡eth0、IP为172.25.254.100、主机名为haproxy.example.com

webserver1:网卡eth0、IP为172.25.254.10、主机名为webserver1.example.com

webserver2:网卡eth0、IP为172.25.254.20、主机名为webserver2.example.com

在两台webserver上安装nginx

[root@webserver1 ~]# dnf install nginx -y

[root@webserver2 ~]# dnf install nginx -y

[root@webserver1 ~]# echo webserver1:172.25.254.10 > /usr/share/nginx/html/index.html
[root@webserver1 ~]# systemctl enable --now nginx.service 
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.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

# 客户端访问
[root@haproxy ~]# curl 172.25.254.10
webserver1:172.25.254.10
[root@haproxy ~]# curl 172.25.254.20
webserver2:172.25.254.20

haproxy基本配置信息

官方文档:HAProxy Documentation Converter

HAProxy的配置文件haproxy.cfg由两大部分组成,分别是:

global:全局配置段

1.进程及安全配置相关的参数

2.性能调整相关参数

3.Debug参数

proxies:代理配置段

1.defaults:为frontend,backend,listen提供默认配置

2.frontend:前端,相当于nginx中的server {}

3.backend:后端,相当于nginx中的upstream {}

4.listen:同时拥有前端和后端配置,配置简单,生产推荐使用

# 在haproxy主机上安装haproxy
[root@haproxy ~]# dnf install haproxy -y

# 配置文件设定
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
# 将以下内容写入配置文件中
frontend webcluster
    bind *:80
    mode http
    use_backend webcluster-host

backend webcluster-host
    balance roundrobin
    server  web1 172.25.254.10:80
    server  web2 172.25.254.20:80

[root@haproxy ~]# systemctl restart haproxy.service
[root@haproxy ~]# systemctl enable haproxy.service 
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service → /usr/lib/systemd/system/haproxy.service.


#本机访问
[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0   9211      0 --:--:-- --:--:-- --:--:-- 12500
webserver1:172.25.254.10

[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0  10660      0 --:--:-- --:--:-- --:--:-- 12500
webserver2:172.25.254.20


# 将前后端合并,将之前写的注释掉,把以下内容写进去
#frontend webcluster
 #   bind *:80
  #  mode http
   # use_backend webcluster-host

#backend webcluster-host
 #   balance roundrobin
  #  server  web1 172.25.254.10:80
   # server  web2 172.25.254.20:80

listen webcluster
   bind *:80
   mode http
   balance roundrobin
   server  web1 172.25.254.10:80
   server  web2 172.25.254.20:80
   
# 重启服务,客户端访问。实验效果跟上面一样
[root@haproxy ~]# systemctl restart haproxy.service
[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0  10084      0 --:--:-- --:--:-- --:--:-- 12500
webserver1:172.25.254.10

[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0  11876      0 --:--:-- --:--:-- --:--:-- 12500
webserver2:172.25.254.20

haproxy的全局配置参数

配置参数

[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(32904)---haproxy(32906)---{haproxy}(32907)

# 将`nbproc 2`添加到配置文件的global中
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
nbproc 2 # 启用多进程
[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(32924)-+-haproxy(32926)
           |                `-haproxy(32927)
# 系统中的线程数量并不是越多越好,跟CPU的核心数量有关。

	cpu-map 1 0 # 进程和CPU核心绑定 防止CPU抖动从而减伤系统资源消耗
    cpu-map 2 1 # 2表示第二个进程,0表示第一个CPU核心,1表示第二个CPU核心

[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(32957)-+-haproxy(32959)
           |                `-haproxy(32960)
           
# 多线程与多进程互斥,多进程与多线程同时设定重启服务的时候会报错
# 查看多线程数量 32960为haproxy子进程的id
[root@haproxy ~]# cat /proc/32960/status | grep -i thread
Threads:	1
Speculation_Store_Bypass:	thread vulnerable

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
········
global
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     100000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

    # utilize system-wide crypto-policies
    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM
    #nbproc 2
    #cpu-map 1 0
    #cpu-map 2 1
    nbthread 2
    
    
    ·······
    
[root@haproxy ~]# systemctl restart haproxy.service 
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(33009)---haproxy(33011)---{haproxy}(33012)
[root@haproxy ~]# cat /proc/33011/status | grep -i thread
Threads:	2
Speculation_Store_Bypass:	thread vulnerable


日志分离

定向haproxy日志

[root@haproxy ~]# vim /etc/rsyslog.conf
···
# 将这两行注释打开
#打开udp端口
#module(load="imudp") # needs to be done just once
#input(type="imudp" port="514")
module(load="imudp") # needs to be done just once
input(type="imudp" port="514")

····
# Log cron stuff
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
*.emerg                                                 :omusrmsg:*

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log
local2.*                                                /var/log/haproxy.log


·····

[root@haproxy ~]# ll /var/log/haproxy.log
ls: cannot access '/var/log/haproxy.log': No such file or directory
[root@haproxy ~]# systemctl restart rsyslog.service


proxies配置

proxies配置-defaults

Proxies配置-frontend

bind:指定HAProxy的监听地址,可以是IPV4或IPV6,可以同时监听多个IP或端口,可同时用于listen字段中

#格式:

bind [

]:<port_range> [, …] [param*] #注意:如果需要绑定在非本机的IP,需要开启内核参数:net.ipv4.ip_nonlocal_bind=1

backlog #针对所有server配置,当前端服务器的连接数达到上限后的后援队列长度,注意:不支持backend

Proxies配置backend

定义一组后端服务器,backend服务器将被frontend进行调用。

注: backend 的名称必须唯一,并且必须在listen或frontend中事先定义才可以使用,否则服务无法启动

mode http|tcp #指定负载协议类型,和对应的frontend必须一致

option #配置选项

server #定义后端real server,必须指定IP和端口

server配置

haproxy的热更新方法

socat

服务器动态权重与状态调整可借助强大的Linux工具——Socat,它作为Socket CAT的简称,是netcat的进阶版。Socat的核心优势在于能轻松构建两个数据流间的双向通道,广泛支持IP、TCP、UDP、IPv6及Socket文件等多种协议与连接方式,为服务器管理与调优提供了极大的灵活性。

修改配置文件

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
stats socket /var/lib/haproxy/stats mode 600 level admin

查看haproxy状态

[root@haproxy ~]# echo "show info" | socat stdio /var/lib/haproxy/stats
Name: HAProxy
Version: 2.4.22-f8e3218
Release_date: 2023/02/14
Nbthread: 1
Nbproc: 1
Process_num: 1
Pid: 33542
Uptime: 0d 0h03m43s
Uptime_sec: 223
Memmax_MB: 0
PoolAlloc_MB: 0

查看集群状态

[root@haproxy ~]# echo "show servers state" | socat stdio /var/lib/haproxy/stats
1
# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight
srv_iweight srv_time_since_last_change srv_check_status srv_check_result
srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id
srv_fqdn srv_port srvrecord srv_use_ssl srv_check_port srv_check_addr
srv_agent_addr srv_agent_port
2 webcluster 1 web1 172.25.254.20 2 0 2 2 188 6 3 7 6 0 0 0 - 80 - 0 0 - - 0
2 webcluster 2 web2 172.25.254.30 2 0 1 1 188 6 3 7 6 0 0 0 - 80 - 0 0 - - 0
4 static 1 static 127.0.0.1 0 0 1 1 187 8 2 0 6 0 0 0 - 4331 - 0 0 - - 0
5 app 1 app1 127.0.0.1 0 0 1 1 187 8 2 0 6 0 0 0 - 5001 - 0 0 - - 0
5 app 2 app2 127.0.0.1 0 0 1 1 187 8 2 0 6 0 0 0 - 5002 - 0 0 - - 0
5 app 3 app3 127.0.0.1 0 0 1 1 186 8 2 0 6 0 0 0 - 5003 - 0 0 - - 0
5 app 4 app4 127.0.0.1 0 0 1 1 186 8 2 0 6 0 0 0 - 5004 - 0 0 - - 0

查看集群权重

[root@haproxy ~]# echo get weight webcluster/web1 | socat stdio
/var/lib/haproxy/stats
2 (initial 2)
[root@haproxy ~]# echo get weight webcluster/web2 | socat stdio
/var/lib/haproxy/stats
1 (initial 1)

设置权重

[root@haproxy ~]# echo "set weight webcluster/web1 1 " | socat stdio
/var/lib/haproxy/stats
[root@haproxy ~]# echo "set weight webcluster/web1 2 " | socat stdio
/var/lib/haproxy/stats

下线后端服务器

[root@haproxy ~]# echo "disable server webcluster/web1 " | socat stdio
/var/lib/haproxy/stats

上线后端服务器

[root@haproxy ~]# echo "enable server webcluster/web1 " | socat stdio
/var/lib/haproxy/stats

多进程处理方法

编辑配置文件

[root@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

haproxy算法

静态算法

静态算法遵循预设规则进行轮询调度,不考量后端服务器的实时负载、连接数或响应速度,且权重调整受限(仅限于0和1),变更需重启HAProxy方能生效,缺乏动态适应性与灵活性。

static-rr:基于权重的轮询调度

该负载均衡方案不支持在运行时通过socat进行权重的动态调整,权重设置仅限于0和1,缺乏中间值支持,调整时需重启HAProxy。同时,不具备慢启动机制,即新启动的服务器无法逐步增加负载,需直接承受完整访问压力。然而,其后端主机数量无上限,类似于LVS中的wrr策略,展现了强大的扩展能力。

示例

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
--------------以上内容省略------------------
listen webcluster
   bind *:80
   mode http
   #balance first
   balance static-rr
   server  web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 2
   server  web2 172.25.254.20:80 check inter 2 fall 3 rise 5 weight 1
   
------------以下内容省略------------------------
[root@haproxy ~]# systemctl restart haproxy.service

#测试
[root@test ~]# for i in {1..10}; do curl 172.25.254.100; done
webserver2:172.25.254.20
webserver1:172.25.254.10
webserver2:172.25.254.20
webserver1:172.25.254.10
webserver2:172.25.254.20
webserver1:172.25.254.10
webserver2:172.25.254.20
webserver1:172.25.254.10
webserver2:172.25.254.20
webserver1:172.25.254.10

first(很少用)

按照服务器列表中的顺序,自上而下依次分配请求。

仅当首台服务器连接数满载时,新请求才会转向下一台服务器。

此方案不采纳服务器权重设置,调度过程不受权重影响。

不支持socat动态调整权重,设置非0即1外的值将不生效。

动态算法

根据后端服务器的实时负载状态,动态调整调度策略,优先将新请求分配给负载较低的服务器。

支持在HAProxy运行时动态调整服务器权重,无需重启服务即可实现负载均衡优化。

静态算法下,后端Real Server的数量无上限,满足大规模部署需求。

roundrobin

基于权重的轮询动态调度算法

支持权重的运行时调整,不同于Ivs中的rr轮训模式

HAProxy中的roundrobin支持慢启动(新加的服务器会逐渐增加转发数)

其每个后端backend中最多支持4095个real server

支持对real server权重动态调整

roundrobin为默认调度算法,此算法使用广泛

示例

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
--------------以上内容省略------------------
listen webcluster
   bind *:80
   mode http
   balance roundrobin
   server  web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 2
   server  web2 172.25.254.20:80 check inter 2 fall 3 rise 5 weight 1
   
------------以下内容省略------------------------
[root@haproxy ~]# systemctl restart haproxy.service

leastconn

leastconn加权的最少连接的动态

此调度策略优先考虑当前连接数最少的后端服务器进行新连接的分配,同时支持权重的运行时调整,实现类似LVS中wlc(加权最少连接)的功能。在连接数相近的情况下,会倾向于选择权重较高的服务器,但连接数仍为首要考量因素。此机制尤其适用于长连接场景,如MySQL数据库等,能够有效平衡服务器负载,提升整体服务性能。

示例

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
--------------以上内容省略------------------
listen webcluster
   bind *:80
   mode http
   balance leastconn
   server  web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 2
   server  web2 172.25.254.20:80 check inter 2 fall 3 rise 5 weight 1
   
------------以下内容省略------------------------
[root@haproxy ~]# systemctl restart haproxy.service

random

基于随机数作为一致性hash的key,随机负载平衡对于大型服务器场或经常添加或删除服务器非常有用,支持weight的动态调整,weight较大的主机有更大概率获取新请求。

其他算法

默认不写就是hash-type map-base的静态,hash-type consistent 就是动态的。

source

源地址hash,该策略依据客户端源地址的Hash值,将请求定向至特定的后端Web服务器,确保来自同一源地址的后续请求均被转发至同一服务器,实现会话粘性。此方式默认为静态配置,但可通过调整hash-type选项来优化算法。它尤其适用于TCP模式下无需Cookie的场景,为拒绝会话Cookie的客户端提供最佳会话保持体验,同时也适合那些需要Session会话保持但无法依赖Cookie或缓存的环境。在实现源地址Hash时,服务器选取通常采用取模法或一致性Hash两种方式,以灵活应对后端服务器数量的变化。

示例

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
--------------以上内容省略------------------
listen webcluster
   bind *:80
   mode http
   balance source
   server  web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 2
   server  web2 172.25.254.20:80 check inter 2 fall 3 rise 5 weight 1
   
------------以下内容省略------------------------
[root@haproxy ~]# systemctl restart haproxy.service

[root@test ~]# for i in {1..10}; do curl 172.25.254.100; done
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20
webserver2:172.25.254.20

map-base

取模法:

取模法通过对客户端源地址进行Hash计算,并结合后端服务器总权重的取模运算,决定请求的转发目标。此方法虽能实现均衡调度,但本质上是静态的,不支持在线权重调整与慢启动。其核心在于,一旦服务器总权重变动(如服务器增减),将导致整体调度结果大幅调整,影响服务的稳定性。hash-type的默认选项即为该算法。

取模运算简述:

取模运算即求两数相除的余数,如10%7=3。在map-based取模法中,HAProxy基于后端服务器权重的总和,对客户端源IP地址的Hash值进行取模,以此确定请求应转发的服务器。此策略虽实现简便,能有效平均分配请求,但存在两大局限:一是服务器数量变动会显著改变请求分配,二是客户端分布不均时可能导致负载不均衡。

一致性hash

在Linux环境下,HAProxy采用的一致性哈希算法是一种高效的负载均衡策略。该算法通过将后端服务器与客户端请求映射至一个环形哈希空间(通常为0至2^32-1的整数范围),实现了请求的智能化分配。每台服务器基于其唯一标识计算哈希值并定位在环上,而客户端请求则根据相似规则寻找顺时针方向上的首个服务器进行处理。

一致性哈希的核心优势在于其灵活性与稳定性。当服务器集群规模调整(增减服务器)时,仅影响环上相邻区域的请求分配,避免了传统取模法可能引发的全局性变动,从而确保了系统的高可用性和可扩展性。此外,该算法对客户端请求分布不均的情况也具备较好的适应性,有助于实现负载均衡的进一步优化。

值得注意的是,一致性哈希算法支持动态调整,利用如socat等工具可在线修改服务器权重,并融入慢启动机制,以适应不同的负载均衡需求和环境变化,为现代高并发、高可用性服务架构提供了有力支持。

算法

1、后端服务器哈希环点keyA=hash(后端服务器虚拟ip)%(2^32)

2、客户机哈希环点key1=hash(client_ip)%(2^32) 得到的值在[0---4294967295]之间

3、将keyA和key1都放在hash环上,将用户请求调度到离key1最近的keyA对应的后端服务器

Hash对象到后端服务器的映射关系

一致性hash示意图

如何解决hash环偏斜问题

为了优化负载均衡效果,我们可以增加虚拟节点的数量来扩展一致性哈希环的“覆盖度”。首先,根据系统规模、物理节点数量及负载均衡需求,合理设定每个物理节点应创建的虚拟节点数。随后,为各物理节点生成独一无二的虚拟节点标识,这通常通过在其原始标识上附加序号或随机字符串实现。

利用相同的哈希函数,计算这些虚拟节点的哈希值,并将它们均匀地映射到一致性哈希环上。此举显著增加了物理节点在环上的“密度”,使得环上的空间被更加细致地划分。

在处理客户端请求时,计算请求的哈希值后,依据一致性哈希规则,在环上顺时针寻找最近的节点。由于虚拟节点的广泛分布,请求被分配至不同物理节点的概率增加,进而促进了负载的均衡分布。

以三台物理服务器A、B、C为例,若每台服务器均配置10个虚拟节点,则服务器A的虚拟节点标识可依次为A-1至A-10。通过计算这些虚拟节点的哈希值并映射至哈希环,有效扩展了服务器A在环上的“影响范围”,提升了其接收请求分配的可能性,最终实现负载在物理服务器间的更均衡分配。

uri

在用户请求的负载均衡策略中,可以采用对URI(统一资源标识符)的左半部分或完整URI进行哈希计算,并将该哈希值基于后端服务器总权重进行取模操作,以决定请求的最终转发目标。这种策略尤其适用于后端作为缓存服务器的场景,能够基于请求内容智能地分配负载。

默认情况下,该算法为静态配置,但HAProxy允许通过hash-type参数灵活选择map-based(基于映射的取模法)或consistent(一致性哈希)模式,以适应不同的负载均衡需求。需要注意的是,由于该算法依赖于URI信息,它仅适用于HTTP模式下的应用层处理,而不支持TCP模式的直接转发。这一特性确保了负载均衡策略能够更精准地根据请求内容来优化资源分配。

url_param

url_param 是一种负载均衡策略,它能够实现会话(session)保持。具体而言,该策略会提取用户请求URL中查询参数(params)部分的一个特定key对应的value值,对该value值进行哈希计算,并基于后端服务器的总权重来决定请求的转发目标。这种方法非常适合用于追踪用户会话,确保来自同一用户的所有请求都被定向到相同的后端服务器(real server),从而维护会话的一致性。

若请求的URL中不包含该指定的key参数,url_param策略将自动回退到轮询(roundrobin)算法,以均衡地分配请求到各个后端服务器,确保服务的连续性和负载均衡。通过这种灵活的机制,url_param既保证了用户会话的连续性,又能在缺少会话标识时实现基本的负载均衡目标。

示例

#假设:
url = http://www.qwertyu.com/foo/bar/index.php?key=value

#则:
host = “www.qwertyu.com”
url_param = “key=value”

hdr 

在HTTP负载均衡场景中,hdr 指令允许基于客户端请求报文头部的特定信息进行高级处理。具体来说,它会根据配置中指定的HTTP头部名称(由name参数指定),从每个HTTP请求中提取该头部的值,并对其进行哈希计算。随后,根据后端服务器的总权重进行取模运算,以决定请求应被转发至哪个后端服务器。这种机制确保了相同HTTP头部值的请求能够被发送到同一服务器,有助于实现会话保持或特定请求的逻辑分组。

若请求的HTTP头部中不包含指定的名称,或该头部值无效,则hdr指令会回退到默认的轮询(roundrobin)调度算法,以确保请求的均衡分配和服务的连续性。通过hdr指令,HAProxy能够灵活地根据请求头部的不同内容来优化负载均衡策略,满足复杂业务场景的需求。

高级功能

haproxy的状态页面监控

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 

--------以上内容省略-------
listen stats
    mode http
    bind *:4567
    stats enable
    stats refresh 1
    stats uri /status
    stats auth www:www
--------省略----------

[root@haproxy ~]# systemctl restart haproxy.service 

测试

基于cookie的会话保持

cookie value:为当前server指定cookie值,实现基于cookie的会话黏性,相对于基于 source 地址hash调度算法对客户端的粒度更精准,但同时也加大了haproxy负载,目前此模式使用较少, 已经被session共享服务器代替。

当用户发起一系列的请求时,如果没有会话保持机制,每次请求可能会被分发到不同的后端服务器。这可能导致用户会话数据的不一致或丢失,例如购物车信息、登录状态等。基于 Cookie 的会话保持可以确保属于同一会话的请求始终被路由到同一台后端服务器,从而保持会话的一致性和完整性。

示例

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg

······以上内容省略·······

listen webcluster
   bind *:80
   mode http
   balance roundrobin
   cookie WEBCOOKIE insert nocache indirect
   server  web1 172.25.254.10:80 cookie web1 check inter 2 fall 3 rise 5 weight 1
   server  web2 172.25.254.20:80 cookie web2 check inter 2 fall 3 rise 5 weight 1


······以上内容省略·······

[root@haproxy ~]# systemctl restart haproxy.service

IP透传

web服务器中需要记录客户端的真实IP地址,用于做访问统计、安全防护、行为分析、区域排行等场景。

四层透传

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
······以上内容省略·····
listen webcluster
   bind *:80
   mode tcp
   #balance first
   #balance static-rr
   balance roundrobin
   #balance leastconn
   #balance source
   #balance uri
   #balance url_param name,userid
   #balance hdr(User-Agent)
   #hash-type consistent
  # redirect prefix http://www.baidu.com/
   #cookie WEBCOOKIE insert nocache indirect
   server  web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 1
   server  web2 172.25.254.20:80 send-proxy check inter 2 fall 3 rise 5 weight 1
#   server web_sorry 172.25.254.100:8080 backup

······以下内容省略·····

[root@haproxy ~]# systemctl restart haproxy.service

# 此时看日志是看不到访问者的真实IP
[root@webserver1 ~]# tail /etc/httpd/logs/access_log 
 - 172.25.254.100 - - [10/Aug/2024:23:09:56 +0800] "PROXY TCP4 172.25.254.100" 400 226 "-" "-"
 - 172.25.254.100 - - [10/Aug/2024:23:09:56 +0800] "PROXY TCP4 172.25.254.100" 400 226 "-" "-"


[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
listen webcluster
   bind *:80
   mode tcp
   balance roundrobin
   server  web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 2
   server  web2 172.25.254.20:80 send-proxy check inter 2 fall 3 rise 5 weight 1 #send-proxy 做代理


[root@webserver2 ~]# vim /etc/nginx/nginx.conf
····上面内容省略·····

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      ' "$proxy_protocol_addr"'
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

····上面内容省略·····

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 proxy_protocol; #启用此项,将无法直接访问此网站,只能通过四层代理
访问
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

····下面内容省略·····


# 查看日志内容
[root@webserver2 ~]# tail /var/log/nginx/access.log
172.25.254.100 - - [10/Aug/2024:23:06:34 +0800] "PROXY TCP4 172.25.254.100 172.25.254.20 55510 80" 400 0 "-" "-" "-"
172.25.254.100 - - [10/Aug/2024:23:06:34 +0800] "PROXY TCP4 172.25.254.100 172.25.254.20 55526 80" 400 0 "-" "-" "-"


七层IP透传

# haproxy配置
# 在由haproxy发往后端主机的请求报文中添加“X-Forwarded-For"首部,其值为前端客户端的地址;用于向后端主发送真实的客户端IP
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
······以上内容省略·····
listen webcluster
   bind *:80
   mode http
   #balance first
   #balance static-rr
   balance roundrobin
   #balance leastconn
   #balance source
   #balance uri
   #balance url_param name,userid
   #balance hdr(User-Agent)
   #hash-type consistent
  # redirect prefix http://www.baidu.com/
   #cookie WEBCOOKIE insert nocache indirect
   server  web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 1
   server  web2 172.25.254.20:80 send-proxy check inter 2 fall 3 rise 5 weight 1
#   server web_sorry 172.25.254.100:8080 backup

······以下内容省略·····

[root@haproxy ~]# systemctl restart haproxy.service



[root@webserver1 ~]# systemctl disable nginx.service 
[root@webserver1 ~]# systemctl stop nginx.service 
[root@webserver1 ~]# dnf install httpd -y
[root@webserver1 ~]# echo web1 - 172.25.254.10 > /var/www/html/index.html
[root@webserver1 ~]# systemctl start httpd
[root@webserver1 ~]# vi /etc/httpd/conf/httpd.conf 
# 配置web服务器,记录负载均衡透传的客户端IP地址
······以上内容省略·····
	
	LogFormat  "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
······以下内容省略·····


[root@webserver1 ~]# systemctl restart httpd

[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0  10794      0 --:--:-- --:--:-- --:--:-- 12500
webserver2:172.25.254.20

[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    21  100    21    0     0   6231      0 --:--:-- --:--:-- --:--:--  7000
web1 - 172.25.254.10

[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    21  100    21    0     0   7996      0 --:--:-- --:--:-- --:--:-- 10500
web1 - 172.25.254.10

# 加上参数之后就可以在日志中查看客户端访问的真实IP
[root@webserver1 ~]# tail /etc/httpd/logs/access_log 
172.25.254.1 172.25.254.100 - - [10/Aug/2024:22:39:31 +0800] "GET / HTTP/1.1" 200 27 "-" "curl/8.7.1"
172.25.254.1 172.25.254.100 - - [10/Aug/2024:22:41:33 +0800] "GET / HTTP/1.1" 200 27 "-" "curl/8.7.1"
172.25.254.1 172.25.254.100 - - [10/Aug/2024:22:41:34 +0800] "GET / HTTP/1.1" 200 27 "-" "curl/8.7.1"


ACL访问控制列表

访问控制列表ACL,Access Control Lists)是一种基于包过滤的访问控制技术。

它可以根据设定的条件对经过服务器传输的数据包进行过滤(条件匹配)即对接收到的报文进行匹配和过滤,基于请求报文头部中的源地址、源端口、目标地址、目标端口、请求方法、URL、文件后缀等信息内容进行匹配并执行进一步操作,比如允许其通过或丢弃。

frontend webcluster
     bind *:80
     mode http
     acl test hdr_dom(host) -i www.abc.org
     use_backend webcluster-host if test
     default_backend default-host

backend webcluster-host
     mode http
     server web1 172.25.254.10:80 check inter 2 fall 2 rise 5

backend default-host
     mode http
     server web2 172.25.254.20:80 check inter 2 fall 2 rise 5

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
[root@haproxy ~]# systemctl restart haproxy.service 

# 满足条件的时候访问webcluster-host,不满足条件默认访问default-host。在做这个之前记得把上面在webserver2上做的IP透传的代码给注释掉,不然访问的时候会报502的错误。在Windows上面也要做本地解析。
[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0  12130      0 --:--:-- --:--:-- --:--:-- 12500
webserver2:172.25.254.20

[C:\~]$ curl www.abc.org
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    21  100    21    0     0   2300      0 --:--:-- --:--:-- --:--:--  3000
web1 - 172.25.254.10



利用ACL做动静分离访问控制

# 基于域名的访问控制
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
frontend webcluster
     bind *:80
     mode http
     acl domain hdr_dom(host) -i www.abc.org

#####################################################

     use_backend webcluster-host if domain
     default_backend default-host

backend webcluster-host
     mode http
     server web1 172.25.254.10:80 check inter 2 fall 2 rise 5

backend default-host
     mode http
     server web2 172.25.254.20:80 check inter 2 fall 2 rise 5



# 只有访问www.abc.org域名的时候才会去访问webserver1,否则访问webserver2
[C:\~]$ curl www.abc.org
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    21  100    21    0     0   3558      0 --:--:-- --:--:-- --:--:--  7000
web1 - 172.25.254.10

[C:\~]$ curl www.abc.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    25  100    25    0     0   2763      0 --:--:-- --:--:-- --:--:--  3571
webserver2:172.25.254.20


# 基于IP的访问控制
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
frontend webcluster
     bind *:80
     mode http
     acl ctrl_ip src 172.25.254.1  172.25.254.20  192.168.0.0/24 # 这里可以写具体的IP地址也可以写网段

#####################################################

     use_backend webcluster-host if ctrl_ip
     default_backend default-host

backend webcluster-host
     mode http
     server web1 172.25.254.10:80 check inter 2 fall 2 rise 5

backend default-host
     mode http
     server web2 172.25.254.20:80 check inter 2 fall 2 rise 5

# 符合条件的访问webserver1,不符合的访问webserver2
[C:\~]$ curl www.abc.com  #本机的IP为172.25.254.1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    21  100    21    0     0   2151      0 --:--:-- --:--:-- --:--:--  3000
web1 - 172.25.254.10
[root@webserver2 ~]# curl 172.25.254.100
web1 - 172.25.254.10
[root@test ~]# curl 172.25.254.100   #这台主机为172.25.254.77
webserver2:172.25.254.20

# 拒绝IP访问
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
frontend webcluster
     bind *:80
     mode http
     acl ctrl_ip src 172.25.254.1  172.25.254.20  192.168.0.0/24

#####################################################

     http-request deny if ctrl_ip
     default_backend default-host

backend webcluster-host
     mode http
     server web1 172.25.254.10:80 check inter 2 fall 2 rise 5

backend default-host
     mode http
     server web2 172.25.254.20:80 check inter 2 fall 2 rise 5


[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    93  100    93    0     0  64898      0 --:--:-- --:--:-- --:--:-- 93000
<html><body><h1>403 Forbidden</h1>
                                  Request forbidden by administrative rules.
                                                                            </body></html>
[root@test ~]# curl 172.25.254.100
webserver2:172.25.254.20

# 基于浏览器类型的访问控制
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
frontend webcluster
     bind *:80
     mode http
     acl badwebbrowers hdr_sub(User-Agent) -i curl wget

#####################################################

     http-request deny if badwebbrowers
     default_backend default-host

backend webcluster-host
     mode http
     server web1 172.25.254.10:80 check inter 2 fall 2 rise 5

backend default-host
     mode http
     server web2 172.25.254.20:80 check inter 2 fall 2 rise 5

[C:\~]$ curl 172.25.254.100
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    93  100    93    0     0  62207      0 --:--:-- --:--:-- --:--:-- 93000
<html><body><h1>403 Forbidden</h1>
                                  Request forbidden by administrative rules.
                                                                            </body></html>



基于后缀名实现动静分离

[root@webserver1 ~]# dnf install php -y
[root@webserver1 ~]# vim /var/www/html/index.php
<?php
        phpinfo();
?>



[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
frontend webcluster
     bind *:80
     mode http
     acl static path_end -i .html .jpg .png .css .js  # 静态 
     acl php    path_end -i .php  # 动态

#####################################################

    use_backend webcluster-host if php  
    default_backend default-host   

backend webcluster-host
     mode http
     server web1 172.25.254.10:80 check inter 2 fall 2 rise 5

backend default-host
     mode http
     server web2 172.25.254.20:80 check inter 2 fall 2 rise 5


# 只有webserver1上做了php,所以访问到以.php结尾的就会到php的页面,访问其他的就会默认去访问webserver2,以此来实现动静分离

基于访问路径实现动静分离

[root@webserver2 ~]# mkdir /usr/share/nginx/html/static -p
[root@webserver2 ~]# echo static - 172.25.254.20 > /usr/share/nginx/html/static/index.html 
[root@webserver2 ~]# 
[root@webserver2 ~]# curl 172.25.254.20/static/
static - 172.25.254.20

[root@webserver1 ~]# mkdir -p /var/www/html/php
[root@webserver1 ~]# cp /var/www/html/index.php /var/www/html/php/


[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
frontend webcluster
     bind *:80
     mode http
     acl static path_sub -m sub static
     acl php    path_sub -m sub php

#####################################################

    use_backend webcluster-host if php
    default_backend default-host

backend webcluster-host
     mode http
     server web1 172.25.254.10:80 check inter 2 fall 2 rise 5

backend default-host
     mode http
     server web2 172.25.254.20:80 check inter 2 fall 2 rise 5

基于http重定向错误页面

[root@webserver1 ~]# systemctl stop httpd.service

[root@webserver2 ~]# systemctl stop nginx.service

[root@haproxy ~]# mkdir /etc/haproxy/errorpage -p
[root@haproxy ~]# vim /etc/haproxy/errorpage/503.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@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
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 /etc/haproxy/errorpage/503.http
    
[root@haproxy ~]# systemctl restart haproxy.service
    

haproxy四层负载

[root@webserver1 ~]# dnf install mariadb-server -y

[root@webserver2 ~]# dnf install mariadb-server -y


[root@webserver1 ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server-id=1  # 设定webserver1上的数据库id为1,为了区分实现实验效果
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid

[root@webserver1 ~]# systemctl start mariadb

[root@webserver1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT @@server_id;
+-------------+
| @@server_id |
+-------------+
|           1 |
+-------------+
1 row in set (0.000 sec)

MariaDB [(none)]> create user wcm@'%' identified by 'wcm';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> grant all on *.* to wcm@'%';
Query OK, 0 rows affected (0.001 sec) 



[root@webserver2 ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server-id=2 
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid

[root@webserver2 ~]# systemctl start mariadb

[root@webserver2 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT @@server_id;
+-------------+
| @@server_id |
+-------------+
|           2 |
+-------------+
1 row in set (0.000 sec)

MariaDB [(none)]> create user wcm@'%' identified by 'wcm';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> grant all on *.* to wcm@'%';
Query OK, 0 rows affected (0.001 sec)




[root@test ~]# dnf install mariadb -y

[root@test ~]# mysql -uwcm -p -h 172.25.254.10
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 


# 做负载
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 

listen dbserver
    bind *:3306
    mode tcp
    balance roundrobin
    server db1 172.25.254.10:3306 check inter 2 fall 2 rise 5
    server db2 172.25.254.20:3306 check inter 2 fall 2 rise 5

[root@haproxy ~]# systemctl restart haproxy.service


# test为测试机
[root@test ~]# mysql -uwcm -pwcm -h 172.25.254.100
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|           1 |
+-------------+
1 row in set (0.001 sec)

MariaDB [(none)]> exit
Bye
[root@test ~]# mysql -uwcm -pwcm -h 172.25.254.100
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|           2 |
+-------------+
1 row in set (0.001 sec)


haproxy的基于https的加密访问

[root@haproxy ~]# mkdir -p /etc/haproxy/certs
[root@haproxy ~]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/haproxy/certs/wcm.com.key -x509 -days 365 -out /etc/haproxy/certs/wcm.com.crt
.+..........+...........+..........+.....+...+.......+...+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...........+.......+......+.........+...+.........+..............+.+...+...+...+......+......+........+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+.+..............+...+...+...+.......+..............+..........+.........+..+....+...+...+...+.....+.+...+......+......+.....+......+...+...............+....+...+.....+..........+.................+.+.....+....+.....+............+...+.............+..+...+...+....+...+..+...+.........+.........+.......+.................+.+.....+....+...............+..+.+........+.+...........+....+...........+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
....+...+............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*......+...+...+.....+...+......+....+..+...+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+..+...+.........+....+......+.....+....+..+...+......+...+..........+......+............+.....+.......+.....+.+......+...+...+........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:ShanXi
Locality Name (eg, city) [Default City]:XiAn
Organization Name (eg, company) [Default Company Ltd]:wcm
Organizational Unit Name (eg, section) []:web
Common Name (eg, your name or your server's hostname) []:www.wcm.com
Email Address []:admin@wcm.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值