Chinaunix首页 | 论坛 | 博客
  • 博客访问: 342598
  • 博文数量: 52
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-27 14:21
个人简介

知道自己该干嘛,知道自己能干嘛

文章分类

全部博文(52)

文章存档

2019年(1)

2018年(8)

2017年(2)

2016年(11)

2015年(3)

2014年(10)

2013年(17)

我的朋友

分类: 系统运维

2013-08-27 22:31:41

       我们使用 haproxy 代理后端的2个 java 应用,使用 acl path_beg 来区别用户的请求,从而分发到各自的java应用上,然后问题应运而生,领导提了一个小要求,就是要在日志里体现每个请求各的主机头信息,好 既然需求有了我们就去搞定,解决的办法很多都是平时阅读文档的积累,可能当时没用,但是有印象,之后有此类需求就可以派上用场啦。
           haproxy 支持三种日志格式: 分别为 "默认 , tcp , http", 既然我们要抓去主机头信息,肯定是要关注http日志的格式。
           官方文档注解:
  1. HAProxy supports 3 log formats. Several fields are common between these formats and will be detailed in the next sections. A few of them may slightly vary with the configuration, due to indicators specific to certain options
          然后我们在去看一下,关于http日志格式的详细说明,看到这句话,我们眼前一亮.
  1. This format is enabled when "option httplog" is set on the frontend. It provides the same information as the TCP format with some HTTP - specific fields such as the request, the status code, and captures of headers and cookies.
         很好,看来只需要我们简单配置 一下就可以了,我们先看一下这个选项的用法及其说明.
  1. capture request header len
  2. Capture and log the first occurrence of the specified request header.
  3. May be used in sections : defaults | frontend | listen | backend
  4.                           no       | yes      | yes    | no
          : 需要捕捉头部信息的内容的名称,我们这次选取 Host User-Agent Referer 这三个内容
         : 定义捕捉内容的字符长度



         接下来,我们重启下服务,查看一下日志 
  1. Aug 6 21:11:52 localhost haproxy[9122]: 124.238.252.219:41862 [06/Aug/2013:21:11:52.674] web_proxy web_proxy/web2_xxx2 0/0/0/0/180 200 1228 - - ---- 69/69/69/37/0 0/0 {p.xxx.com|Mozilla/4.0 (com|} "GET /iframe.jsp?%20ytc=&ycc=&ybc=&ybco=D9D9D9&ytb=0&ycb=0&ytu=0&ycu=0&yw=468&yh%20=60&ys=093829739350beab&ym=7d2f148c95df91fa&yu=72301&yz=1275%2074&yp=3&yt=1&ya=1&yc=1&yf=miaozhen&yhc=86431 HTTP/1.1"
         网站名称使用 xxx 代替 

                     OK , 看到了吧,我们的日志内容已出现 Host User-Agent Referer 相关信息.

                                                                                                                                    emar_Cail


                    参考资料:
                                      



阅读(3285) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~