当前位置: 首页 > news >正文

Haproxy简介及配置详解

一、Haproxy简介

官网:

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

Haproxy是法国人Willy Tarreaus开发的一款开源软件,能够提供高性能、负载均衡以及基于HTTP和TCP应用个代理,支持虚拟机,特别适用于负载大的web站点(这些站点通常需要七层处理)。

Haproxy的配置文件haproxy.cfg由globle和proxies两部分组成。

1.1 Haproxy的配置文件

Haproxy的配置文件haproxy.cfg由globle和proxies两部分组成。

globle:

(1)进程及安全相关的参数

(2)性能调整相关参数

(3)Debug参数

1.2 globle 配置参数说明

参数作用
log 127.0.0.1 local3 wa定义Haproxy日志输出设置
ulimit -n 82000设置每个进程的可用的最大文件描述符
chroot锁定目录运行
nbproc n开启进程数
pidfile指定pid文件路径,与servise指定pid路径一样
ndthread多线程(不能与单线程同时启用)
maxconn/maxlssconn/maxconnrate + n最大连接数/配备证书的前提下ssl最大连接数/连接速率(每个进程)
chroot /usr/local/haproxychroot运行路径
uid 99/gid 99运行haproxy 用户 UID/用户组gid
 spread-checks + n后端服务check随机提前或延迟的百分比时间
daemon以后台形式运行harpoxy
nbproc(多进程)+n可设置进程数量
pidfile/usr/local/haproxy/run/haproxy.pidhaproxy 进程PID文件
debughaproxy调试级别,建议只在开启单进程的时候调试
cpu-map +进程数+cpu号绑定hap进程至指定cpu
stats / socket套接字文件,处于协议与应用层中间,相当于虚拟的门

1.3 多进程和线程展示

启用多进程,修改配置文件  /etc/haproxy/haproxy.cfg

stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin process 1
stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin process 2
# 启用多个socket文件nbproc 2
# 启用多进程cpu-map 1 0
cpu-map 2 1
# 进程+cpu核心

查看信息

启用多线成,继续进入 /etc/haproxy/haproxy.cfg 并修改配置文件

nbthread 2
# 将文件中的多进程关闭,开启多线程

1.4 proxies 配置参数说明

参数作用
default默认配置,针对fronted、backend、listen生效,name可有可无
frontend前端servername,类似Nginx的一个虚拟主机server和LVS的服务集群
backend后端服务器,等于LVS 的RS服务器
listen将frontend和backend合并在一起,使之更简洁

1.4.1 四种配置参数详情

defaults

参数作用
option redispatch当server Id对应的服务器挂掉后,强制定向到其他健康的服务器,重新派发
option abortonclose当服务器负载很高时,自动结束掉当前队列处理比较久的连接,针对业务情况选择开启
option http-keep-alive开启与客户端的会话保持
option forwardfor透传客户端RIP至后端web服务器
mode http|tcp设置默认工作类型,使用TCP更好,减少压力
timeout http-keep-alive 120ssession会话保持超时时间,此时间段内会转发到相同的后端服务器
timeout connect 120s客户端请求从haproxy到后端server最长连接等待时间(TCP连接之前),默认单位ms
timeout server 600s客户端请求从haproxy到后端服务端的请求处理超时时长(TCP连接之后),默认单位ms,如果超时,会出现502错误,把这个值设置大一点,可以有效地避免502
timeout client 600s设置haproxy与客户端的最长非活动时间,默认单位ms
timeout check   2s对后端服务器的默认检测超时时间
 
default-server inter 2 weight 3指定后端服务器的默认设置

defaults

参数作用
bind指定haproxy(以后简称hap)的监听地址,IPV4/IPV6都ok,可同时监听多个IP或者端口
backend
参数作用
mode http|tcp指定负载协议类型,和对应的frontend一致
option配置选项
server定义后端real server.必须指定IP和端口

1.5 小小实验

1、server配置

在server配置中,我们可以使用check进行健康检测,check必须手动添加,否则默认不开启检查,如果只有check,没有后面的内容,也可以进行健康检测。但是在添加check后面连接的内容时,必须指定IP和端口,才能实现健康检测

参数作用
addr + IP指定进行健康检测的IP,减少业务网络的流量
port + 端口指定进行健康检测的端口号
inter + 间隔时间健康检测间隔时间,默认为2000ms
fall + n服务器从线上转为线下的检查的连续失败次数,默认3
rise + n与fall作用相反,线下---->线上,默认2
weight默认1,最大256,0表示不参与负载,但是仍然接受连接
backup备份服务器,相当于sorry server
disable将服务器标记为不可用状态,不再接受用户请求
redirect prefix / redir http://www.baidu.com/ 将临时请求定向至baidu,只能在http服务中使用
maxconn后端服务最大连接数

实验演示:

进入配置文件修改

backend yee-webserver-80-RS
server web1 172.25.254.10:80  check inter 4 fall 3 rise 2 weight 1
server web2 172.25.254.20:80  check inter 4 fall 3 rise 2 weight 1

测试

[root@client ~]# for N in {1..10}
> do
> curl 172.25.254.100
> done
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
webserver2 - 172.25.254.20

2、listen简化配置

listen webserver_80
bind 172.25.254.100:80
mode http
option forwardfor
server web1 172.25.254.10:80  check inter 4 fall 3 rise 2 weight 1
server web2 172.25.254.20:80  check inter 4 fall 3 rise 2 weight 1

3、针对对进程的处理方式

stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin process 1
stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin process 2
nbproc 2
cpu-map 1 0
cpu-map 2 1

二、haproxy的算法

2.1 静态算法

按照指定好的规则轮询公平调度,不考虑服务器的当前负载、连接数和其他因素,并且不能实时修改权重,只能重启haproxy使之生效。

2.1.1慢启动---static-rr

listen webserver_80bind 172.25.254.100:80mode httpbalance static-rrserver web1 172.25.254.10:80  check inter 3s fall 3 rise 2server web2 172.25.254.20:80  check inter 3s fall 3 rise 2

2.1.2 first

  listen webserver_80bind 172.25.254.100:80mode http balance firstserver web1 172.25.254.10:80 maxconn 3 check inter 3s fall 3 rise 5server web2 172.25.254.20:80  check inter 3s fall 3 rise 2

2.2 动态算法

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

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

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

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

⑤支持对real server权重动态调整

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

2.2.1roundrobin

修改脚本:

listen webserver_80bind 172.25.254.100:80mode httpbalance roundrobinserver web1 172.25.254.10:80  check inter 3s fall 3 rise 2server web2 172.25.254.20:80  check inter 3s fall 3 rise 2

动态调整权重:

[root@hap ~]# echo "set weight webserver_80/web1 2" | socat stdio /var/lib/haproxy/haproxy.sock

2.2.3 leastconn

与上述操作相同,修改脚本即可。

2.3 其他算法

2.3.1 sourse

基于用户源地址hash并将请求转发到后端服务器,并且后续同一个源地址请求将被转发至同一个web服务器。用法:修改 balance sourse,测试结果为:

两种算法 

map-base取模法:计算两个数相除之后的余数  10%7=3   hash(sourse_ip)%所有web相加的总权重。

一致性hash:就是hash函数(hashcode%size)的size保持不变,从而保证了hash函数的前后一致性。

listen webserver_80bind 172.25.254.100:80mode httpbalance urihash-type consistentserver web1 172.25.254.10:80  check inter 2 fall 3 rise 5 weight 2server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1

2.3.2 uri

对用户请求的uri的左半部分或者整个uri做hash,再将hash结果对总权重进行取模处理,最后根据最终结果将请求转发到指定的web服务器。取模使用的依旧是一致性hash,且此算法只能在应用层进行,只支持mode http。

1、uri取模示例

listen webserver_80bind 172.25.254.100:80mode httpbalance uriserver web1 172.25.254.10:80  check inter 2 fall 3 rise 5 weight 2server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1

2、uri一致性hash

listen webserver_80bind 172.25.254.100:80mode httpbalance urihash-type consistentserver web1 172.25.254.10:80  check inter 2 fall 3 rise 5 weight 2server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1

3、测试

web1:
[root@w1 ~]# echo 172.25.254.10 - index1.html > /usr/share/nginx/html/index1.html
[root@w1 ~]# echo 172.25.254.10 - index2.html > /usr/share/nginx/html/index2.html
[root@w1 ~]# echo 172.25.254.10 - index3.html > /usr/share/nginx/html/index3.htmlweb2:
[root@w2 ~]# echo 172.25.254.20 - index1.html > /usr/share/nginx/html/index1.html
[root@w2 ~]# echo 172.25.254.20 - index2.html > /usr/share/nginx/html/index2.html
[root@w2 ~]# echo 172.25.254.20 - index3.html > /usr/share/nginx/html/index3.html访问:
[root@client ~]# curl 172.25.254.100/index.html
webserver1 - 172.25.254.10
[root@client ~]# curl 172.25.254.100/index1.html
172.25.254.10 - index1.html
[root@client ~]# curl 172.25.254.100/index2.html
172.25.254.20 - index2.html
[root@client ~]# curl 172.25.254.100/index3.html
172.25.254.10 - index3.html# 访问不同的uri,用户可以将请求转发至相同的服务器

2.3.3 url_param

url_param对用户请求的url中的 params 部分中的一个参数key对应的value值作hash计算,并由服务器总权重相除以后派发至某挑出的服务器,后端搜索同一个数据会被调度到同一个服务器,多用与电商。通常用于追踪用户,以确保来自同一个用户的请求始终发往同一个real server如果无没key,将按roundrobin算法。

1、url_param 取模法

listen webserver_80bind 172.25.254.100:80mode httpbalance url_param name,userid
#  支持多个url_param hashserver web1 172.25.254.10:80  check inter 2 fall 3 rise 5 weight 2server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1

2、url_param 一致性hash

listen webserver_80bind 172.25.254.100:80mode httpbalance url_param name,useridhash-type consistentserver web1 172.25.254.10:80  check inter 2 fall 3 rise 5 weight 2server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1

3、测试

[root@client ~]# curl 172.25.254.100/index3.html?userid=111
172.25.254.10 - index3.html
[root@client ~]# curl 172.25.254.100/index3.html?userid=222
172.25.254.10 - index3.html
[root@client ~]# curl 172.25.254.100/index3.html?userid=333
172.25.254.20 - index3.html
[root@client ~]# curl 172.25.254.100/index3.html?userid=444
172.25.254.10 - index3.html

3.2.4 hrd

针对用户每个http头部(header)请求中的指定信息做hash,此处由 name 指定的http首部将会被取出并做hash计算,然后由服务器总权重取模以后派发至某挑出的服务器,如果无有效值,则会使用默认的轮询调度。

1、hrd取模法

listen webserver_80bind 172.25.254.100:80mode httpbalance hrd(user-Agent)server web1 172.25.254.10:80  check inter 2 fall 3 rise 5 weight 2server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1

2、hrd一致性hash

listen webserver_80bind 172.25.254.100:80mode httpbalance hrd(user-Agent)hash-type consistentserver web1 172.25.254.10:80  check inter 2 fall 3 rise 5 weight 2server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1

3、测试

[root@client ~]# curl -A "yee" 172.25.254.100/index.html
webserver1 - 172.25.254.10
[root@client ~]# curl -A "yee" 172.25.254.100/index.html
webserver2 - 172.25.254.20

三、高级功能配置

3.1 建立在cookie上的会话保持

与sourse地址hash调度算法相比较,cookie对客户端的粒度更加准确,但同时也加大了haproxy的负载。目前使用较少,且只能使用 mode http。

3.1.1 配置示例

listen webserver_80bind 172.25.254.100:80mode httpbalance roundrobincookie WEBCOOKIE insert nocache indirectserver web1 172.25.254.10:80 cookie yee1 check inter 2 fall 3 rise 5 weight 1server web2 172.25.254.20:80 cookie yee2 check inter 2 fall 3 rise 5 weight 1

3.1.2 测试+验证

[root@client ~]# curl -b WEBCOOKIE=yee1 172.25.254.100
webserver1 - 172.25.254.10
[root@client ~]# curl -b WEBCOOKIE=yee2 172.25.254.100
webserver2 - 172.25.254.20
webserver2 - 172.25.254.20
[root@client ~]# curl -i 172.25.254.100
HTTP/1.1 200 OK
server: nginx/1.20.1
date: Sat, 10 Aug 2024 09:19:37 GMT
content-type: text/html
content-length: 27
last-modified: Wed, 07 Aug 2024 08:08:45 GMT
etag: "66b32b8d-1b"
accept-ranges: bytes
set-cookie: WEBCOOKIE=yee1; path=/
cache-control: privatewebserver1 - 172.25.254.10
[root@client ~]# curl -i 172.25.254.100
HTTP/1.1 200 OK
server: nginx/1.20.1
date: Sat, 10 Aug 2024 09:19:40 GMT
content-type: text/html
content-length: 27
last-modified: Wed, 07 Aug 2024 08:09:03 GMT
etag: "66b32b9f-1b"
accept-ranges: bytes
set-cookie: WEBCOOKIE=yee2; path=/
cache-control: private

3.2 haproxy状态页

3.2.1 haproxy状态页配置

参数作用
status enable启用状态页
status hide-version隐藏页面当中的haproxy版本
status refresh设置自动刷新时间间隔,默认不开启自动刷新
status uri自定义status page uri,默认值为:/haproxy?status
status auth+用户:密码认证时的账户和密码。可以定义多个,每行指定一个用户
status admin{ if  |  unless}启用status page 中的管理功能

3.2.2 启用状态页并登录

1、修改配置文件

 listen stats:bind 0.0.0.0:8080mode httpstats enblelog globlestats uri /statusstats auth yee:yee

2、测试

3.2.3 backend server参数说明

session rate:每秒的连接会话信息
cur:每秒的当前会话数量
max:每秒新的最大会话数量
limit:每秒新的会话限制量
sessions:会话信息
cur:当前会话量
max:最大会话量
Errors:错误统计信息
Req:错误请求量
conn:错误链接量
Resp:错误响应量
Warnings:警告统计信息
Retr:重新尝试次数
Redis:再次发送次数
limit: 限制会话量
Total:总共会话量
LBTot:选中一台服务器所用的总时间
Last:和服务器的持续连接时间
Server:real server信息
Status:后端机的状态,包括UP和LastChk:持续检查后端服务器的时
Wght:权重
Bytes:流量统计
Out:网络的字节输出总量
Dwn:后端服务器连接后都是DOWN的数量
Denied:拒绝统计信息
Req:拒绝请求量
Act:活动链接数量
Bck:备份的服务器数量
Chk:心跳检测时间
Dwntme:总的downtime时间
Thrtle:server 状态
Resp:拒绝回复量

3.3 IP透传

3.3.1 layer 4与layer 7

四层负载:把client发送的报文目标地址,根据均衡设备设置的选择web服务器的规则选择对应的web服务器IP地址,这样client就可以直接跟此服务器建立TCP连接并发送数据,而四层负载自身不参与建立连接,而和LVS不同,haproxy是伪四层负载均衡,因为haprox需要分别和前端客户端及后端服务器建立连接。

七层负载:七层负载均衡服务器起了一个反向代理服务器的作用,服务器建立一次TCP连接要三次握手,而client要访问Web Server要先与七层负载设备进行三次握手后建立TCP连接,把要访问的报文信息发送给七层负载均衡;然后七层负载均衡再根据设置的均衡规则选择特定的 Web Server,然后通过三次握手与此台Web Server建立TCP连接,然后Web Server把需要的数据发送给七层负载均衡设备,负载均衡设备再把数据发送给client;所以,七层负载均衡设备起到了代理服务器的作用,七层代理需要和Client和后端服务器分别建立连接。

3.3.2 开启四层IP透传服务

1、在web1修改配置文件/etc/nginx/nginx.conf以下内容

2、在haproxy修改配置文件/etc/haproxy/haproxy.cfg以下内容

  listen stats:bind 172.25.254.100:80mode tcpbalance roundrobinserver web1 172.25.254.10:80 send-proxy check inter 2 fall 3 rise 5 weight 1

3、查看日志内容

3.3.3 开启七层IP透传服务

1、修改配置文件

listen stats:bind 172.25.254.100:80mode tcpbalance roundrobinoption forwardforserver web1 172.25.254.10:80 send-proxy check inter 2 fall 3 rise 5 weight 1server web2 172.25.254.20:80  check inter 2 fall 3 rise 5 weight 1#apache 配置:
LogFormat "%{x-Forwarded-For}i %a %] %u %t\"%r\" %>s %b \"%{Referer}i\"\"%{user-Agent}i\"" combined#nginx 日志格式:
$proxy_add_x_forwarded_for:包括客户端IP和中间经过的所有代理的IP$http_x_forwarded_For:只有客户端IP
l0g_format main'"$proxy_add_x_forwarded_for"-$remote_user [$time_loca1]
"$request"
$status $body bytes sent "$http_referer"1
""$http_user_agent" $http_x_forwarded_For';#tomcat 配置:conf目录下的server.xm7<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logsprefix="1ocalhost_access_1og" suffix=".txtpattern="%{x-Forwarded-For}i %h % %u %t &quot;%r&quot; %s %b" />

2、查看日志内容

[root@w1 ~]# tail -n 3 /var/log/nginx/access.log
[root@w2 ~]# tail -n 3 /etc/httpd/logs/access_log
使用上述两条命令即可。

3.4 ACL

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

3.4.1 ACL匹配模式

参数作用
-i不区分大小写
-m使用指定的正则表达式匹配方式
-n不做dns解析
-u禁止acl重名

3.4.2 具体操作符

1、整体:eq、ge、gt、le、lt

2、字符:-m str、-m sub 、-m beg 、-m end 、-m dir 、-m dom 

字符比较:
exact match (-m str):字符串必须完全匹配模式
exact match (-m sub):在提取的字符串中查找模式,如果其中任何一个被发现,ACL将匹配substring 
prefix match (-m beg):在提取的字符串首部中查找模式,如果其中任何一个被发现,ACL将匹配-suffix suffix match (-m end):将模式与提取字符串的尾部进行比较,如果其中任何一个匹配,则ACL进行匹配
subdir match (-m dir):查看提取出来的用斜线分隔(“/")的字符串,如其中任一个匹配,则- subdir matchACL进行匹配
domain match (-m dom):查找提取的用点(“.")分隔字符串,如果其中任何一个匹配,则ACL进-domain match行匹配

3.4.3 操作对象

-Boolean #布尔值
-integer or integer range#整数或整数范围,比如用于匹配端口范围二
-IP address/network#IP地址或IP范围,192.168.0.1192.168.0.1/24
-string-->www.timinglee.org
exact    #精确比较
substring    #子串
suffix    #后缀比较
prefix    #前缀比较
subdir    #路径,/wp-includes/js/jquery/jquery.js
domain    #域名,www.timinglee.org
regular expression    #正则表达式
- hex block    #16进制

3.4.4 域名匹配演示


frontend webclusterbind :80mode httpacl test hdr(dom)-i www.yee.orguse backendwebcluster host if testdefault backend default-hostbackend webcluster-hostmode httpserver web1 172.25.254.10:80 check inter 2 fall 2 rise 5backend default*hostmode httpserver web2 172.25.254.20:80 check inter 2 fall 2 rise 5

测试:

[root@client]# curl www.yee.org
webserver1 - 172.25.254.20
[root@client]#curl www.yee.org
webserver1 - 172.25.254.10

3.4.5 基于源IP或子网调度访问演示

(以下只展示做修改的部分,相同部分不再展示)

frontend webcluster
bind *:80
mode http
acl ctrl_ip rox src 172.25.254.1 172.25.254.20  192.168.0.0/24use backend webcluster-host if ctrl_ip
# 拒绝可以这样写
http-request  deny if ctrl_ip default backend default-host

测试:

[root@client]# curl 172.25.254.100
webserver1 - 172.25.254.10

3.4.6 匹配浏览器类型

frontend webclusterbind *:80mode http acl badwebrowers hdr_sub(User-Agent)-i curl wgethttp-request deny if badwebrowers
default_backend default-host

测试:

[root@client]# curl 172.25.254.100
<html><body><h1>403 Forbidden</h1>
Request forbidden by administrative rules.</body></html>

3.4.7 基于文件后缀名动静分离类型

web1:
# 安装php
[root@w1 ~]# dnf install php -y
# 重启httpd
[root@w1 ~]# systemctl restart httpd
[root@w1 ~]# vim /var/www/html/index.php
[root@w1 ~]# cat /var/www/html/index.php
<?phpphpinfo();
?># 然后再去浏览器测试一下hap:
# 配置文件修改
frontend webclusterbind *:80mode httpacl static   path end  -i .html .jpg .png .css .jsacl php      path end -i .phpuse_backend webcluster-host if php

测试:

3.4.8 匹配访问路径实现动静分离

frontend webclusterbind *:80mode httpacl static  path_sub -m sub  staticacl php     path_sub -m sub  phpuse_backend webcluster-host if php[root@w2 ~]# mkdir /usr/share/nginx/html/static -p 
[root@w2 ~]# echo static - 172.25.254.20 > /usr/share/nginx/html/static/index.html[root@w2 ~]# curl 172.25.254.20/static/ static - 172.25.254.20[root@w1 ~]# mkdir /var/www/html/php -p 
[root@w1 ~]# cp /var/www/html/index.php /var/www/html/php

测试:

根据自己需求,在脚本中进行修改即可得到下一步想要进行的操作,但是修改脚本后,一定要重启服务,才能保证脚本的正常运行。

3.5 自定义haproxy错误界面

对指定的报错进行重定向,显示错误页面
使用errorfile和erroroc指令的两种方法,可以实现自定义各种错误页面,以下是haproxy默认使用的错误页面

[root@hap ~]# rpm -ql haproxy24z-2.4.27-1.e17.zenetys.x86_64 | grep -E http$
/usr/share/haproxy/400.http
/usr/share/haproxy/403.http
/usr/share/haproxy/408.http
/usr/share/haproxy/500.http
/usr/share/haproxy/502.http
/usr/share/haproxy/503.http
/usr/share/haproxy/504.http

示例:

[root@hap ~]# mkdir /haproxy/errorpages/ -p
[root@hap ~]# cp /usr/share/haproxy/503.http
[root@hap ~]# vim /haproxy/errorpages/503page.http
[root@hap ~]# cat /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>

测试1:

测试2:

在进行后续实验时,只需要在配置文件中对标红部分进行修改即可

3.6 haproxy 四层负载

示例:对MySQL服务实现四层负载

在web2和web1中安装并启动mariabd服务

修改配置文件

在hap中修改

测试:在web1输入mysql

实现四层负载

listen dbserverbind *:3306mode tcpbalance static-rrserver db1 172.25.254.10:3360 check inter 3 fall 3 rise 5server db2 172.25.254.20:3360 check inter 3 fall 3 rise 5

重启后测试:

[root@client ~]# mysql -uyee -p -h 172.25.254.100
Welcome to the MariaDB monitor.Commands end with; or \ g
Your MariaDB connection id is 11
Server version: 10.5.22-MariaDB MariaDB ServerCopyright(c)2000,2018, 0racle, MariaDB Corporation Ab and others.Type 'help;'or '\h' for help. Type 'ic' to clear the current input statement.

 

3.7 haproxy 的https

# 证书的制作
[root@hap ~]# mkdir -p /etc/haproxy/certs[root@hap ~]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/haproxy/certs/yee.org.key -x509 -days 365 -out /etc/haproxy/certs/yee.org.crtYou 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]:xi'an
Organization Name (eg, company) [Default Company Ltd]:yee
Organizational Unit Name (eg, section) []:webserver
Common Name (eg, your name or your server's hostname) []:www.yee.org
Email Address []:admin@yee.org[root@hap ~]# cd /etc/haproxy/conf.d/
[root@hap conf.d] # ls
webcluster.cfg
[root@hap conf.d]# pwd
/etc/haproxy/conf.d
[rootahap conf.d]# cat webcluster.cfg
listen statsmode httpbind *:9999stats enablestats refresh 3stats uri /statusstats auth yee:yee# http配置
[root@hap ~]# vim /etc/haproxy/haproxy.cfglisten web-httpsbind *:443 ssl crt /etc/haproxy/certs/yee.pemmode httprbalance roundrobinserver web2 172.25.254.20:80 check inter 2 fall 2 rise 5server webl 172.25.254.10:80 check inter 2 fall 2 rise 5# 全站加密
frontend webclusterbind *:80mode httpredirect scheme https if !{ ssl fc }

测试:

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【Qt QML】ComboBox组件
  • 运维 | Node.js 的安装与使用汇总
  • Linux嵌入式学习——C++学习(2)
  • 腾讯研究院《工业大模型应用报告》2024.03 简读
  • 深度学习的前沿技术有哪些?
  • Power BI产品详细介绍
  • Ftrans文件摆渡方案:重塑文件传输与管控的科技先锋
  • 【Java】深入理解 Java 中的 trim() 方法
  • Selenium + Python 自动化测试10(unittest概念)
  • 科技文献笔记模版(自用)
  • 力扣爆刷第171天之TOP200五连刷121-125(跳跃游戏、买卖股票、旋转链表)
  • Zabbix自动导出PDF报告
  • k8s—Prometheus原理
  • Qt十多年的开发经验,无私奉献!
  • 127. Go反射基本原理
  • 【跃迁之路】【733天】程序员高效学习方法论探索系列(实验阶段490-2019.2.23)...
  • Asm.js的简单介绍
  • CSS3 变换
  • HTTP那些事
  • Java精华积累:初学者都应该搞懂的问题
  • laravel5.5 视图共享数据
  • Linux各目录及每个目录的详细介绍
  • Redux 中间件分析
  • 从0到1:PostCSS 插件开发最佳实践
  • 高性能JavaScript阅读简记(三)
  • 检测对象或数组
  • 配置 PM2 实现代码自动发布
  • 再谈express与koa的对比
  • ​2020 年大前端技术趋势解读
  • ​LeetCode解法汇总1410. HTML 实体解析器
  • ​低代码平台的核心价值与优势
  • # windows 安装 mysql 显示 no packages found 解决方法
  • (不用互三)AI绘画:科技赋能艺术的崭新时代
  • (附源码)c#+winform实现远程开机(广域网可用)
  • (附源码)spring boot校园拼车微信小程序 毕业设计 091617
  • (新)网络工程师考点串讲与真题详解
  • (学习日记)2024.01.09
  • (转载)利用webkit抓取动态网页和链接
  • ./configure,make,make install的作用
  • .NET C# 使用 SetWindowsHookEx 监听鼠标或键盘消息以及此方法的坑
  • .NET Core 和 .NET Framework 中的 MEF2
  • .NET Core 通过 Ef Core 操作 Mysql
  • .net redis定时_一场由fork引发的超时,让我们重新探讨了Redis的抖动问题
  • .NET 中小心嵌套等待的 Task,它可能会耗尽你线程池的现有资源,出现类似死锁的情况
  • .NET/C# 利用 Walterlv.WeakEvents 高性能地定义和使用弱事件
  • @31省区市高考时间表来了,祝考试成功
  • @hook扩展分析
  • @Value获取值和@ConfigurationProperties获取值用法及比较(springboot)
  • [ vulhub漏洞复现篇 ] Jetty WEB-INF 文件读取复现CVE-2021-34429
  • [ 蓝桥杯Web真题 ]-布局切换
  • [ 渗透工具篇 ] 一篇文章让你掌握神奇的shuize -- 信息收集自动化工具
  • [2019.2.28]BZOJ4033 [HAOI2015]树上染色
  • [AHOI2009]中国象棋 DP,递推,组合数
  • [AIGC] CompletableFuture的重要方法有哪些?
  • [Android Pro] android 混淆文件project.properties和proguard-project.txt