|
使用场景:
基于awstats的日志访问统计系统,用于分析统计网站页面访问量,为后期扩展提供依据。
公司网站架构:
一部分应用采用haproxy+tomcat,一部分采用nginx+tomcat(nginx通过域名分发请求都后端的非80端口)。
工作原理:
应用部署服务器0点以后通过rsync方式把访问日志同步到awstats服务器,awstat根据之前定义好的配置文件进行分析统计。
日志格式配置:
A,haproxy + tomcat
haproxy配置haproxy.cfg
defaults
.........
option forwardfor # 从Http Header中获得客户端ip
.........
tomcat 配置server.xml(注意pattern由双引号改为单引号,以便awstats分析时候将包含空格的内容作为一个字段分析)
B, nginx + tomcat
nginx配置nginx.conf
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/client.test.com.access.log main;
tomcat无需配置。
awstats配置:
单个分析域名配置 awstats.test.com.conf
Include "awstats.common.conf"
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /usr/local/awstats/log/*test.com* |"
LogType=W
LogFormat="%host %other %logname %time1 %methodurl %code %bytesd"
LogSeparator=" "
SiteDomain="site.test.com"
HostAliases="site.com"
awstats计划任务:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=site.test.com
使用经验:
A,日志集中存放;有多个节点时,节点日志文件名要不一样。
B,删除重复多余日志。如果在haproxy前端还有代理服务器,需要删除后端tomcat中包含代理服务器IP的重复日志;同时删除监控软件访问请求,比如nagios的check_http
C,附件中为awstats.common.conf
附件:http://down.运维网.com/data/2364364
|
|
|