vieyahn2017 / iBlog

44 stars 0 forks source link

6.19 日志切割之Logrotate #357

Closed vieyahn2017 closed 3 months ago

vieyahn2017 commented 3 years ago

日志切割之Logrotate https://www.cnblogs.com/clsn/p/8428257.html

vieyahn2017 commented 3 years ago

/etc/logrotate.conf # 主配置文件 /etc/logrotate.d # 配置目录

vieyahn2017 commented 3 years ago

/etc/logrotate.conf # 主配置文件

# 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
dateformat -%Y%m%d-%s

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# system-specific logs may be also be configured here.
vieyahn2017 commented 3 years ago

redis_logrtate.sh

#!/bin/bash
# script redis_logrotate
# Copyright © Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.

set -e

redis_path="/opt/redis"
redis_soft_log_path="${redis_path}/packages/log"

(cat <<EOF

{
    copytruncate
    size 10M
    rotate 5
    missingok
    compress
    notifempty
}

EOF
) >  /etc/logrotate.d/redisLog

chmod 600 /etc/logrotate.d/redisLog

sed -i "1i${redis_soft_log_path}/redis-sentinel-login.log" /etc/logrotate.d/redisLog
sed -i "1i${redis_soft_log_path}/redis-login.log" /etc/logrotate.d/redisLog
sed -i "1i${redis_soft_log_path}/redis-sentinel.log" /etc/logrotate.d/redisLog
sed -i "1i${redis_soft_log_path}/redis.log" /etc/logrotate.d/redisLog
vieyahn2017 commented 3 years ago

/etc/logrotate.d/redisLog


/opt/redis/packages/log/redis.log
/opt/redis/packages/log/redis-sentinel.log
/opt/redis/packages/log/redis-login.log
/opt/redis/packages/log/redis-sentinel-login.log

{
    copytruncate
    size 10M
    rotate 5
    missingok
    compress
    notifempty
}