Apache日志分割

Apache日志分割

随着网站的访问量增大,默认状况下Apache的单个日志文件也会愈来愈大

(1)日志文件占用磁盘空间愈来愈大
(2)查看相关信息不方便php

对日志文件进行分割

(1)Apache自带的rotatelogs分割工具实现
(2)第三方工具cronolog分割mysql

rotatelogs分割工具

配置网站的日志文件转交给rotatelogs分割处理

配置格式为:sql

ErrorLog "| rotatelogs命令的绝对工具 -| 日志文件路径/网站名-error_%Y%m%d.log 86400"
CustomLog "| rotatelogs命令路径 -| 日志文件路径/网站名-access_%Y%m%d.log 86400" combined

在安装后Apache服务后再/usr/sbin/目录下能够查看到自带的rotatelogs工具
在这里插入图片描述
查看日志,发现安装Apache服务后没有日志
在这里插入图片描述
进入Apache配置文件配置域名和IP地址vim

[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf

在这里插入图片描述
在这里插入图片描述
关闭防火墙,开启Apache服务windows

[root@localhost httpd]# systemctl stop firewalld.service 
[root@localhost httpd]# setenforce 0
[root@localhost httpd]# systemctl start httpd

查看日志,服务开启后,日志文件自动建立ide

[root@localhost httpd]# ls /var/log/httpd/
access_log  error_log

在windows10 上访问192.168.45.135
在这里插入图片描述
在虚拟机上查看日志文件,能够看到来自刚才windows 10的访问
在这里插入图片描述工具

进行日志分割

进入Apache配置文件修改网站

[root@localhost httpd]# cd /etc/httpd/
[root@localhost httpd]# ls
conf  conf.d  conf.modules.d  logs  modules  run
[root@localhost httpd]# cd conf
[root@localhost conf]# vim httpd.conf

在这里插入图片描述
在这里插入图片描述
先guanbi服务,而后重启服务,查看日志文件rest

[root@localhost conf]# systemctl stop httpd
[root@localhost conf]# systemctl start httpd
[root@localhost conf]# cd /var/log/httpd/
[root@localhost httpd]# ls
access_log  error_log  www.kgc.com.error_20191025log
[root@localhost httpd]#

第三方工具cronolog

源码编译安装cronolog工具

配置网站日志文件转交给cronolog分割处理

配置格式为:日志

ErrorLog "| cronolog命令的绝对工具 -| 日志文件路径/网站名-error_%Y%m%d.log "
CustomLog "| cronolog命令路径 -| 日志文件路径/网站名-access_%Y%m%d.log " combined

cronolog工具的使用

在刚才的基础上恢复镜像,而后重启虚拟机,安装httpd服务

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

远程挂载主机共享的文件,安装cronolog软件

[root@localhost ~]# mkdir /abc                   //建立挂载点
[root@localhost ~]# mount.cifs //192.168.100.3/LAMP-C7 /abc/                        //远程挂载主机共享的文件
Password for root@//192.168.100.3/LAMP-C7:  
[root@localhost ~]# cd /abc/
[root@localhost abc]# ls
apr-1.6.2.tar.gz       cronolog-1.6.2-14.el7.x86_64.rpm  LAMP-php5.6.txt
apr-util-1.6.0.tar.gz  Discuz_X2.5_SC_UTF8.zip           mysql-5.6.26.tar.gz
awstats-7.6.tar.gz     httpd-2.4.29.tar.bz2              php-5.6.11.tar.bz2
[root@localhost abc]# rpm -ivh cronolog-1.6.2-14.el7.x86_64.rpm                             
警告:cronolog-1.6.2-14.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:cronolog-1.6.2-14.el7            ################################# [100%]
[root@localhost abc]#

查看cronolog文件位置

[root@localhost abc]# cd /usr/bin/
[root@localhost bin]# ls cronolog*
ls: 没法访问cronolog*: 没有那个文件或目录
[root@localhost bin]# cd /usr/sbin/
[root@localhost sbin]# ls cronolog*
cronolog
[root@localhost sbin]#

修改配置文件、在配置文件中进行下列修改

[root@localhost sbin]# vim /etc/httpd/conf/httpd.conf

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
重启httpd服务,查看建立好的日志文件

[root@localhost sbin]# systemctl restart httpd
[root@localhost sbin]# ls /var/log/httpd/
www.kgc.com.error_20191025.log
[root@localhost sbin]#
相关文章
相关标签/搜索