HAProxy配置中分成五部分内容,当然这些组件不是必选的,可以根据需要选择部分作为配置。

=====================

global      参数是进程级的,通常和操作系统(OS)相关.这些参数一般只设置一次,如果配置无误,就不需要再次配置进行修改
defaults   配置默认参数的,这些参数可以被利用配置到frontend,backend,listen组件
frontend     接收请求的前端虚拟节点,Frontend可以根据规则直接指定具体使用后端的 backend(可动态选择)。
backend     后端服务集群的配置,是真实的服务器,一个Backend对应一个或者多个实体服务器。
listen         Frontend和Backend的组合体。

======================
global
log 137.0.0.1 local0 notice
#全局的日志配置 其中日志级别是[err warning info debug].local0 是日志设备,必须为如下24种标准syslog设备的一种:
#kern user mail daemon auth syslog lpr news
#uucp cron auth2 ftp ntp audit alert cron2
#local0 local1 local2 local3 local4 local5 local6 local7
maxconn 65535 #最大连接数
user haproxy #haproxy运行的用户和组
group haproxy
#nbproc 8 #创建4个进程进入deamon模式运行。此参数要求将运行模式设置为"daemon"
daemon #使HAProxy进程进入后台运行。这是推荐的运行模式
spread-checks 5

defaults
log global
mode http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
option httplog clf #采用http日志格式
option dontlognull
option dontlog-normal
stats uri /admin/status #监控haproxy状态的页面,可以使用http://IP/admin/status查看
stats auth focus:@focus123 #登录监控页面的用户名密码
stats refresh 60s #监控页面的刷新时间
#option nolinger
option redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
retries 2 #两次连接失败就认为是服务器不可用,也可以通过后面设置
option http-server-close
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
option allbackups
option forwardfor
maxconn 65535 #默认的最大连接数
timeout connect 20s #连接超时
timeout client 120s #客户端超时
timeout server 120s #服务器超时
timeout queue 5m
timeout http-keep-alive 75s
timeout http-request 30m

frontend web_in
mode http #http的七层模式
maxconn 65535
bind :8080 #监听端口为8080

acl is_down hdr_beg(host) -i down.focus.cn #如果请求的域名满足down.focus.cn返回true -i是忽略大小写
acl is_pms hdr_beg(host) -i pms.focus.cn
acl is_image hdr_beg(host) -i image.focus.cn

acl is_css path_beg /css #如果请求的路径名满足/css返回true
acl is_js path_beg /js #如果请求的路径名满足/js返回true

#acl is_dynamic path_end .html #判断文件后缀名是不是.html,如果是返回true
#acl ref hdr(Referer) -i www.focus.cn #判断http-referer是不是www.baidu.com,如果是返回true

use_backend image_nginx if is_image is_css or is_js #当满足is_image,并且满足is_css或者满足is_js的策略时,使用image_nginx的backend
use_backend down_nginx if is_down #当满足is_down的策略时,使用down_nginx的backend
use_backend pms_nginx if is_pms #当满足is_pms的策略时,使用pms_nginx的backend
#use_backend bbs_nginx if is_bbs is_dynamic !is_admin#当满足is_bbs,is_dynamic并且不满足is_admin时,使用bbs_nginxdbackend
default_backend all_nginx #以上都不满足时,使用默认的all_nginx的backend

errorfile 400 /etc/haproxy/errors/400.http #定义haproxy的错误页面
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

backend down_nginx
mode http #http的七层模式
fullconn 4096 #设置最大连接
option httpchk HEAD /noc.gif HTTP/1.1\r\nHost:image.focus.cn
#服务器的request中的域名是什么,这个在应用的检测URL对应的功能有对域名依赖的话需要设置

balance roundrobin #负载均衡的方式,roundrobin平均方式
#balance source #负载均衡的方式,source根据客户端IP进行哈希的方式
#option allbackups #在设置了backup的时候,默认第一个backup会优先,设置option allbackups后,所有备份服务器权重一样
#cookie SERVERID insert nocache indirect #允许插入serverid到cookie中,serverid后面可以定义
server Server141 192.168.242.141:80 check inter 2s minconn 64 maxconn 1024 slowstart 10s weight 100 #定义Real服务器名/ip/启用健康检查/最小连接数/最大连接数/至全速缓冲时间/weight
server Server142 192.168.242.142:80 check inter 2s minconn 64 maxconn 1024 slowstart 10s weight 100
#server Server154D 192.168.242.154:80 check cookie ServerD inter 10s maxconn 256 slowstart 10s weight 64
#cookie ServerD 表示SERVERID为ServerD;check inter 2s 是检测心跳频率

backend image_nginx
mode http
fullconn 1024
option httpchk HEAD /noc.gif HTTP/1.1\r\nHost:image.focus.cn
balance roundrobin
server Server170 192.168.242.170:80 check inter 2s minconn 64 maxconn 1024 slowstart 10s weight 100

backend pms_nginx
mode http
fullconn 1024
option httpchk HEAD /noc.gif HTTP/1.1\r\nHost:image.focus.cn
balance roundrobin
server Server170 192.168.242.170:80 check inter 2s minconn 64 maxconn 1024 slowstart 10s weight 100

backend all_nginx
mode http
fullconn 3072
option httpchk HEAD /noc.gif HTTP/1.1\r\nHost:image.focus.cn
balance roundrobin
server Server170 192.168.242.170:80 check inter 2s minconn 64 maxconn 1024 slowstart 10s weight 100
server Server141 192.168.242.141:80 check inter 2s minconn 64 maxconn 1024 slowstart 10s weight 100
server Server142 192.168.242.142:80 check inter 2s minconn 64 maxconn 1024 slowstart 10s weight 100

Haproxy配置参数的更多相关文章

  1. HAproxy 配置参数详解

    HAproxy 配置参数详解 /etc/haproxy/haproxy.cfg # 配置文件 ----------------------------------------------------- ...

  2. 2、haproxy配置参数详解

    代理相关配置参数 内容参考自马哥教育 HAProxy官方文档 https://cbonte.github.io/haproxy-dconv/2.0/configuration.html URI Syn ...

  3. Linux haproxy配置参数

    http-request option http-server-close option http-pretend-keepalive option httpclose option redispat ...

  4. haproxy配置基于ssl证书的https负载均衡

    本实验全部在haproxy1.5.19版本进行测试通过,经过测试1.7.X及haproxy1.3版本以下haproxy配置参数可能不适用,需要注意版本号. 一.业务要求现在根据业务的实际需要,有以下几 ...

  5. HAProxy配置SSL

    前沿 据悉苹果强制APP在2016年底使用ATS协议,所以公司准备将部分站点http统一替换成https.所有我们就得测试下 1.首先原有的haproxy1.5升级到了1.7版本支持ssl 2.查看相 ...

  6. haproxy配置详解

    先看一个ha的配置文件: # # Global settings # global # to have these messages end up in /var/log/haproxy.log yo ...

  7. redis sentinel集群配置及haproxy配置

    ip分布情况: sentinel-1/redis 主 10.11.11.5 sentinel-2/redis 从 10.11.11.7 sentinel-3/redis 从 10.11.11.8 ha ...

  8. [转载]fullPage.js中文api 配置参数~

    fullPage.js中文api 配置参数 选项 类型 默认值 说明 verticalCentered 字符串 true 内容是否垂直居中 resize 布尔值 false 字体是否随着窗口缩放而缩放 ...

  9. kafka配置参数

    Kafka为broker,producer和consumer提供了很多的配置参数. 了解并理解这些配置参数对于我们使用kafka是非常重要的.本文列出了一些重要的配置参数. 官方的文档 Configu ...

随机推荐

  1. mysqld_multi配置MySQL多实例

    # This is an example of a my.cnf file for mysqld_multi.# Usually this file is located in home dir ~/ ...

  2. python __enter__ 与 __exit__的作用,以及与 with 语句的关系

    转载自:http://linbo.github.io/2013/01/08/python-with/ (一直不知道博客园哪里发转载文章) With语句是什么? 有一些任务,可能事先需要设置,事后做清理 ...

  3. Lua类和类继承实现

    Lua本身是不能像C++那样直接实现继承,但我们可以用万能的table表来实现. 以下我总结了三种方式的类以及继承的实现 第一.官方的做法,使用元表实现 原理参照<Programming in ...

  4. [POJ1012]Joseph

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 50596   Accepted: 19239 Description T ...

  5. Windows Azure中对映像的管理及操作

    映像是用作新虚拟机的创建模板的 .vhd 文件.映像是一个模板,因为它与已配置的虚拟机不同,没有计算机名称和用户帐户设置等特定设置.可以通过 Windows Azure 管理门户使用现有映像,或创建您 ...

  6. 【Java基础】Java IO流的总结

    Java IO流分为输入流和输出流,而输入流和输出流中又分字符流和字节流.顾名思义,输入流则是输入到程序中计算,输出流是把程序的结果输出到文件或者设备.而字符流输入输出以字符为单位,字节流则是以字节为 ...

  7. 【原创】MapReduce编程系列之表连接

    问题描述 需要连接的表如下:其中左边是child,右边是parent,我们要做的是找出grandchild和grandparent的对应关系,为此需要进行表的连接. Tom Lucy Tom Jim ...

  8. HDOJ(~1004)

    T1000 #include <stdio.h> int main() { int a, b; while (scanf("%d %d", &a, &b ...

  9. WPF的MVVM模式

    Model->數據模型View->視圖View-Model->連接數據模型和視圖

  10. windows 7 下安装 IIS 和 ArcGis Server 9.3 遇到的问题及解决方法

    windows 7 下安装 IIS 和 ArcGis Server 9.3 遇到的问题及解决方法 分类: ArcGIS server 计算机2012-07-31 14:17 631人阅读 评论(0)  ...