首页 Haproxy教程haproxy-web服务器状态监测

haproxy-压缩功能

hapxory-ACL基础介绍

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

三种状态监测方式

基于四层的传输端口做状态监测,此为默认方式
基于指定 URI 做状态监测
基于指定 URI 的request请求头部内容做状态监测,建议使用此方式

基于应用层http协议进行健康性检测

基于应用层http协议,采有不同的监测方式,对后端real server进行状态监测

option httpchk          #启用七层健康性检测,对tcp 和 http 模式都支持,默认为:OPTIONS / HTTP/1.0
option httpchk <uri>
option httpchk <method> <uri>
option httpchk <method> <uri> <version>

#期望以上检查得到的响应码
http-check expect [!] <match> <pattern>
#示例:
http-check expect status 200
http-check expect ! rstatus ^5

<version> is the optional HTTP version string. It defaults to "HTTP/1.0"
          but some servers might behave incorrectly in HTTP 1.0, so turning
          it to HTTP/1.1 may sometimes help. Note that the Host field is
          mandatory in HTTP/1.1, and as a trick, it is possible to pass it
          after "\r\n" following the version string.

配置示例

listen  web_host
  bind 10.0.0.7:80
  mode http
  balance  roundrobin
  #option httpchk GET /monitor/check.html               #默认HTTP/1.0
  #option httpchk GET /monitor/check.html HTTP/1.0
  #option httpchk GET /monitor/check.html HTTP/1.1      #注意:HTTP/1.1强制要求必须有Host字段
  option httpchk HEAD  /monitor/check.html HTTP/1.1\r\nHost:\ 10.0.0.7 #使用HEAD减少网络流量
  cookie  SERVER-COOKIE  insert  indirect nocache
  server web1 10.0.0.17:80  cookie web1 check inter 3000 fall 3 rise 5
  server web2 10.0.0.27:80  cookie web2 check inter 3000 fall 3 rise 5

#在所有后端服务建立检测页面
[root@backend ~]#mkdir /var/www/html/monitor/
[root@backend ~]#echo  monitor > /var/www/html/monitor/check.html

#关闭一台Backend服务器
[root@backend1 ~]#systemctl stop httpd

验证http监测

查看到状态页,可以看到启了七层检测功能:LastChk字段:L7

haproxy-web服务器状态监测插图

#后端服务器查看访问日志
[root@backend ~]#tail /var/log/httpd/access_log
10.0.0.7 - - [02/Apr/2020:14:25:22 +0800] "HEAD /monitor/check.html HTTP/1.1" 200 - "-" "-"
10.0.0.7 - - [02/Apr/2020:14:25:25 +0800] "HEAD /monitor/check.html HTTP/1.1" 200 - "-" "-"
10.0.0.7 - - [02/Apr/2020:14:25:28 +0800] "HEAD /monitor/check.html HTTP/1.1" 200 - "-" "-"

本文链接:http://www.yunweipai.com/35297.html

haproxy-压缩功能

hapxory-ACL基础介绍

网友评论comments

发表评论

邮箱地址不会被公开。

暂无评论

Copyright © 2012-2021 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部