当前位置: > Linux服务器 > Linux软件 >

Haproxy1.6 config详解

时间:2016-05-16 11:00来源:linux.it.net.cn 作者:IT
global:

    global section中设置的参数都是进程级别或者操作系统级别的,他们一般只需要设置一次,一旦设置好之后并不需要修改
   
   
    chroot <jail dir>:修改当前目录到chroot指定的目录,该设置有助于加强安全
    daemon:使haproxy运行在后台,或者在启动时,使用-D参数
    gid <number>:指定进程运行时的gid
    group <group name>:和gid很相像,不过指定的是group的名称
    log <address> <facility>:添加一个全局的syslog server,只能增加两个syslog server,他们会接收启动和退出时的log,所有配置log global的日志也会被接收。
    log-send-hostname [<string>]:在syslog header中设置hostname域
    log-tag <string>:在syslog header中设置tag域
    nbproc <number>:在haproxy以daemon启动的时候,创建几个进程,默认是创建一个进程,
    pidfile <pidfile>:指定pid文件的位置,等同于-p参数
    stats socket <path>:创建一个unix socket,连接到改socket的时候,会返回详细的统计数据,有user、operator、admin模式可选
    stats timeout <timeout, in milliseconds>:stats的超时时间,默认是10s
    stats maxconn <connections>:stats的允许的最大连接数,默认是10个连接
    uid <number>:指定进程运行时的uid
    ulimit-n <number>:设置每个进程可以打开的进程描述符个数,默认是自动计算的
    user <user name>:和uid很相像,治国指定的是 运行用户的名称
    node <name>:在HA配置中很有用,指定节点
    description <text>:增加一段描述
   
    maxconn <number>:设置每个进程的最大连接数,等同于-n参数,ulimit-n自动计算改参数
    maxpipes <number>:设置每个进程的最大pipe数,目前pipe使用基于内核的tcp splicing,默认是maxconn/4。
    noepoll:不使用epoll
    nokqueue:不使用queue
    nopoll:不使用poll
    nosepoll:不使用sepoll
    nosplice:在linux上禁止使用kernel tcp splicing
    spread-checks <0..50, in percent>:
    tune.bufsize <number>:设置buffer size,小的值允许内存中连接更多的session,大的值允许内存中存储更大的cookies。默认是16384,不建议修改
    tune.chksize <number>:设置check的buffer size,默认是16384,不建议修改
    tune.maxaccept <number>:设置单个进程可以接收的最大连接数,在单进程模式下,改值是100,在多进程模式下(nbproc>1),默认是8,-1是禁止该限制
    tune.maxpollevents <number>:在一次系统调用中最大可以执行多少个events
    tune.maxrewrite <number>:
    debug:开启debug模式,并且禁止允许在后台,等同于-d参数
    quiet:在启动的时候不显示任何信息,等同于-q参数
   
    userlist <listname>:创建一个userlist
    group <groupname> [users <user>,<user>,(...)]:把group加入到当前的userlist中,也可设置以加入该组中的user,多个user用逗号分隔
    user <username> [password|insecure-password <password>] [groups <group>,<group>,(...)]:设置该userlist中的user,并且设置加密的密码,或者设置不加密的密码
   
   
proxy section:proxy设置中包含了四个section:defaults、frontend、backend、listen

defaults:

    defaults section:defaults设置其他跟在defaults后面的sections中默认参数值,defaults的区域范围在碰到下一个defaults sections截止
    frontend section:frontend设置一些监听的sockets,用来监听接收客户端发来的请求
    backend section:backend设置一些后端的server,proxy会把接收到的请求转发到这些server上面去
    listen section:listen设置则是把frontend和backend连接在一起的设置,在TCP转发中很常用
   
    acl <aclname> <criterion> [flags] [operator] <value>      设置声明访问列表
    appsession <cookie> len <length> timeout <holdtime>        在一个app cookie上设置session粘置
    backlog <conns>        设置backlog size,一般不要大于32768
    balance <algorithm> [ <arguments> ]        设置后端server使用的load balance算法
    balance url_param <param> [check_post [<max_wait>]]        设置后端server使用的load balance算法
    bind [<address>]:<port_range> interface <interface>     设置一个或者多个frontend监听的地址和端口
    block { if | unless } <condition>        如果条件满足,则在7层拒绝服务
    capture cookie <name> len <length>        捕获请求中的cookie
    capture request header <name> len <length>
    capture response header <name> len <length>
    default-server [param*]        设置backend server的默认配置
    default_backend <backend>        设置一个特殊的backend,当已经设置的use_backend没有匹配到的时候
    disabled    禁止一个proxy、frontend、backend
    dispatch <address>:<port>    设置server的默认地址
    enabled        开启一个proxy、frontend、backend
    errorfile <code> <file>        当haproxy抓取到http的code的时候,可以根据这些code把访问保存到文件中去
    fullconn <conns>    设置backend server可接接收的最大连接数
    grace <time>   
    http-check disable-on-404   
    http-check send-state
    http-request { allow | deny | auth [realm <realm>] }  [ { if | unless } <condition> ]     7层的访问控制
    http-send-name-header [<header>]    在request中增加server name
    id <value>        给proxy设置一个id
    log global        开启每个实例的日志记录
    log <address> <facility> [<level> [<minlevel>]]        开启每个实例的日志记录
    maxconn <conns>        frontend可以接受的最大连接数
    mode { tcp|http|health }        设置运行模式
    monitor fail { if | unless } <condition>    当监控http请求失败的时候,产生一个report
    monitor-net <source>
    monitor-uri <uri>
    option allbackups
    option checkcache
    option clitcpka        开启到client的tcp keepalived
    option contstats        开启连续流量的统计
    option dontlog-normal        开启成功连接的日志记录
    option dontlognull        开启空连接的日志记录
    option forceclose        在响应完毕后,开启可以主动关闭连接
    option forwardfor [ except <network> ] [ header <name> ] [ if-none ]
    option http-no-delay
    option http-pretend-keepalive
    option http-server-close        允许server段可以关闭连接
    option http-use-proxy-header
    option httpchk <method> <uri> <version>        开启http检测
    option httpclose    开启被动http连接关闭
    option httplog [ clf ]
    option http_proxy
    option log-health-checks
    option socket-stats
    option srvtcpka
    option tcpka
    option tcplog
    source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ]
    stats auth <user>:<passwd>
    stats enable
    stats hide-version

   
server关键字,在server指令后面,支持一些在server上设置的参数,
    server <name> <address>[:port] [settings ...]

   
    settings... 包含的参数如下:
   
        addr <ipv4>:用来设置一个不同的ip,用来发送health-checks检测
        backup:指定该server为备机,只有当其他server没有响应的时候,该备机才正式工作
        check:开启健康检测
        cookie <value>:在访问server时,设置cookie
        disabled:设置server在disabled状态,使服务器处于维护状态
        error-limit <count>:如果开启了健康检测,设置触发的error数目,默认是10
        fall <count>:健康检测失败几次后认为server处于dead状态
        inter <delay>:
        fastinter <delay>:
        downinter <delay>:
        maxconn <maxconn>:
        maxqueue <maxqueue>:
        minconn <minconn>:
        observe <mode>:
        on-error <mode>:
        port <port>:
        redir <prefix>:
        rise <count>:
        slowstart <start_time_in_ms>:
        weight <weight>:
        track [<proxy>/]<server>:




(责任编辑:IT)
------分隔线----------------------------