最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】继续折腾WordPress网站的日志覆盖问题

WordPress crifan 1731浏览 0评论

之前已经弄过了:

【基本解决】CentOS7中空间占用异常

https://www.crifan.com/centos_7_disk_space_usage_abnormal

但是没有真正解决问题

导致每过一段时间,都要去手动删除对应的,很多GB的日志文件

cd /var/www/crifan.com/logs/

rm access.log error.log

所以很是麻烦。

想要去彻底解决此问题。

让网站的日志可以自动覆盖。

php log file too large

crifan@crifan:~$ ls /var/log/php/ -latotal 8drwxr-xr-x  2 apache root 4096 Sep 12  2015 .drwxr-xr-x 11 root   root 4096 May 22 03:45 ..
crifan@crifan:~$ ls /var/www/crifan.com/logs/  -lahtotal 3.8Gdrwxrwxrwx 2 root root 4.0K May  9 22:54 .drwxrwxrwx 4 root root 4.0K May 21  2015 ..-rw-r–r– 1 root root 3.8G May 28 11:02 access.log-rw-r–r– 1 root root 9.2M May 28 10:29 error.log

/var/www logs/access.log too large

How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS | DigitalOcean

logging – Apache’s access.log files taking up too much space – Server Fault

HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples

apache – access_log is huge, not being archived. how to reset it? – Stack Overflow

Log File paths

此处去看了看,log的配置,不是:

crifan@crifan:~$ cat /etc/httpd/conf/httpd.conf

而是:

crifan@crifan:~$ cat /etc/httpd/conf.d/vhost.conf

中的:

<VirtualHost *:80>
    ErrorLog /var/www/crifan.com/logs/error.log    CustomLog /var/www/crifan.com/logs/access.log combined

vhost.conf CustomLog

vhost.conf CustomLog logrotate

ExampleVhosts – Httpd Wiki

Log Files – Apache HTTP Server Version 2.4

去看了看此处的:

rotatelogs

此处是在:/usr/sbin/rotatelogs

crifan@crifan:~$ ls /usr/local/bin  cpanel  etc  games  include  lib  lib64  libexec  sbin  share  srccrifan@crifan:~$ ls /usr/local/bin/crifan@crifan:~$ which rotatelogs/usr/sbin/rotatelogs

然后看了看语法:

crifan@crifan:~$ /usr/sbin/rotatelogs  –helpIncorrect number of argumentsUsage: /usr/sbin/rotatelogs [-v] [-l] [-L linkname] [-p prog] [-f] [-t] [-e] [-c] [-n number] <logfile> {<rotation time in seconds>|<rotation size>(B|K|M|G)} [offset minutes from UTC]
Add this:
TransferLog "|/usr/sbin/rotatelogs /some/where 86400"
or
TransferLog "|/usr/sbin/rotatelogs /some/where 5M"
to httpd.conf. By default, the generated name will be<logfile>.nnnn where nnnn is the system time at which the lognominally starts (N.B. if using a rotation time, the time willalways be a multiple of the rotation time, so you can synchronizecron scripts with it). If <logfile> contains strftime conversionspecifications, those will be used instead. At the end of eachrotation time or when the file size is reached a new log isstarted.
Options:  -v       Verbose operation. Messages are written to stderr.  -l       Base rotation on local time instead of UTC.  -L path  Create hard link from current log to specified path.  -p prog  Run specified program after opening a new log file. See below.  -f       Force opening of log on program start.  -t       Truncate logfile instead of rotating, tail friendly.  -e       Echo log to stdout for further processing.  -c       Create log even if it is empty.
The program is invoked as "[prog] <curfile> [<prevfile>]"where <curfile> is the filename of the newly opened logfile, and<prevfile>, if given, is the filename of the previously used logfile.

rotatelogs – Piped logging program to rotate Apache logs – Apache HTTP Server Version 2.4

然后去改为:

    ErrorLog /var/www/crifan.com/logs/error.log    #CustomLog /var/www/crifan.com/logs/access.log combined    CustomLog "|/usr/sbin/rotatelogs /var/www/crifan.com/logs/access_log.%Y%m%d_%H%M%S 604800" common

其中

604800=604800 秒=60*60*24*7秒=7天

再去重启服务器

看看是否生成对应的log

好像是生效了,生成对应的带时间的log文件了:

crifan@crifan:logs$ pwd/var/www/crifan.com/logscrifan@crifan:logs$ ls -haltotal 9.3Mdrwxrwxrwx 2 root root 4.0K May 28 11:54 .drwxrwxrwx 4 root root 4.0K May 21  2015 ..-rw-r–r– 1 root root  78K May 28 11:55 access_log.20160526_000000-rw-r–r– 1 root root 9.2M May 28 11:45 error.log

然后就是,等再过1周后,再去看,是否rotate,重新生成新的log文件吧

【后记 2016-06-05】

后来再去看log:

crifan@crifan:~$ cd /var/www/crifan.com/logs
crifan@crifan:logs$ ls -lha
total 704M
drwxrwxrwx 2 root root 4.0K Jun  2 08:00 .
drwxrwxrwx 4 root root 4.0K May 21  2015 ..
-rw-r–r– 1 root root 410M Jun  2 07:59 access_log.20160526_000000
-rw-r–r– 1 root root 284M Jun  5 16:52 access_log.20160602_000000
-rw-r–r– 1 root root 9.7M Jun  5 16:48 error.log

果然:

对应的,是一周后,就rotate,重新生成的log文件了。

-》但是是:

一周之前的log文件,不是删除掉了,而是保留了。

然后新建了对应的log文件了

-》这样过段时间后,log文件还是会很多,很大的

-》我要的是

重新删除掉,冲掉旧的

-》所以还是要抽空去设置为truncate,而不是保留旧log

后来发现还是log文件内容太多太大,

导致无法登录wordpress后台

去删除后:

➜  ~ cd /var/www/crifan.com/logs
➜  logs ll -h
total 11G
-rw-r–r– 1 root root 544M Jun 16 07:59 access_log.20160609_000000
-rw-r–r– 1 root root 572M Jun 23 07:59 access_log.20160616_000000
-rw-r–r– 1 root root 574M Jun 30 07:59 access_log.20160623_000000
-rw-r–r– 1 root root 583M Jul  7 07:59 access_log.20160630_000000
-rw-r–r– 1 root root 609M Jul 14 07:59 access_log.20160707_000000
-rw-r–r– 1 root root 618M Jul 21 07:59 access_log.20160714_000000
-rw-r–r– 1 root root 633M Jul 28 07:59 access_log.20160721_000000
-rw-r–r– 1 root root 583M Aug  4 07:59 access_log.20160728_000000
-rw-r–r– 1 root root 575M Aug 11 07:59 access_log.20160804_000000
-rw-r–r– 1 root root 570M Aug 18 07:59 access_log.20160811_000000
-rw-r–r– 1 root root 583M Aug 25 07:59 access_log.20160818_000000
-rw-r–r– 1 root root 571M Sep  1 07:59 access_log.20160825_000000
-rw-r–r– 1 root root 587M Sep  8 07:59 access_log.20160901_000000
-rw-r–r– 1 root root 604M Sep 15 07:59 access_log.20160908_000000
-rw-r–r– 1 root root 558M Sep 22 07:59 access_log.20160915_000000
-rw-r–r– 1 root root 634M Sep 29 07:59 access_log.20160922_000000
-rw-r–r– 1 root root 453M Oct  6 07:59 access_log.20160929_000000
-rw-r–r– 1 root root 603M Oct 13 07:59 access_log.20161006_000000
-rw-r–r– 1 root root  83M Oct 13 20:42 access_log.20161013_000000
-rw-r–r– 1 root root  17M Oct 13 20:42 error.log
➜  logs rm access_log.2016* -f
➜  logs ll
total 17M
-rw-r–r– 1 root root 17M Oct 13 20:42 error.log

才能正常登录后台。

【2017-01-15】

再去及时删除log:

➜  ~ cd /var/www/crifan.com/logs
➜  logs ll
total 5.3G
-rw-r–r– 1 root root 603M Dec  8 07:59 access_log.20161201_000000
-rw-r–r– 1 root root 460M Dec 15 07:59 access_log.20161208_000000
-rw-r–r– 1 root root 489M Dec 22 07:59 access_log.20161215_000000
-rw-r–r– 1 root root 501M Dec 29 07:59 access_log.20161222_000000
-rw-r–r– 1 root root 447M Jan  5 07:59 access_log.20161229_000000
-rw-r–r– 1 root root 513M Jan 12 07:59 access_log.20170105_000000
-rw-r–r– 1 root root 491M Jan 19 07:59 access_log.20170112_000000
-rw-r–r– 1 root root 392M Jan 25 11:32 access_log.20170119_000000
-rw-r–r– 1 root root 1.5G Jan 25 11:32 error.log
➜  logs rm access_log.201*
rm: remove write-protected regular file ‘access_log.20161201_000000’? y
rm: remove write-protected regular file ‘access_log.20161208_000000’? ^C
➜  logs rm -f access_log.201*
➜  logs ll
total 1.5G
-rw-r–r– 1 root root 1.5G Jan 25 11:33 error.log
➜  logs rm error.log
rm: remove write-protected regular file ‘error.log’? y
➜  logs ll
total 0

转载请注明:在路上 » 【记录】继续折腾WordPress网站的日志覆盖问题

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.178 seconds, using 22.14MB memory