日志分析主要是分析web服务的访问日志,通过日志中包含的信息体现web服务的状态,访问情况等等信息,由此可以对web服务进行调整。

日志分析要分析的主要项
1、客户端的IP了解其所在地,为了提高访问的速度,可以在同地区访问很多的地方建立机房。
2、那些资源访问次数较多,代表资源受欢迎程度高。
3、记录访问时间,了解网站访问的波峰波谷,可以根据这个确定维护时间。
4、客户端使用的浏览器。做兼容。
独立IP:
      定的IP地址访问网站的次数。
独立访客:
      访问网站的自然人。
页面浏览量 pv(page view)
      网站的某个内容或消息,比较受欢迎。

信息的汇总最好形成可视化的图表,方便查看和整理。

日志的轮滚,日志的轮滚周期要根据需求确定好。轮滚就是防止单个日志文件太大,时间跨度太长,造成查看困难的问题而生的。

如果要将轮滚过的日志重新合成一个那么就直接追加到一个文件中就好了。

#!/bin/bash
logdir="/log/nginx"
filename="access.log-"
logfile="${logdir}/all_access.log"
> $logfile
for i in `seq 7 -1 1`
docat ${logdir}/${filename}`date -d "$i day ago" "+%Y%m%d"` >> $logfile
done

合并7天内日志的脚本。

主要用了

date -d "1 day ago" "+%Y%m%d"

这个命令。打印1天前的日期,并格式化输出。

清空日志:如果直接rm -f 删除日志的文件并不会释放空间,它只是切断了用户和文件之间的联系,但是进程没有被杀死,硬盘的容量还是那么多,要重启服务才能生效。

最简单的清空日志。

> filename.log
cat /dev/null > filename.log

就直接重定向把文件内容顶掉。

综合以上情况使用的日志分析工具选用awstats

配置方法:
1、下载安装。
2、配置。
3、生成数据库文件

1、用的是从网上下载的直接就有bin包的awstats,解压就可以用。

下载地址:http://www.awstats.org/

然后解压缩到/usr/local/awstats

[root@localhost local]# tar xf awstats-7.7.tar.gz
[root@localhost local]# mv awstats-7.7/ awstats/

这个是默认的路径,直接解压的是后边有版本号的,最好改下名,否则会有warning警告信息,提示你。

我下的是awstats7.7,直接就可以有执行权限。如果是7.2还是多少以前的版本,要将目录内的.pl文件加上可执行权限chmod +x /usr/local/awstats/tools/*.plchmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl

安装apache。安装这个是为了能在网页上看到图形的日志汇总,日志分析。

[root@localhost local]# yum install httpd -y

给awstats整个目录的属组改成apache。

[root@localhost local]# chown -R apache:apache awstats/

2、配置,生成awstats配置文件并修改。

运行向导文件,生成awstats的配置文件:

这个过程基本都是自动生成的,只要注意有注释的就好了。

[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 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 installEnter 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):
> /etc/httpd/conf/httpd.conf    //这里指定的是Apache的配置文件位置。-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'All AWStats directives are already present.-----> 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    //这里需要写下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:
> testawstats        //这里指定的是访问的地址-----> 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.testawstats.conf'Config file /etc/awstats/awstats.testawstats.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=testawstats
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.testawstats.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'testawstats' with command:
> perl awstats.pl -update -config=testawstats
You can also read your statistics for 'testawstats' with URL:
> http://localhost/awstats/awstats.pl?config=testawstatsPress ENTER to finish...    //按回车结束

到这里就生成了awstats的配置文件。

[root@localhost tools]# vim /etc/awstats/awstats.testawstats.conf

可以看到这个配置文件的中间那段就是在上边写的访问地址。

 50 LogFile="/var/log/httpd/access_log"这个是被分析日志的位置,随便写,但是要有这个日志220 DirData="/usr/local/awstats/data"这个是日志分析数据库文件的位置,也是随便的

创建目录赋予权限

[root@localhost tools]# mkdir /usr/local/awstats/data
[root@localhost tools]# chown apache:apache /usr/local/awstats/data/

配置apache

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf //Apache配置文件
<Directory "/usr/local/awstats/wwwroot">Options NoneAllowOverride Noneorder allow,denyallow from allRequire all granted
</Directory>

改成这样就可以了。

启动服务

[root@localhost tools]# systemctl restart httpd
[root@localhost tools]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

3、生成数据库文件。

生成数据库文件:

[root@localhost data]# perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=testawstats -update
Create/Update database for config "/etc/awstats/awstats.testawstats.conf" by AWStats version 7.7 (build 20180105)
From data in log file "/var/log/httpd/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 5654Found 0 dropped records,Found 0 comments,Found 0 blank records,Found 0 corrupted records,Found 0 old records,Found 5654 new qualified records.
[root@localhost tools]# 

注意:-config=testawstats =后边的要写在最初配置时写的访问地址

然后查看数据库文件:

[root@localhost tools]# cd /usr/local/awstats/data/
[root@localhost data]# ls
awstats112019.testawstats.txt  awstats122019.testawstats.txt

目录就是配置文件中的那个位置。

注意:如果没有生成数据库文件但是看到那个输出的都是0 ,就是没有日志,空的自然没办法生成数据库文件。

打开浏览器访问。

http://172.16.12.72/awstats/awstats.pl?config=testawstats

然后就能看到这个日志的分析了。

以上就是apache的日志分析了。

分析其他的东西:

nginx的日志格式和Apache的日志格式一样,不用改东西,直接修改配置文件中的被分析日志就好了。

tomcat 的日志格式不一样,所以要进行修改。

将配置文件中加上这个

LogFormat = "%host %other %logname %time1 %methodurl %code"
这个就是日志的格式,主机名(IP) 访问的人  登录名   访问时间   访问方式  代码块

并修改被监控日志就好了。

注意:在修改被分析日志之后,一定要重新生成数据库文件。否则还是上一个日志的分析情况。

另外,awstats这个软件在epel源中有,如果配置了epel源可以直接yum install 安装。

awstats日志分析相关推荐

  1. 搭建AWStats日志分析系统

    文章目录 搭建AWStats日志分析系统 实验步骤: 修改DNS主配置文件 修改http服务主配置文件 安装AWStats 修改http服务配置文件 搭建AWStats日志分析系统 AWStats是一 ...

  2. Apache的配置与应用【Apache访问控制】以及apache日志管理【日志分割、awstats日志分析】

    Apache的配置与应用以及日志管理 文章目录 Apache的配置与应用以及日志管理 一.Apache连接和访问控制 1.Apache连接 [1]KeepAlive [2]KeepAlive Time ...

  3. Centos7.6下搭建AWStats日志分析系统

    文章目录 一.AWStats日志分析系统简介 二.部署AWStats日志分析系统 一.AWStats日志分析系统简介 Perl语言开发的一款开源日志分析系统 可用来分析Apache.Samba.Vsf ...

  4. AWStats 日志分析系统(含源码包)

    前言 在上一篇文章中写了关于httpd的一些简介.配置.那么我们应该知道,HTTP服务器的访问量非常庞大,在它的访问日志文件access_log 中,记录了很多很多客户的访问信息,维护的管理人员会通过 ...

  5. AWStats日志分析系统

    文章目录 一.概述 二.实验环境 三.实验步骤 四.安装配置apache 五.安装配置DNS 六.安装AWStats 七.实验测试 搭建服务所需安装包和工具包 链接:https://pan.baidu ...

  6. AWStats日志分析理论与实验

    文章目录 前言: 一.AWStats概述 1.1 AWStats日志分析系统 1.2 AWStats主要功能 二.AWStats 实验 2.1 实验环境 2.2.1 安装dns.httpd服务 2.2 ...

  7. AWStats日志分析之系统的部署

    文章目录 一.AWStats日志分析系统介绍 二.AWStats日志分析系统的部署 2.1.系统环境 2.2.部署过程 2.3.数据更新 2.4.优化网页地址 一.AWStats日志分析系统介绍 AW ...

  8. 部署Awstats日志分析系统

    AWStats分析系统是使用Perl语言开发的一款开源日志分析系统.可用于分析Apache.Samba.Vsftpd.IIS等服务的日志信息.也可以结合crond等计划任务,不断对增长的日志进行定期分 ...

  9. awstats linux日志分析,Linux环境下安装部署AWStats日志分析系统实例

    AWStats是使用Perl语言开发的一款开放性日志分析系统,可分析Apache网站服务器的访问日志,还可以用来分析Samba.Vsftpd.IIS等日志信息. 此文章主要讲解如何在linux系统下安 ...

  10. Linux环境下安装部署AWStats日志分析系统实例

    AWStats是使用Perl语言开发的一款开放性日志分析系统,可分析Apache网站服务器的访问日志,还可以用来分析Samba.Vsftpd.IIS等日志信息.       此文章主要讲解如何在lin ...

最新文章

  1. typedef 多文件引用
  2. 深度学习-TF函数-layers.concatenate用法 numpy数组维度
  3. SAP Spartacus list view里router-outlet的填充逻辑
  4. [react] 和Component两者的区别是什么
  5. 18张颠覆三观的照片!
  6. [Unity] TortoiseSVN 的 CheckOut 未响应的解决记录
  7. 蓝桥杯 ADV-170算法提高 数字黑洞
  8. Qt4 QRadioButton和QCheckBox用法示例
  9. 学校计算机维护投标书,信息化系统硬件及应用系统安全运维服务投标书范本
  10. WORD插入多张图片并上下左右居中自动对齐操作;论文图片表格排版
  11. 文件名不显示后缀格式(扩展名)
  12. 基于Java+Springboot+Vue校园志愿者管理系统设计与实现
  13. android中Uri.parse()用法,调用电话短信浏览器等
  14. fiddler抓包如何只抓手机端的包 不抓电脑的包
  15. 您只能在Photoshop CS4中做的3酷技巧
  16. maptalks+three.js+vue webpack项目实现二维地图上贴三维模型
  17. 规范使用计算机的ppt,2016年职称计算机PowerPoint操作练习题
  18. Docker怎么样拉取镜像?怎样删除镜像?
  19. photoshop插画插件_一键生成2.5D风格插画的PS插件
  20. 空口定义、下行传输流程

热门文章

  1. 炸房”网游外挂的刑事责任辨析
  2. apk如何使用腾讯加固
  3. 【cartographer源码解析--外推器】
  4. 租房哪里又便宜又好?python可视化爬虫告诉你!
  5. Highcharts JS v10.1.0 Crack
  6. java游戏开发入门(九) -音效
  7. 联网系统中Cisco交换机的注意事项
  8. 打开cmd方式与常用Dos命令
  9. 三十而立再出发 六十六载谱芳华 | 吉林大学举行交通学院成立30周年暨交通学科创建66周年庆祝大会...
  10. steamVR插件的基本功能