Apache日志分割(rotatelogs与cronolog)
程序员文章站
2022-06-25 21:46:08
...
目录
日志分割
简介
随着网站的访问量增加,默认情况下Apache的单个日志文件也会越来越大
日志文件占用磁盘空间很大
- 查看相关信息不方便
- 对日志文件进行分割
工具
- Apache自带rotatelogs分割工具实现
- 第三方工具cronolog分割
rotatelogs分割工具
- 配置网站的日志文件转交给rotatelogs分割处理
配置格式
ErrorLog "| rotatelogs命令的绝对路径-日志文件路径/网站名-error_%Y %m%d.log 86400”
CustomLog "| rotatelogs命令的绝对路径1日志文件路径/网站名-access_%Y%m%d.log 86400" combined
编辑配置文件
[aaa@qq.com ~]# vi /etc/httpd.conf
[aaa@qq.com ~]# systemctl start httpd
[aaa@qq.com ~]# systemctl status httpd
日志设置
ErrorLog "|/usr/bin/rotatelogs -l logs/error_log_%Y-%m-%d 86400"
-l:表示使用本地时间
/error_log:日志名称
%Y-%m-%d:年-月-日
86400:表示日志分隔的间隔是1天,单位是秒
CustomLog "|/usr/bin/rotatelogs -l logs/access_log_%Y-%m-%d 86400" common //错误日志
查看日志文件
[aaa@qq.com ~]# cd /usr/local/httpd/logs/
[aaa@qq.com logs]# ls -lh
cronolog日志分割
解压缩安装包
[aaa@qq.com ~]# tar zxvf cronolog-1.6.2.tar.gz
文件默认设置
[aaa@qq.com ~]# cd cronolog-1.6.2/
[aaa@qq.com cronolog-1.6.2]# ./configure
编译安装
[aaa@qq.com cronolog-1.6.2]# make && make install
查看日志
[aaa@qq.com cronolog-1.6.2]# vi /etc/httpd.conf
ErrorLog "|/usr/local/sbin/cronolog logs/error.log_%Y-%m-%d"
CustomLog "|/usr/local/sbin/cronolog logs/access.log_%Y-%m-%d" common
[aaa@qq.com ~]# systemctl start httpd
[aaa@qq.com ~]# httpd -t
[aaa@qq.com ~]# systemctl stop firewalld
[aaa@qq.com ~]# setenforce 0
[aaa@qq.com ~]# cd /usr/local/httpd/logs/
[aaa@qq.com logs]# ls -lh
-rw-r--r--.1 root root 286 11月 26 17:16 access_log
-rw-r--r-- l root root 383 11月 26 18:02 access.log_2020-11-26
-rw-r--r--.1 root root 288 11月 26 18:16 error_log
-rw-r--r-- l root root 286 11月 26 17:00 error.log_2020-11-26
-rw-r--r-- l root root 5 11月 26 18:00 httpd.pid
AWstats日志分析
- 不同于日志分割,是对整个日志进行分析
[aaa@qq.com ~]# vi /etc/httpd.conf
[aaa@qq.com ~]# systemctl start httpd
[aaa@qq.com ~]# httpd -t
[aaa@qq.com ~]# systemctl status httpd
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
配置文件
修改配置
[aaa@qq.com modules]# vi /etc/httpd.conf
[aaa@qq.com modules]# cd
LoadModule cgid_module modules/mod_cgid.so
LoadModule cgi_module modules/mod_cgi.so
解压安装包
[aaa@qq.com ~]# tar zxvf awstats-7.6.tar.gz
配置映射
[aaa@qq.com ~]# mv awstats-7.6 /usr/local/awstats
[aaa@qq.com ~]# vi /etc/hosts 映射记录
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.10 www.aaa.com l
[aaa@qq.com ~]# vi /etc/httpd.conf
ServerName www.aaa.com:80
[aaa@qq.com ~]# cd /usr/local/
[aaa@qq.com local]# ls -lh
[aaa@qq.com local]# chown -R root.root awstats/
[aaa@qq.com local]# cd awstats/
[aaa@qq.com awstats]# ls -lh
[aaa@qq.comrver1 awstats]# cd tools/ //进入工具目录
[aaa@qq.com tools]# ./awstats_configure.pl //找到配置脚本
对AWstats文件进行配置
[aaa@qq.com tools]# vi /etc/awstats/awstats.www.aaa.com.conf
LogFile="/usr/local/httpd/logs/access_log"
DirData="/var/lib/awstats"
[aaa@qq.com tools]# cd
[aaa@qq.com ~]# cd /var/lib/awstats
[aaa@qq.com ~]# mkdir /var/lib/awstats
删除多余文件进行配置
[aaa@qq.com ~]# cd /usr/local/httpd/logs/
[aaa@qq.com logs]# ls -lh
[aaa@qq.com logs]# rm -rf access.log*
[aaa@qq.com logs]# rm -rf error.log*
[aaa@qq.com ~]# cd /usr/local/awstats/tools/
[aaa@qq.com tools]# ls -lh
日志更新
[aaa@qq.com tools]# ./awstats_updateall.pl now
[aaa@qq.com ~]# vi /etc/httpd.conf
[aaa@qq.com ~]# systemctl stop httpd
[aaa@qq.com ~]# systemctl start httpd
//添加
Require all granted
[aaa@qq.com tools]# vi /etc/httpd.conf
编辑awstats的配置文件
[aaa@qq.com tools]# vi /etc/awstats/awstats.www.aa.com.conf
[aaa@qq.com tools]# systemctl start httpd
LogFile="/usr/local/httpd/logs/access_log"
重启主机,查看日志
[aaa@qq.com ~]# cd /usr/local/httpd/logs/
[aaa@qq.com logs]# ls -lh
手动采集日志
[aaa@qq.com logs]# cd
[aaa@qq.com ~]# cd /usr/local/awstats/tools/
[aaa@qq.com tools]# ./awstats_updateall.pl now
[aaa@qq.com ~]# mkdir /var/lib/awstats
[aaa@qq.com awstats]# systemctl stop httpd
[aaa@qq.com awstats]# systemctl start httpd
[aaa@qq.com tools]# ./awstats_updateall.pl now
上一篇: Apache网页优化之压缩
下一篇: linux环境配置nginx环境
推荐阅读
-
apache使用日志分割模块rotatelogs分割日志详解
-
Linux下apache日志分析与状态查看方法
-
使用apache的rotatelogs命令实现WebLogic启动命令的nohup的日志回滚
-
Apache访问日志的配置与使用
-
tomcat下使用cronolog对catalina.out日志文件分割
-
apache使用日志分割模块rotatelogs分割日志详解
-
rotatelogs、cronolog分割日志和awstats日志分析系统
-
centos 7.6——Apache日志分割(rotatelogs 分割工具、cronolog分割工具)
-
Apache日志分割(rotatelogs与cronolog)
-
企业平台架构--Apache配置与应用(Apache的访问控制(KeepAlive),日志分割(rotatelogs和cronolog)实操,日志分析(AWStats)实操