logrotate的配置
今天登录到服务器上进行检查,发现一个问题那就是nginx日志的大小,我通过du -sh查看到nginx日志已经达到几百M了,这个怎么得行呢,再这样下去肯定要出问题。
我发现这个问题我第一个想到的是日志自动切换功能,下面就来说说日志切换功能的设置吧
cat /etc/logrotate.conf #logrotate全局配置文件
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
# system-specific logs may be also be configured here.
前面的信息都可以不管的看下面我对nginx的配置
cat /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
dateext
minsize 3M
rotate 5
create
postrotate
/bin/kill -USR1 `cat /usr/local/nginx/logs/nginx.pid` > /dev/null 2>/dev/null || true
endscript
}
操作的时候可能会出现下面红色的部分,不用担心不是错误
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/backup/postgres/postgres_db_dump_20091019.gz.1.1.1.1.1.1.1.1.1.1-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021 to /var/backup/postgres/postgres_db_dump_20091019.gz.1.1.1.1.1.1.1.1.1.1-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021
rotating log /var/backup/postgres/postgres_db_dump_20091020.gz.1.1.1.1.1.1.1.1.1-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021, log->rotateCount is 4
dateext suffix '-20091021'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/backup/postgres/postgres_db_dump_20091020.gz.1.1.1.1.1.1.1.1.1-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021 to /var/backup/postgres/postgres_db_dump_20091020.gz.1.1.1.1.1.1.1.1.1-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021
rotating log /var/backup/postgres/postgres_db_dump_20091021.gz.1.1.1.1.1.1.1.1.1-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021-20091021, log->rotateCount is 4
dateext suffix '-20091021'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /var/backup/postgres/postgres_db_dump_20091021.gz.1.1.1.1.1.1.1.1.1-200910
转载于:https://my.oschina.net/yyping/blog/103760