LOG 功能:

  编辑/etc/rsyslog.conf 配置文件:

  1. # Provides UDP syslog reception
  2. $ModLoad imudp              #需要启用
  3. $UDPServerRun 514           #启动syslog 服务
  4.  
  5. # Provides TCP syslog reception
  6. #$ModLoad imtcp
  7. #$InputTCPServerRun
  8.  
  9. # Save news errors of level crit and higher in a special file.
  10. uucp,news.crit /var/log/spooler
  11.  
  12. # Save boot messages also to boot.log
  13. local7.* /var/log/boot.log
  14.  
  15. local2.* /var/log/haproxy/haproxy.log #指定 log 输出位置

配置案例一:

  1. #---------------------------------------------------------------------
  2. # Example configuration for a possible web application. See the
  3. # full configuration options online.
  4. #
  5. # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
  6. #
  7. #---------------------------------------------------------------------
  8.  
  9. #---------------------------------------------------------------------
  10. # Global settings
  11. #---------------------------------------------------------------------
  12. global #全局配置 ,进程和系统相关
  13. # to have these messages end up in /var/log/haproxy.log you will
  14. # need to:
  15. #
  16. # ) configure syslog to accept network log events. This is done
  17. # by adding the '-r' option to the SYSLOGD_OPTIONS in
  18. # /etc/sysconfig/syslog
  19. #
  20. # ) configure local2 events to go to the /var/log/haproxy.log
  21. # file. A line like the following can be added to
  22. # /etc/sysconfig/syslog
  23. #
  24. # local2.* /var/log/haproxy.log
  25. #
  26. log 127.0.0.1 local2 #日志设定,需要在/etc/rsyslog.conf 配置文件中进行设定。
  27.  
  28. chroot /var/lib/haproxy #修改haproxy 工作目录
  29. pidfile /var/run/haproxy.pid
  30. maxconn #允许最大连接
  31. user haproxy
  32. group haproxy
  33. daemon #以守护进程方式进行运行,否则在前台进行工作
  34.  
  35. # turn on stats unix socket
  36. stats socket /var/lib/haproxy/stats #stats 工作目录
  37.  
  38. #---------------------------------------------------------------------
  39. #Proxies 配置段,代理的配置在这
  40. # common defaults that all the 'listen' and 'backend' sections will
  41. # use if not designated in their block
  42. #---------------------------------------------------------------------
  43. defaults #Proxies 的默认配置
  44. mode http #默认代理模式
  45. log global #全局的syslog 服务器,可以定义多个
  46. option httplog #日志格式
  47. option dontlognull
  48. option http-server-close #代理主动断开超时连接
  49. option forwardfor except 127.0.0.0/ #代理默认向后端插入 X-Forwarded-For ,mode 必须 http
  50. option redispatch
  51. retries
  52. timeout http-request 10s
  53. timeout queue 1m
  54. timeout connect 10s
  55. timeout client 1m
  56. timeout server 1m
  57. timeout http-keep-alive 10s
  58. timeout check 10s
  59. maxconn
  60.  
  61. #---------------------------------------------------------------------
    #stats 配置实例
  1. #---------------------------------------------------------------------
  1.  
  2. listen stats_test #配置stats 监听实例
  3. bind *:1080 #绑定监听端口 1080
  4. stats enable #启动stats 功能
  5. stats hide-version #隐藏 haproxy 版本
  6. #stats scope . #指定管理范围
  7. stats uri /haproxyadmin?stats #指定访问路径
  8. stats realm "HAproxy\ Statistics" #指定名称
  9. stats auth zy:zzzzy #指定认证用户名,密码
  10. stats admin if TRUE #启用管理功能
  1.  
  1. #---------------------------------------------------------------------
  1. # main frontend which proxys to the backends
  2. #---------------------------------------------------------------------
  3. frontend http_porxy #前端虚拟负载配置项,定义名称main ,或者别的
  4. bind : #配置监听端口,有多种写法
  5. bind : ssl crt /etc/haproxy/site.pem #监听端口绑定证书
  6.  
  7. acl url_static path_beg -i /static /images /javascript /stylesheets #acl 规则编辑,acl <aclname> <criterion> [flags] [operator] <value> ...
  8. acl url_static path_end -i .jpg .gif .png .css .js #先定义规则然后在 use_backend 进行引用
  9.  
  10. use_backend static if url_static #匹配规则,匹配的规则调用值 static 节点池
  11. default_backend app #默认节点池
  12.  
  13. #---------------------------------------------------------------------
  14. # static backend for serving up images, stylesheets and such
  15. #---------------------------------------------------------------------
  16. backend static #定义static 节点池
  17. # mode tcp
  18. mode http #指定负载模式
  19. # blance static-rr 动态轮询负载
  20. # blance leastconn 最小连接负载
  21. # blance souce 基于源地址 hash 的负载
  22. # blance hdr(Host) 基于访问请求中的Host 的负载
  23. #
  24. balance roundrobin
  25. cookie SERVERID insert nocache indirect #插入 SERVERID cookie name ,并在后续用户访问时,利用cookie 维持会话
  26. server web1 192.68.100.101: check inter rise fall weight maxconn cookie webserver01 #指定server 状态监测,权重,最大连接和cookie 值
  27. server web2 192.68.100.103: check inter rise fall weight maxconn cookie webserver02
  28.  
  29. #---------------------------------------------------------------------
  30. # round robin balancing between the various backends
  31. #---------------------------------------------------------------------
  32. backend app
  33. balance roundrobin
  34. server app1 127.0.0.1: check
  35. server app2 127.0.0.1: check
  36. server app3 127.0.0.1: check
  37. server app4 127.0.0.1: check

配置案例二:

  1. #通过ACL 进行动静分离的配置
  2.  
  3. global
  4. log 127.0.0.1 local2
  5.  
  6. chroot /var/lib/haproxy
  7. pidfile /var/run/haproxy.pid
  8. maxconn
  9. user haproxy
  10. group haproxy
  11. daemon
  12.  
  13. # turn on stats unix socket
  14. stats socket /var/lib/haproxy/stats
  15.  
  16. defaults
  17. mode http
  18. log global
  19. option httplog
  20. option dontlognull
  21. option http-server-close
  22. option forwardfor except 127.0.0.0/
  23. option redispatch
  24. retries
  25. timeout http-request 10s
  26. timeout queue 1m
  27. timeout connect 10s
  28. timeout client 1m
  29. timeout server 1m
  30. timeout http-keep-alive 10s
  31. timeout check 10s
  32. maxconn
  33.  
  34. listen stats
  35. mode http
  36. bind 0.0.0.0:
  37. stats enable
  38. stats hide-version
  39. stats uri /haproxyadmin?stats
  40. stats realm Haproxy\ Statistics
  41. stats auth admin:admin
  42. stats admin if TRUE
  43.  
  44. frontend http-in
  45. bind *:
  46. mode http
  47. log global
  48. option httpclose
  49. option logasap
  50. option dontlognull
  51. capture request header Host len
  52. capture request header Referer len
  53. acl url_static path_beg -i /static /images /javascript /stylesheets
  54. acl url_static path_end -i .jpg .jpeg .gif .png .css .js
  55.  
  56. use_backend static_servers if url_static
  57. default_backend dynamic_servers
  58.  
  59. backend static_servers
  60. balance roundrobin
  61. server imgsrv1 172.16.200.7: check maxconn
  62. server imgsrv2 172.16.200.8: check maxconn
  63.  
  64. backend dynamic_servers
  65. cookie srv insert nocache
  66. balance roundrobin
  67. server websrv1 172.16.200.7: check maxconn cookie websrv1
  68. server websrv2 172.16.200.8: check maxconn cookie websrv2
  69. server websrv3 172.16.200.9: check maxconn cookie websrv3

配置案例 MySQL服务的配置示例:

  1. MySQL服务的配置示例
  2.  
  3. #---------------------------------------------------------------------
  4. # Global settings
  5. #---------------------------------------------------------------------
  6. global
  7. # to have these messages end up in /var/log/haproxy.log you will
  8. # need to:
  9. #
  10. # ) configure syslog to accept network log events. This is done
  11. # by adding the '-r' option to the SYSLOGD_OPTIONS in
  12. # /etc/sysconfig/syslog
  13. #
  14. # ) configure local2 events to go to the /var/log/haproxy.log
  15. # file. A line like the following can be added to
  16. # /etc/sysconfig/syslog
  17. #
  18. # local2.* /var/log/haproxy.log
  19. #
  20. log 127.0.0.1 local2
  21.  
  22. chroot /var/lib/haproxy
  23. pidfile /var/run/haproxy.pid
  24. maxconn
  25. user haproxy
  26. group haproxy
  27. daemon
  28.  
  29. defaults
  30. mode tcp
  31. log global
  32. option httplog
  33. option dontlognull
  34. retries
  35. timeout http-request 10s
  36. timeout queue 1m
  37. timeout connect 10s
  38. timeout client 1m
  39. timeout server 1m
  40. timeout http-keep-alive 10s
  41. timeout check 10s
  42. maxconn
  43.  
  44. listen stats
  45. mode http
  46. bind 0.0.0.0:
  47. stats enable
  48. stats hide-version
  49. stats uri /haproxyadmin?stats
  50. stats realm Haproxy\ Statistics
  51. stats auth admin:admin
  52. stats admin if TRUE
  53.  
  54. frontend mysql
  55. bind *:
  56. mode tcp
  57. log global
  58. default_backend mysqlservers
  59.  
  60. backend mysqlservers
  61. balance leastconn
  62. server dbsrv1 192.168.10.11: check port intval rise fall maxconn
  63. server dbsrv2 192.168.10.12: check port intval rise fall maxconn

haproxy 配置文件分析的更多相关文章

  1. haproxy配置文件详解和ACL功能

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  2. 千万级高并发负载均衡软件haproxy配置文件详解

    balance roundrobin         #轮询方式 balance source               #将用户IP经过hash计算后,使同一IP地址的所有请求都发送到同一固定的后 ...

  3. Python3.5 day3作业二:修改haproxy配置文件。

    需求: 1.使python具体增删查的功能. haproxy的配置文件. global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 lo ...

  4. python之haproxy配置文件操作(第三天)

    作业: 对haproxy配置文件进行操作 要求: 对haproxy配置文件中backend下的server实现增删改查的功能 一.这个程序有二个版本 1. python2.7版本见haproxy_py ...

  5. haproxy配置文件

    haproxy配置文件   思路:读一行.写一行 global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 info de ...

  6. haproxy配置文件简单管理

    版本:python3功能:对haproxy配置文件进行简单的查询.添加以及删除功能操作流程:1.根据提示选择相应的选项2.进入所选项后,根据提示写入相应的参数3.查询功能会返回查询结果,添加.删除以及 ...

  7. 作业-haproxy配置文件的增删查(有一个bug不知道咋改)

    # yangqiao #查询 ''' f=open("C:\\aaaaaaaaaaaaa\\haproxy.txt", "r", encoding=" ...

  8. RobotFramework 官方demo Quick Start Guide rst配置文件分析

    RobotFramework官方demo Quick Start Guide rst配置文件分析   by:授客 QQ:1033553122     博客:http://blog.sina.com.c ...

  9. s12-day03-work01 python修改haproxy配置文件(初级版本)

    #!/usr/local/env python3 ''' Author:@南非波波 Blog:http://www.cnblogs.com/songqingbo/ E-mail:qingbo.song ...

随机推荐

  1. C++中继承与抽象类

    继承语法格式如下: class 子类名称 : 继承方式(public private protected 三种) 父类名称 纯虚函数格式: virtual 返回值类型 函数名(参数列表)= 0:含有纯 ...

  2. Ehcache 3.7文档—基础篇—XML Configuration

    你可以使用xml配置创建CacheManager,根据这个schema definition ( http://www.ehcache.org/documentation/3.7/xsds.html# ...

  3. 使用npm 下载 cnpm

    在vue终端使用npm 1. 下载安装node.js 在node.js中有集成npm 2. 可以在终端中使用 node -v / npm -v 来查看安装的node/npm 的版本号 使用npm 安装 ...

  4. tcpdump我的交叉编译(mips)

    一.libpcap交叉编译 1.下载libpcap-1.8.1(http://www.tcpdump.org/) 2.解压 3.修改configure文件 a.注释掉 #if test -z &quo ...

  5. STA 463 Simple Linear Regression Report

    STA 463 Simple Linear Regression ReportSpring 2019 The goal of this part of the project is to perfor ...

  6. 在Vuex更新,组件内的视图更新问题

    由于js的限制,vue无法进行监听数组; 当你利用索引直接设置一个项时,例如: vm.items[indexOfItem] = newValue 当你修改数组的长度时,例如: vm.items.len ...

  7. nodejs启动web项目

    1.在根目录路径下输入 npm install ,会自动下载所需的包 2.安装完成对应的包以后,npm start,会自动打开浏览器

  8. idea搭建可运行Servlet的Web项目[maven]

    1. new Project File > new > Project… 2. 填写 GroupID\ArtifactID GroupID 是项目组织唯一的标识符,实际对应JAVA的包的结 ...

  9. ADB——修改手机默认参数

    修改原理 修改设置的原理主要是通过 settings 命令修改 /data/data/com.android.providers.settings/databases/settings.db 里存放的 ...

  10. 代码混淆工具——Virbox Protector Standalone

    VirboxProtector Standalone 加壳工具可对代码加密的技术有:代码混淆.代码虚拟化.代码加密. 代码混淆:利用花指令和代码非等价变形等技术,将程序的代码,转换成一种功能上等价,但 ...