haproxy 基础知识

配置说明

global  # 全局配置
    log         127.0.0.1 local2  # centos7 /etc/rsyslog.conf日志配置
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin 
# 监控unix socket 权限600,级别admin
     
defaults  # 默认配置
    mode                    http   # http 七层
    log                     global  # 日志记录使用global中定义
    option                  httplog  # 记录http日志,建议关闭
    option                  dontlognull  # 不记录空连接日志 
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
     
listen stats  # 监听
    mode http
    bind 0.0.0.0:8888
    stats enable
    stats uri     /haproxy-status   # 监听URL
    stats auth    haproxy:saltstack  # 用户名、密码
     
frontend frontend_www_test_com  # 前端配置名称
    bind 192.168.10.11:80  # VIP
    mode http  # http协议
    option httplog
    log global  # 日志输出
    default_backend backend_www_example_com  # 跳转后端名称
     
backend backend_www_example_com  # 后端配置名称
    option forwardfor header X-REAL-IP
    option httpchk HEAD / HTTP/1.0  # 监控检查
    balance roundrobin # 负载均衡算法,源IP hash
    server web-node1  192.168.10.12:80 check inter 3000 rise 30 fall 10 
    # 参数: check启用监控检查, inter 3000健康检查的时间间隔(毫秒),rise 30检查服务连续可以次数,加入这台服务,fall 10检查服务连续不可用的次数,剔除这台服务
    server web-node2  192.168.10.13:80 check inter 3000 rise 30 fall 10

测试
http://192.168.10.11:8888/haproxy-status

posted @ 2019-01-13 17:54  reaperhero  阅读(130)  评论(0编辑  收藏  举报