LOG 功能:

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

# Provides UDP syslog reception
$ModLoad imudp              #需要启用
$UDPServerRun 514           #启动syslog 服务 # Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun # Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler # Save boot messages also to boot.log
local7.* /var/log/boot.log local2.* /var/log/haproxy/haproxy.log #指定 log 输出位置

配置案例一:

#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global #全局配置 ,进程和系统相关
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# ) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# ) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2 #日志设定,需要在/etc/rsyslog.conf 配置文件中进行设定。 chroot /var/lib/haproxy #修改haproxy 工作目录
pidfile /var/run/haproxy.pid
maxconn #允许最大连接
user haproxy
group haproxy
daemon #以守护进程方式进行运行,否则在前台进行工作 # turn on stats unix socket
stats socket /var/lib/haproxy/stats #stats 工作目录 #---------------------------------------------------------------------
#Proxies 配置段,代理的配置在这
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults #Proxies 的默认配置
mode http #默认代理模式
log global #全局的syslog 服务器,可以定义多个
option httplog #日志格式
option dontlognull
option http-server-close #代理主动断开超时连接
option forwardfor except 127.0.0.0/ #代理默认向后端插入 X-Forwarded-For ,mode 必须 http
option redispatch
retries
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 #---------------------------------------------------------------------
#stats 配置实例
#---------------------------------------------------------------------

listen stats_test          #配置stats 监听实例
bind *:1080 #绑定监听端口 1080
stats enable #启动stats 功能
stats hide-version #隐藏 haproxy 版本
#stats scope . #指定管理范围
stats uri /haproxyadmin?stats #指定访问路径
stats realm "HAproxy\ Statistics" #指定名称
stats auth zy:zzzzy #指定认证用户名,密码
stats admin if TRUE #启用管理功能
 
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend http_porxy #前端虚拟负载配置项,定义名称main ,或者别的
bind : #配置监听端口,有多种写法
bind : ssl crt /etc/haproxy/site.pem #监听端口绑定证书 acl url_static path_beg -i /static /images /javascript /stylesheets #acl 规则编辑,acl <aclname> <criterion> [flags] [operator] <value> ...
acl url_static path_end -i .jpg .gif .png .css .js #先定义规则然后在 use_backend 进行引用 use_backend static if url_static #匹配规则,匹配的规则调用值 static 节点池
default_backend app #默认节点池 #---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static #定义static 节点池
# mode tcp
mode http #指定负载模式
# blance static-rr 动态轮询负载
# blance leastconn 最小连接负载
# blance souce 基于源地址 hash 的负载
# blance hdr(Host) 基于访问请求中的Host 的负载
#
balance roundrobin
cookie SERVERID insert nocache indirect #插入 SERVERID cookie name ,并在后续用户访问时,利用cookie 维持会话
server web1 192.68.100.101: check inter rise fall weight maxconn cookie webserver01 #指定server 状态监测,权重,最大连接和cookie 值
server web2 192.68.100.103: check inter rise fall weight maxconn cookie webserver02 #---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 127.0.0.1: check
server app2 127.0.0.1: check
server app3 127.0.0.1: check
server app4 127.0.0.1: check

配置案例二:

#通过ACL 进行动静分离的配置

global
log 127.0.0.1 local2 chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn
user haproxy
group haproxy
daemon # turn on stats unix socket
stats socket /var/lib/haproxy/stats defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/
option redispatch
retries
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 listen stats
mode http
bind 0.0.0.0:
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin
stats admin if TRUE frontend http-in
bind *:
mode http
log global
option httpclose
option logasap
option dontlognull
capture request header Host len
capture request header Referer len
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .jpeg .gif .png .css .js use_backend static_servers if url_static
default_backend dynamic_servers backend static_servers
balance roundrobin
server imgsrv1 172.16.200.7: check maxconn
server imgsrv2 172.16.200.8: check maxconn backend dynamic_servers
cookie srv insert nocache
balance roundrobin
server websrv1 172.16.200.7: check maxconn cookie websrv1
server websrv2 172.16.200.8: check maxconn cookie websrv2
server websrv3 172.16.200.9: check maxconn cookie websrv3

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

MySQL服务的配置示例

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# ) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# ) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2 chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn
user haproxy
group haproxy
daemon defaults
mode tcp
log global
option httplog
option dontlognull
retries
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 listen stats
mode http
bind 0.0.0.0:
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin
stats admin if TRUE frontend mysql
bind *:
mode tcp
log global
default_backend mysqlservers backend mysqlservers
balance leastconn
server dbsrv1 192.168.10.11: check port intval rise fall maxconn
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. 使用MDI 和 XtraTabbedMdiManager 后 选项卡切换后Ribbon 合并后不选中MDI子窗...

    使用MDI 和 XtraTabbedMdiManager 后 选项卡切换后Ribbon 合并后不选中MDI子我这里是 继承 XtraTabbedMdiManager  所以,是重载的  OnSelec ...

  2. WcPro项目(WordCount优化)

    1 基本任务:代码编写+单元测试 1.1 项目GitHub地址 https://github.com/ReWr1te/WcPro 1.2 项目PSP表格 PSP2.1 PSP阶段 预估耗时(分钟) 实 ...

  3. docker container 互联

    创建一个 network docker network create test-network 创建rocketmq docker run -d  -p 9876:9876 -p 10909:1090 ...

  4. boot跳转到app后,中断不起作用的原因

    boot跳转到app后 osKernelStart()之前,中断有问题,不起作用 原因是因为boot跳转之前__disable_irq(); 跳转到APP后,并不是一切从头开始,__disable_i ...

  5. X86-32位架构的CPU是不是内存只能到4G

    不是的,可以通过分页机制扩展实现超过4G内存的支持. 什么是分页机制扩展? PAE. 什么是PAE?   PAE如何实现的?  

  6. sizeof操作符的一些例子

    例一: #include <iostream> using namespace std; class A { public: char c; }; class B { public: in ...

  7. 当使用eclipse将项目部署到Tomcat时,提示Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modul

    原因: 此版本选择过高.当出现此错误时,直接对项目可能无法进行修改.可以通过修改项目的配置文件来达到目的. \workspace\项目名称\.settings\org.eclipse.wst.comm ...

  8. 数据库主库从库宕机重启后binlog数据同步

    由于阿里云经典网络迁移到专用网络,一不小心没有先预备方案调整网段, 导致实例无法以内网IP形式访问数据库,被迫进行数据库停机后网络网段调整,导致宕机了几个小时...被客户各种投诉爆了.. 基于这次数据 ...

  9. 【转】Java遍历Map对象的四种方式

    关于java中遍历map具体哪四种方式,请看下文详解吧. 方式一 这是最常见的并且在大多数情况下也是最可取的遍历方式.在键值都需要时使用. Map<Integer, Integer> ma ...

  10. hystrix参数使用方法

    hystrix+feign+ribbon,但是可能很多人都知道hystrix还有线程隔离,信号量隔离,等等各种参数配置,在这几就记录下hystrix的参数, 一.hystrix参数使用方法 通过注解@ ...