**随着网站的访问量增长,默认状况Apache单个日志文件也会愈来愈大** * 日志文件占用磁盘空间很大 * 查看相关信息不方便 **对日志文件进行分割** * Apache自带rotatelogs分割工具实现 * 第三方工具cronolog分割
配置网站的日志文件转交给rotatelogs分割处理
一台Linux服务器(192.168.13.128) 一台win7测试主机
[root@localhost ~]# yum install httpd -y [root@localhost ~]# cd /usr/sbin ##切换到/usr/sbin目录下 [root@localhost sbin]# ls rotat* ##日志分析工具位置 rotatelogs [root@localhost sbin]# vim /etc/httpd/conf/httpd.conf ##修改配置文件 Listen 192.168.13.128:80 ##修改ipv4监听端口 #Listen 80 ##将ipv6端口注释 ServerName www.kgc.com:80 ##修改域名 [root@localhost named]# systemctl stop firewalld.service ##关闭防火墙 [root@localhost named]# setenforce 0 ##关闭加强功能 [root@localhost html]# systemctl start httpd.service ##启动网络服务 [root@localhost sbin]# ls /var/log/httpd/ ##此时就有了日志文件了 accesslog errorlog
[root@localhost sbin]# cd /etc/httpd/conf
[root@localhost conf]# vim httpd.conf ##配置http主配置文件
#ErrorLog "logs/errorlog"
ErrorLog "| /usr/sbin/rotatelogs -l logs/www.kgc.com.error%Y%m%dlog 86400"
##此处添加工具绝对路径,生成日志的时间php
CustomLog "| /usr/sbin/rotatelogs -l logs/www.kgc.com.access_%Y%m%dlog 86400" combined
##此处添加工具绝对路径,生成日志的时间html
[root@localhost conf]# systemctl stop httpd.service ##关闭http服务 [root@localhost conf]# systemctl start httpd ##启动http服务 [root@localhost conf]# cd /var/log/httpd/ ##切换到日志目录下查看 [root@localhost httpd]# ls access_log error_log www.kgc.com.error_20191025log ##即为今日的分割日志文件 [root@localhost httpd]# date 2019年 10月 25日 星期五 09:12:31 CST [root@localhost httpd]# date -s 10/26/19 ##修改时间为明天 2019年 10月 26日 星期六 00:00:00 CST [root@localhost httpd]# systemctl stop httpd ##关闭重启服务 [root@localhost httpd]# systemctl start httpd [root@localhost httpd]# ls ##查看日志分割的状况 access_log www.kgc.com.error_20191025log error_log www.kgc.com.error_20191026log
源码编译安装cronolog工具 配置网站日志文件转交给cronolog分割处理
[root@localhost ~]# yum install httpd -y [root@localhost ~]# smbclient -L //192.168.10.88/ Sharename Type Comment --------- ---- ------- LAMP-C7 Disk [root@localhost ~]# mount.cifs //192.168.10.88/LAMP-C7 /mnt ##远程挂载软件包到/mnt目录 [root@localhost ~]# cd /mnt/ ##切换到/mnt目录下 [root@localhost mnt]# 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 mnt]# rpm -ivh cronolog-1.6.2-14.el7.x86_64.rpm ##安装工具
[root@localhost mnt]# cd /usr/sbin [root@localhost sbin]# ls cronolog* cronolog [root@localhost sbin]# vim /etc/httpd/conf/httpd.conf Listen 192.168.13.128:80 ##修改监听的地址 #Listen 80 ServerName www.kgc.com:80 ##修改域名 ErrorLog "| /usr/sbin/cronolog logs/www.kgc.com.error_%Y%m%d.log" CustomLog "| /usr/sbin/cronolog logs/www.kgc.com.access_%Y%m%d.log" combined ##修改日志文件
[root@localhost sbin]# systemctl restart httpd ##重启http服务 [root@localhost sbin]# ls /var/log/httpd ##查看日志文件 www.kgc.com.error_20191025.log