HAProxy的高级配置选项-haproxy预定义(内置)acl使用案例

         HAProxy的高级配置选项-haproxy预定义(内置)acl使用案例

                                       作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.haproxy内置的ACL概述

博主推荐阅读:
  http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#7.4

二.使用内置的acl案例实战

1>.后端服务器安装及数据准备

  该过程相对简单,可参考我之前的笔记:https://www.cnblogs.com/yinzhengjie/p/12153240.html

2>.编辑haproxy的配置文件

[root@node102.yinzhengjie.org.cn ~]# cat /etc/haproxy/haproxy.cfg
global
    maxconn 100000
    chroot /yinzhengjie/softwares/haproxy
    stats socket /yinzhengjie/softwares/haproxy/haproxy.sock mode 600 level admin
    user haproxy
    group haproxy
    daemon
    nbproc 2
    cpu-map 1 0
    cpu-map 2 1
    nbthread 2
    pidfile /yinzhengjie/softwares/haproxy/haproxy.pid
    log 127.0.0.1 local5 info

defaults
    option http-keep-alive
    option  forwardfor
    option redispatch
    option abortonclose
    maxconn 100000
    mode http
    timeout connect 300000ms
    timeout client  300000ms
    timeout server  300000ms
    errorloc 503 http://node107.yinzhengjie.org.cn/monitor/503.html

listen status_page
    bind 172.30.1.102:8888
    stats enable
    stats uri /haproxy-status
    stats auth    admin:yinzhengjie
    stats realm "Welcome to the haproxy load balancer status page of YinZhengjie"
    stats hide-version
    stats admin if TRUE
    stats refresh 5s

frontend WEB_PORT_80
    bind 172.30.1.102:80
    mode http
    acl php_server path_end -i .php
    use_backend nginx_php if php_server
    acl static_path path_beg -i /static /images /javascript
    #此处我们匹配了3给ACL规则,其中包括HTTP_1.1是内置的acl,TRUE也是内置的acl,而只有static_path才是咱们自定义的ACL
    use_backend apache_httpd if HTTP_1.1 TRUE static_path
    default_backend backup_web

backend nginx_php
    server web04 172.30.1.104:80  check inter 3000 fall 3 rise 5

backend apache_httpd
    server web03 172.30.1.103:80  check inter 3000 fall 3 rise 5

backend backup_web
    server web03 172.30.1.108:80  check inter 3000 fall 3 rise 5 
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# systemctl restart haproxy            #别忘记重启haproxy服务使得配置文件生效哟~
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# 

3>.查看haproxy的状态页

4>.浏览器访问"http://node102.yinzhengjie.org.cn/images/01.jpeg"

5>.浏览器访问"http://node102.yinzhengjie.org.cn/index.php"

6>.浏览器访问"http://node102.yinzhengjie.org.cn/index.html"

原文地址:https://www.cnblogs.com/yinzhengjie/p/12153787.html