haproxy

  

 

日志

 

 

配置rsyslog

 

 

 

 

检测配置文件

 

 

检测编译选项

haproxy -vv

 

 

 

Configuration

复制代码
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # log是发给server的, 而不是本地的facility
    log         127.0.0.1 local2 
    log         /dev/log  local1 notice
    
    chroot      /var/lib/haproxy  # <jail dir>
    pidfile     /var/run/haproxy.pid
    maxconn     40000
    user        haproxy
    group       haproxy
    daemon  # 守护进程

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats



#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog  # mode 为http时, 记录详细日志
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8  # 在发往backend的请求首部插入 X-Forwarded-For 首部
    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                 30000



#---------------------------------------------------------------------
# statistics 
#---------------------------------------------------------------------
listen statistics
  bind *:9000
  stats enable
  #stats hide-version
  #stats scope .
  stats uri /admin
  stats realm Haproxy\ Statistics
  stats auth admin:admin
  stats admin if TRUE  # web管理



#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  frontend-main *:80
    #use_backend static          if url_static
    #default_backend             app
    default_backend              server
  #errorfile 503 /etc/haproxy/errorpages/503.html  # 自定义 503 code
  errorloc 504 http://baidu.com

#---------------------------------------------------------------------
# apiserver frontend which proxys to the control plane nodes
#---------------------------------------------------------------------
frontend frontend-apiserver
    mode tcp
    bind *:16443  # 必须为* BACKUP的主机,没有VIP,会导致haproxy cannot bind socket
    option tcplog
    default_backend backend-apiserver



#---------------------------------------------------------------------
# round robin balancing for apiserver
#---------------------------------------------------------------------
backend backend-apiserver
    mode tcp
    option httpchk GET /healthz
    http-check expect status 200
    option ssl-hello-chk  # https
    option tcplog
    option tcp-check

    balance     roundrobin
    #server ${HOST1_ID} ${HOST1_ADDRESS}:${APISERVER_SRC_PORT} check
    server gale1 192.168.8.11:6443 check
    server gale2 192.168.8.12:6443 check
    server gale3 192.168.8.13:6443 check

#---------------------------------------------------------------------
# backend server
#---------------------------------------------------------------------

backend backend-server
    balance     roundrobin
    cookie ServerID insert
    server      gale2 192.168.8.12:80 check weight 10 cookie gale2
    server      gale3 192.168.8.13:80 check weight 20 cookie gale3



#---------------------------------------------------------------------
# frontend demo
#---------------------------------------------------------------------

# bind
frontend  main *:80

frontend main
  bind *:80  # bind 用于frontend, listen
  bind *:8080
  bind *:900-910

# balance
balance roundrobin, static-rr, leastconn, source, uri,

# server
server first 172.16.1.7:8080 cookie first check inter 1s port 80
server second 172.16.1.7:8080 cookie second check inter 1s port 80
复制代码

 

posted @   ascertain  阅读(48)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2020-08-08 windows的/dev/null
2020-08-08 openssh-server & openssh-clients
2020-08-08 Linux利用curl监控api接口,请求失败,发送报警邮件
2020-08-08 linux使用mailx发送邮件
2020-08-08 访问Windows的默认共享
点击右上角即可分享
微信分享提示