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

[经验分享] Apache日志分析工具awstats配置

[复制链接]

尚未签到

发表于 2018-11-17 12:41:55 | 显示全部楼层 |阅读模式
  Apache日志分析工具awstats配置
  awstats软件下载地址:
  http://www.awstats.org/#DOWNLOAD
  https://awstats.sourceforge.io/#download
一、准备工作
  1、一台Linux系统虚拟机或服务器,这里我使用的是CentOS7.3系统虚拟机
  IP地址:192.168.115.120
  域名:www. awstats.com
  在CentOS7.3中执行下面的内容添加域名解析
  echo “192.168.115.120  www. awstats.com” >>/etc/hosts
  2、一台用来测试配置结果的window10客户端
  IP地址和CentOS7.3在同一网段,同样Windows10的C:\Windows\System32\drivers\etc\hosts文件中也需要添加域名解析, 以记事本打开hosts文件,最后加上一行:192.168.115.120  www. awstats.com,保存退出。
二、安装Apache服务及相关配置
1、Apache快速编译安装
  yum -y install gcc gcc-c++ make pcre-devel expat-devel perl
  wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz
  tar xf apr-1.6.3.tar.gz
  cd apr-1.6.3
  ./configure
  make && make install
  cd ..
  wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
  tar xf apr-util-1.6.1.tar.gz
  cd apr-util-1.6.1
  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  make && make install
  cd ..
  wget https://ftp.pcre.org/pub/pcre/pcre-8.34.tar.gz
  tar xf pcre-8.34.tar.gz
  cd pcre-8.34
  ./configure
  make && make install
  cd ..
  wget http://www.zlib.net/fossils/zlib-1.2.11.tar.gz
  tar xf zlib-1.2.11.tar.gz
  cd zlib-1.2.11
  ./configure
  make && make install
  cd ..
  wget  http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  tar xf httpd-2.4.7.tar.gz
  cd httpd-2.4.7
  ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so  --with-mpm=worker --enable-rewrite --enable-charset-lite --enable-cgid --enable-cgi
  make && make install
  cd ..
2、将Apache服务添加到系统服务并设置开机自启
  cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
  vim /etc/init.d/httpd  编辑此文件添加以下两行内容
  #!/bin/sh
  #chkconfig:35 80 25
  #description:web server
  chkconfig --add httpd    将httpd加入到service管理器
  systemctl daemon-reload   重载系统系统管理器
  systemctl enable httpd    设置httpd为开机自启
3、Apache其他配置
  设置主机名
  vim /usr/local/apache2/conf/httpd.conf
  ServerName www.awstats.com:80
  /usr/local/apache2/bin/apachectl start
  优化执行路径(把Apache的执行程序文件做个软链接使其可以直接执行)
  ln -s /usr/local/apache2/conf/httpd.conf /etc/httpd.conf
  ln -s /usr/local/apache2/bin/* /usr/local/bin/
三、配置Awstats日志分析软件
1、查看是否加载和编译cgi模块
  注意:awstats不支持分析分割日志,如果日志已分割,需修改回来
  确认是否加载了cgi模块
  [root@localhost ~]# apachectl -D DUMP_MODULES | grep cgi
  确认是否编译过cgi模块
  [root@localhost ~]# ls /usr/local/apache2/modules/|grep cgi
  mod_cgid.so
  mod_cgi.so
  mod_proxy_fcgi.so
  mod_proxy_scgi.so
  通过查看发现这里没有加载cgi模块,但是编译过cgi模块
  [root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf   去掉cgi相关注释
  LoadModule cgid_module modules/mod_cgid.so
  LoadModule cgi_module modules/mod_cgi.so
2、下载并配置awstats软件
(1)下载awstats软件并解压
  [root@localhost ~]# wget https://jaist.dl.sourceforge.net/project/awstats/AWStats/7.6/awstats-7.6.tar.gz
  [root@localhost ~]# tar xf awstats-7.6.tar.gz
  [root@localhost ~]# mv awstats-7.6 /usr/local/awstats
(2)编辑awstats配置脚本
  [root@localhost ~]# cd /usr/local/awstats/tools/
  [root@localhost tools]# ./awstats_configure.pl
  ----- AWStats awstats_configure 1.0 (build 20140126) (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>  - 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
  Found Web server Apache config file '/usr/local/apache2/conf/httpd.conf'
  -----> Check and complete web server config file '/usr/local/apache2/conf/httpd.conf'
  Warning: You Apache config file contains directives to write 'common' log files
  This means that some features can't work (os, browsers and keywords detection).
  Do you want me to setup Apache to write 'combined' log files [y/N] ? y
  Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
  Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
  Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
  Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
  Add '' directive
  AWStats directives added to Apache config file.
  -----> 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.awstats.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.awstats.com.conf'
  Config file /etc/awstats/awstats.www.awstats.com.conf created.
  -----> Restart Web server with '/sbin/service httpd restart'
  -----> 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.awstats.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.awstats.com.conf
  You should have a look inside to check and change manually main parameters.
  You can then manually update your statistics for 'www.awstats.com' with command:
  > perl awstats.pl -update -config=www.awstats.com
  You can also read your statistics for 'www.awstats.com' with URL:
  > http://localhost/awstats/awstats.pl?config=www.awstats.com
  记住这一段,之后会在浏览器使用这个地址
  Press ENTER to finish...     继续按回车
(3)编辑awstats程序的主配置文件
  [root@localhost ~]# vim /etc/awstats/awstats.www.awstats.com.conf
  LogFile="/usr/local/apache2/logs/access_log"
  DirData="/usr/local/awstats/awstats_data"
  [root@localhost ~]# systemctl restart httpd
  [root@localhost ~]# cd /usr/local/awstats/tools/
  [root@localhost tools]# chmod +x awstats_updateall.pl
  [root@localhost tools]# ./awstats_updateall.pl now   手动采集数据
(4)设置crond开机自启和定时任务,每5分钟采集一次数据
  [root@localhost tools]# crontab -e
  */5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
  [root@localhost ~]# systemctl enable crond
  [root@localhost ~]# systemctl list-unit-files | grep crond
  crond.service                               enabled
(5)httpd.conf中添加允许访问的权限
  [root@localhost ~]# vim /etc/httpd.conf
  
  Options None
  AllowOverride None
  Order allow,deny
  Allow from all
  Require all granted
  
  [root@localhost ~]# systemctl restart httpd
四、在Windows的浏览器中进行测试
1、浏览器测试页面是否能正常访问
  浏览器地址栏输入以下网址:http://192.168.115.120//awstats/awstats.pl?config=www.awstats.com会出现如下界面。
DSC0000.jpg

2、配置页面自动跳转优化统计页面访问
  [root@localhost ~]# vim /usr/local/apache2/htdocs/index.html
  
  
  
  
  
  
  上面跳转代码写好之后重启Apache服务
  [root@localhost ~]# systemctl restart httpd
  在Windows浏览器地址栏输入www.awstats.com,就会自动跳转到http://192.168.115.120//awstats/awstats.pl?config=www.awstats.com地址了。
  好了,到这里我们的Apache日志分析工具awstats就已经配置完成了。
  注意:服务器如果没做dns的话,必须服务器和客户端上都修改hosts文件


运维网声明 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-636232-1-1.html 上篇帖子: 用Linux虚拟机手工编译安装Apache 下篇帖子: Could not initialize class org.apache.xpath...
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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