• HAProxy的高级配置选项-ACL篇之基于源地址和子网子网匹配案例


          HAProxy的高级配置选项-ACL篇之基于源地址和子网子网匹配案例

                                           作者:尹正杰

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

    一.安装Apache Httpd及准备测试数据

    1>.试验架构说明

      node102.yinzhengjie.org.cn:
        Haproxy服务器
    
      node105.yinzhengjie.org.cn:
        测试服务器,模拟客户端
    
      node106.yinzhengjie.org.cn:
        Apache httpd服务器
    
      node107.yinzhengjie.org.cn:
        Apache httpd服务器
    
      node108.yinzhengjie.org.cn:
        Apache httpd服务器

    2>.安装Apache httpd服务

      此过程相对简单,我这里就直接略过了,可参考我之前的笔记:https://www.cnblogs.com/yinzhengjie/p/12114195.html

    二.配置haproxy基于源地址子网匹配的ACL实战案例

    1>.编辑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
    
    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
        #基于客户端的源IP地址("172.30.1.254")或者基于源IP子网地址(如"192.168.1.0/24"),使用空格分割相应的匹配规则即可。
        acl my_ip_range src 172.30.1.254 192.168.1.0/24
        #调用ACL
        use_backend my_web if my_ip_range
        #如果前面的ACL都没有匹配成功就访问默认的ACL
        default_backend backup_web
    
    backend my_web
        server web01 172.30.1.106:80 check inter 3000 fall 3 rise 5
        server web02 172.30.1.107: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 ~]# 
    [root@node102.yinzhengjie.org.cn ~]# systemctl restart haproxy        #别忘记重启配置文件使得配置生效哟~重启后可以看到如下图所示的状态页。
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# 

    2>.IP地址为"172.30.1.254"主机通过浏览器访问"http://node102.yinzhengjie.org.cn/"

    3>.使用"node105.yinzhengjie.org.cn"访问"http://node102.yinzhengjie.org.cn/",如下图所示。

  • 相关阅读:
    springboot—spring aop 实现系统操作日志记录存储到数据库
    排名前16的Java工具类
    SpringBoot集成JWT实现token验证
    使用jQuery实现图片懒加载原理
    Spring主从数据库的配置和动态数据源切换原理
    使用Nginx过滤网络爬虫
    Java io.netty.util.ReferenceCountUtil 代码实例
    Netty系列之Netty百万级推送服务设计要点
    Java给图片和PDF文件添加水印(图片水印和文字水印)
    【TortoiseSVN】windows中连接SVN服务器的工具
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12151021.html
Copyright © 2020-2023  润新知