logrotate 程序控制日志文件大小
#在linux环境下 /etc/目录 分别有:
logrotate.conf文件 = 用于全局配置日志
logrotate.d目录 = 用于局部控制日志
#日志控制命令如下:
weekly = 表示默认情况下,该命令每周执行一次。
missingok = 日志文件不存在的时候不会报错(如果有多个配置,会继续执行)
rotate 3 = 总共保留 3 份备份文件
copytruncate = 使用先拷贝文件再 truncate 原文件的方法来轮转,这种方法无需停应用,也不会有数据丢失
size 200M = 只有文件大于 200M 时才轮转
daily = 按天执行
dateext = 轮转后的日志备份加上日期后缀
#配置方式
1,全局配置 = 在logrotate.conf文件中添加日志控制命令即可
2,局部配置 = 在/etc/logrotate.d 目录下新建一个文件(不需要加后缀),配置内容如下:
/xxx/xxx/<日志文件名>.<后缀名> {
#日志控制命令
copytruncate
daily
dateext
rotate 3
compress
missingok
size 100M
}
cronolog
yum安装
yum install -y cronolog httpd
which cronolog
/usr/sbin/cronolog
cronolog 使用
cronolog -h
usage: cronolog [OPTIONS] logfile-spec-H NAME, --hardlink=NAME maintain a hard link from NAME to current log
-S NAME, --symlink=NAME maintain a symbolic link from NAME to current log
-P NAME, --prev-symlink=NAME maintain a symbolic link from NAME to previous log
-l NAME, --link=NAME same as -S/--symlink
-h, --help print this help, then exit
-p PERIOD, --period=PERIOD set the rotation period explicitly
-d DELAY, --delay=DELAY set the rotation period delay
-o, --once-only create single output log from template (not rotated)
-x FILE, --debug=FILE write debug messages to FILE
( or to standard error if FILE is "-")
-a, --american American date formats
-e, --european European date formats (default)
-s, --start-time=TIME starting time
-z TZ, --time-zone=TZ use TZ for timezone
-V, --version print version number, then exit