设为首页 收藏本站
查看: 660|回复: 0

[经验分享] 使用awstats监控Tomcat日志

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2018-11-30 13:26:59 | 显示全部楼层 |阅读模式
awstats 是由perl语言编写的,所以要首先准备好awstats的运行环境。
# yum install –y perl


1、下载安装awstats




awstats install 文件夹
# cd /opt
# wget http://www.awstats.org/files/awstats.tar.gz
# tar xvf awstats.tar.gz
# mv awstats/usr/local/awstats



2、创建一个tomcot统计
[root@portal-1 tools]cd /user/local/awstats/tools
[root@portal-1 tools]# perl awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):> none    //tomcat 设置为空
Your web server config file(s) could not be found.
You will need to setup your web server manually to declare AWStats
script as a CGI, if you want to build reports dynamically.
See AWStats setup documentation (file docs/index.html)
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
  File awstats.model.conf updated.
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.ejoywifi.com
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>


-----> Create config file '/etc/awstats/awstats.www.ejoywifi.com.conf'
Config file /etc/awstats/awstats.www.ejoywifi.com.conf created.
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.ejoywifi.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
A SIMPLE config file has been created: /etc/awstats/awstats.www.ejoywifi.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.ejoywifi.com' with command:
> perl awstats.pl -update -config=www.ejoywifi.com
You can also build static report pages for 'www.ejoywifi.com' with command:
> perl awstats.pl -output=pagetype -config=www.ejoywifi.com
Press ENTER to finish…





3、tomcat7 logs 设置


  配置tomcat日志文件格式
vi /data/portalCms/web/tomcat7_web/conf/server.xml
pattern="%h %u %t "%r" %s %b %{Referer}i "%{User-Agent}i";" />

本服务器tomcat /data/portalCms/web/tomcat7_web
/data/portalCms/web/tomcat7_web/logs/web_access_log.2015-09-06.txt
/data/portalCms/web/tomcat7_web/logs/web_access_log.%YYYY-%MM-%DD.txt


tomcat输出的日志格式


10.238.38.190 - [21/Oct/2015:15:39:09 +0800] "GET /favicon.ico HTTP/1.1" 200 310 http://10.248.2.10/awstats/cgi-bin/awstats.pl?config=www.ejoywifi.com
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36"




4、修改awstats配置文件
[root@portal-1 awstats]# vi /etc/awstats/awstats.www.ejoywifi.com.conf#LogFile="/var/log/httpd/mylog.log"



设置tomcat日志路径
LogFile=“/data/portalCms/web/tomcat7_web/logs/web_access_log.%YYYY-%MM-%DD.txt"
设置日志格式通配
LogFormat =“%host %logname %time1 %methodurl %code %bytesd %referer %uaquot”
设置图标调用,默认为 /icon,显示有问题
DirIcons="./icon"



awstats logformat:
#   %host             Client hostname or IP address (or Sender host for mail log)
#   %host_r           Receiver hostname or IP address (for mail log)
#   %lognamequot      Authenticated login/user with format: "john"
#   %logname          Authenticated login/user with format: john
#   %time1            Date and time with format: [dd/mon/yyyy:hh:mm:ss +0000] or [dd/mon/yyyy:hh:mm:ss]
#   %time2            Date and time with format: yyyy-mm-dd hh:mm:ss
#   %time3            Date and time with format: Mon dd hh:mm:ss or Mon dd hh:mm:ss yyyy
#   %time4            Date and time with unix timestamp format: dddddddddd
#   %methodurl        Method and URL with format: "GET /index.html HTTP/x.x"
#   %methodurlnoprot  Method and URL with format: "GET /index.html"
#   %method           Method with format: GET
#   %url              URL only with format: /index.html
#   %query            Query string (used by URLWithQuery option)
#   %code             Return code status (with format for web log: 999)
#   %bytesd           Size of document in bytes
#   %refererquot      Referer page with format: "http://from.com/from.htm"
#   %referer          Referer page with format: http://from.com/from.htm
#   %uabracket        User agent with format: [Mozilla/4.0 (compatible, ...)]
#   %uaquot           User agent with format: "Mozilla/4.0 (compatible, ...)"
#   %ua               User agent with format: Mozilla/4.0_(compatible...)
#   %gzipin           mod_gzip compression input bytes: In:XXX
#   %gzipout          mod_gzip compression output bytes & ratio: Out:YYY:ZZpct.
#   %gzipratio        mod_gzip compression ratio: ZZpct.
#   %deflateratio     mod_deflate compression ratio with format: (ZZ)
#   %email            EMail sender (for mail log)
#   %email_r          EMail receiver (for mail log)
#   %virtualname      Web sever virtual hostname. Use this tag when same log
#                     contains data of several virtual web servers. AWStats
#                     will discard records not in SiteDomain nor HostAliases
#   %cluster          If log file is provided from several computers (merged by
#                     logresolvemerge.pl), use this to define cluster id field.
#   %extraX           Another field that you plan to use for building a
#                     personalized report with ExtraSection feature (See later).
#   If your log format has some fields not included in this list, use:
#   %other            Means another not used field
#   %otherquot        Means another not used double quoted field






5、测试执行读取日志更新
[root@portal-1 cgi-bin]# perl awstats.pl -update -config=www.ejoywifi.com
Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.
Setup ('/etc/awstats/awstats.www.ejoywifi.com.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).
#用来存放awstats的数据文件
[root@portal-1 /]# mkdir -m 755 /var/lib/awstats



手动生成awstats日志分析数据库信息
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.ejoywifi.com
[root@portal-1 conf]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.ejoywifi.com
Create/Update database for config "/etc/awstats/awstats.www.ejoywifi.com.conf" by AWStats version 7.0 (build 1.975)
From data in log file "/data/portalCms/web/tomcat7_web/logs/web_access_log.2015-10-13.txt"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 1202)
Jumped lines in file: 1202
Found 1202 already parsed records.
Parsed lines in file: 4
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 4 new qualified records.





6、创建awstats日志报告静态html目录
mkdir -p /data/portalCms/web/www/static/awstats/
cp -R /usr/local/awstats/wwwroot/css /data/portalCms/web/www/static/awstats/
cp -R /usr/local/awstats/wwwroot/icon /data/portalCms/web/www/static/awstats/



7、手动生成html静态页面报告


[root@portal-1 /]# /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.ejoywifi.com -lang=cn -dir=/data/portalCms/web/www/static/awstats/wifiportal -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl

Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -update -configdir=
Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output
Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=alldomains
Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=allhosts
Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=lasthosts
Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=unknownip
Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=allrobots
Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=lastrobots
Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=session
Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=urldetail
Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=urlentry
Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=urlexit
Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=osdetail
Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=unknownos
Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=browserdetail
Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=unknownbrowser
Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=refererse
Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=refererpages
Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=keyphrases
Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=keywords
Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.ejoywifi.com -staticlinks -lang=cn -output=errors404
20 files built.
Main HTML page is 'awstats.www.ejoywifi.com.html'.
[root@portal-1 /]#



8、放在crontab计划任务中
在上面我们只是手动生成了html报告文件,这里让它自动完成这些操作.
编辑/etc/crontab文件,在最后添加以下两行,每天23:58分重新生成一次统计页面
# crontab –e
58 23 * * * /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.ejoywifi.com -lang=cn -dir=/data/portalCms/web/www/static/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl > /dev/null 2&>1


9、访问静态页面


http://10.248.2.10:8080/static/awstats/awstats.www.ejoywifi.com.html






http://s3.运维网.com/wyfs02/M01/76/D6/wKiom1ZdYDWSA3SIAADJ2Jd8rj0945.png


10、Tomcat7 开启CGI,并配置awstats日志监控
1. 修改\conf\web.xml配置文件,取消 cgi servlet 和对应的 mapping 注释,让Tomcat支持cgi程序执行:


   
    cgi
    org.apache.catalina.servlets.CGIServlet
   
        debug
        0
   
   
        cgiPathPrefix
        WEB-INF/cgi
   
   
        passShellEnvironment
        true
   
5


    cgi
    /cgi-bin/*
11. 修改\conf\context.xml配置文件,在Context上添加 privileged="true" 属性:







12. 测试CGI是否成功,在\webapps\ROOT\WEB-INF\cgi\下创建cgi脚本文件 test.cgi:


# filename: test.cgi
print "Content-type: text/html\n\n";
print "Hello, world!\n"
启动Tomcat,并访问:http://localhost:8080/cgi-bin/test.cgi,如果能看到  Hello, world! 页面,说明cgi开启成功。


13.  a. 在/webapps/下创建 awstats目录以及相应的WEB-INF目录
       b. 将user/local/awststs/wwwroot/目录下 css/,icon/,js/目录拷贝到 /webapps/awstats/ 目录下
       c. 将user/local/awststs/wwwroot/cgi-bin/ 下的所有文件拷贝到 /webapps/awstats/WEB-INF/cgi 目录下




14. 拷贝ejoywifi配置文件至cig cp /etc/awstats/awstats.www.ejoywifi.com.conf /data/portalCms/web/tomcat7_web/webapps/awstats/WEB-INF/cgi

      
      修改  DirIcons=“../icon”,否则页面无法显示图片
     允许在页面更新数据 AllowToUpdateStatsFromBrowser=1
     
15.测试 http://10.248.2.10/awstats/cgi-bin/awstats.pl?config=www.ejoywifi.com


http://s4.运维网.com/wyfs02/M01/76/D5/wKioL1ZdYXmDNi7XAAC20qtUlOA532.png
  

  参考:http://www.linuxidc.com/Linux/2012-10/72943.htm
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-641644-1-1.html 上篇帖子: Tomcat相关总结 下篇帖子: tomcat在ubuntu14下使用80端口
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表