• HAProxy——关于配置的备份


    一份HAProxy配置文件

    #全局配置
    global
        #设置日志
        log 127.0.0.1 local0 info
        #当前工作目录
        chroot /usr/local/haproxy
        #用户与用户组
        user haproxy
        group haproxy
        #运行进程ID
        uid 99
        gid 99
        #守护进程启动
        daemon
        #最大连接数
        maxconn 4096
    #默认配置
    defaults
        #应用全局的日志配置
        log global
        #默认的模式mode {tcp|http|health}
        #TCP是4层,HTTP是7层,health只返回OK
        mode tcp
        #日志类别tcplog
        option tcplog
        #不记录健康检查日志信息
        option dontlognull
        #3次失败则认为服务不可用
        retries 3
        #每个进程可用的最大连接数
        maxconn 2000
        #连接超时
        timeout connect 5s
        #客户端超时
        timeout client 120s
        #服务端超时
        timeout server 120s
    #绑定配置
    listen rabbitmq_cluster 
            bind 0.0.0.0:5671
            #配置TCP模式
            mode tcp
            #简单的轮询
            balance roundrobin
            #RabbitMQ集群节点配置
            server rmq_node1 10.110.8.34:5672 check inter 5000 rise 2 fall 3 weight 1
            server rmq_node2 10.110.8.38:5672 check inter 5000 rise 2 fall 3 weight 1
    #haproxy监控页面地址
    listen monitor 
            bind 0.0.0.0:8100
            mode http
            option httplog
            stats enable
            stats uri /stats
            stats refresh 5s

    另一份配置文件

    global
        log 127.0.0.1 local0 info maxconn 4096
        user nobody 
        group nobody 
        daemon 
        nbproc 1
        pidfile /usr/local/haproxy/logs/haproxy.pid 
    defaults
        mode http 
        retries 3
        timeout connect 10s 
        timeout client 20s 
        timeout server 30s 
        timeout check 5s
    frontend www
        bind *:80 
        mode    http
        option    httplog 
        option    forwardfor 
        option    httpclose 
        log    global
        default_backend htmpool
    backend htmpool
        mode    http 
        option    redispatch
        option    abortonclose 
        balance    roundrobin 
        cookie    SERVERID
        option    httpchk GET /index.php
        server    web1 10.200.34.181:80    cookie server1 weight 6 check inter 2000 rise 2 fall 3
        server    web2 10.200.34.182:8080 cookie server2 weight 6 check inter 2000 rise 2 fall 
    listen admin_stats
        bind 0.0.0.0:9188
        mode http
        log 127.0.0.1 
        local0 err stats 
        refresh 30s
        stats uri /haproxy-status
        stats realm welcome login Haproxy
        stats auth admin:admin123
        stats hide-version 
        stats admin if TRUE

    HAProxy 基础配置文件详解
    HAProxy 配置文件根据功能和用途,主要有 5 个部分组成,但有些部分并不是必须的, 可以根据需要选择相应的部分进行配置。

       1、global 部分

    用来设定全局配置参数,属于进程级的配置,通常和操作系统配置有关。

       2、defaults 部分

    默认参数的配置部分。在此部分设置的参数值,默认会自动被引用到下面的 frontend、

    backend 和 listen 部分中,因此,如果某些参数属于公用的配置,只需在 defaults 部分添加一次即可。而如果在 frontend、backend 和 listen 部分中也配置了与 defaults 部分一样的参数,那么defaults 部分参数对应的值自动被覆盖。

       3、frontend 部分

    此部分用于设置接收用户请求的前端虚拟节点。frontend 是在 HAProxy1.3 版本之后才引入的一个组件,同时引入的还有 backend 组件。通过引入这些组件,在很大程度上简化了 HAProxy 配置文件的复杂性。frontend 可以根据 ACL 规则直接指定要使用的后端

    4、backend 部分

    此部分用于设置集群后端服务集群的配置,也就是用来添加一组真实服务器,以处理前端用户的请求。添加的真实服务器类似于 LVS 中的real server 节点。

    5、listen 部分

    此部分是 frontend 部分和 backend 部分的结合体。在 HAProxy1.3 版本之前,

    HAProxy 的所有配置选项都在这个部分中设置。为了保持兼容性,HAProxy 新的版本仍然保留了 listen 组件的配置方式。目前在 HAProxy 中,两种配置方式任选其一即可。

    负载均衡算法介绍

    HAProxy关于session共享问题

    HAProxy 解决集群 session 共享问题
    Haproxy 二种方法保持客户端 session 一致

    5.1、用户 IP 识别
    haroxy 将用户 IP 经过 hash 计算后 指定到固定的真实服务器上(类似于 nginx 的 IP hash 指令)

    配置指令: balance source

    backend htmpool
      mode http
      option redispatch
      option abortonclose
      balance source
      cookie SERVERID
      option httpchk GET /index.jsp
      server s237er 1.1.1.1:8080 cookie server1 weight 6 check inter 2000 rise 2 fall 3
      server sii234  1.1.1.1:8080 cookie server2 weight 3 check inter 2000 rise 2 fall 3

    5.2、 cookie 识别
    haproxy 将WEB 服务端发送给客户端的 cookie 中插入(或添加加前缀)haproxy 定义的后端的服务器COOKIE ID。

    配置指令例举 cookie SESSION_COOKIE insert indirect nocache

    backend htmpool
        mode http
        option redispatch
        option abortonclose
        balance static-rr
        cookie SERVERID #cookie参数
        option httpchk GET /index.jsp
        server a111server 1.1.1.1:8080 cookie server1 weight 6 check inter 2000 rise 2 fall 3 
        server a324server  1.1.1.1:8080 cookie server2 weight 3 check inter 2000 rise 2 fall 3 
  • 相关阅读:
    $prufer$序列
    倍增
    二分
    英语词汇速查表
    ACM模拟赛
    Trie树
    关于军训的模拟赛-R2
    树上差分
    列队
    斜率优化dp
  • 原文地址:https://www.cnblogs.com/xingchong/p/14738658.html
Copyright © 2020-2023  润新知