我在 TI-J7 嵌入式板上运行 Linux。它使用 busybox 的 syslogd。但我面临的 syslog 问题是,当日志文件大小超过 200kb 时,它会覆盖日志文件,因此无法收集更多日志。 (当达到 200k 时,日志文件将被截断,并且 syslog 的新日志将写入同一文件)
我确信它没有被 logrotate 轮换,因为我还没有配置 logrotate 并且 /etc/logrotate.conf 中没有基于大小的轮换配置
以下是/etc/syslog.conf
# /etc/syslog.conf Configuration file for busybox's syslogd utility
以下是/etc/syslog-startup.conf
# /etc/init.d/syslog[.busybox] to set syslog configuration at start time.
DESTINATION=file # log destinations (buffer file remote)
#LOGFILE=/var/log/messages # where to log (file)
LOGFILE=/opt/vision_apps/log.log # where to log (file)
REMOTE=loghost:514 # where to log (syslog remote)
REDUCE=no # reduce-size logging
DROPDUPLICATES=no # whether to drop duplicate log entries
#ROTATESIZE=0 # rotate log if grown beyond X [kByte]
#ROTATEGENS=3 # keep X generations of rotated logs
BUFFERSIZE=64 # size of circular buffer [kByte]
FOREGROUND=no # run in foreground (don't use!)
#LOGLEVEL=5 # local log level (between 1 and 8)
以下是/etc/init.d/syslog
#! /bin/sh
### BEGIN INIT INFO
# Provides: sysklogd
# Required-Start: $remote_fs $time
# Required-Stop: $remote_fs $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: System logger
### END INIT INFO
set -e
if [ -f /etc/syslog-startup.conf ]; then
. /etc/syslog-startup.conf
LOG_LOCAL=0
LOG_REMOTE=0
for D in $DESTINATION; do
if [ "$D" = "buffer" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -C$BUFFERSIZE"
LOG_LOCAL=1
elif [ "$D" = "file" ]; then
if [ -n "$LOGFILE" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -O $LOGFILE"
fi
if [ -n "$ROTATESIZE" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -s $ROTATESIZE"
fi
if [ -n "$ROTATEGENS" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -b $ROTATEGENS"
fi
LOG_LOCAL=1
elif [ "$D" = "remote" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -R $REMOTE"
LOG_REMOTE=1
fi
done
if [ "$LOG_LOCAL" = "1" -a "$LOG_REMOTE" = "1" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -L"
fi
if [ "$REDUCE" = "yes" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -S"
fi
if [ "$DROPDUPLICATES" = "yes" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -D"
fi
if [ -n "$LOGLEVEL" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -l $LOGLEVEL"
fi
else
# default: log to 16K shm circular buffer
SYSLOG_ARGS="-C"
fi
waitpid ()
{
pid=$1
# Give pid a chance to exit before we restart with a 5s timeout in 1s intervals
if [ -z "$pid" ]; then
return
fi
timeout=5;
while [ $timeout -gt 0 ]
do
timeout=$(( $timeout-1 ))
kill -0 $pid 2> /dev/null || break
sleep 1
done
}
case "$1" in
start)
echo -n "Starting syslogd/klogd: "
start-stop-daemon -S -b -n syslogd -a /sbin/syslogd -- -n $SYSLOG_ARGS
start-stop-daemon -S -b -n klogd -a /sbin/klogd -- -n
echo "done"
;;
stop)
echo -n "Stopping syslogd/klogd: "
start-stop-daemon -K -n syslogd
start-stop-daemon -K -n klogd
echo "done"
;;
restart)
pid1=`pidof syslogd`
pid2=`pidof klogd`
$0 stop
waitpid $pid1
waitpid $pid2
$0 start
;;
*)
echo "Usage: syslog { start | stop | restart }" >&2
exit 1
;;
esac
exit 0
答案1
由于您是/etc/syslog-startup.conf
在 syslog 启动文件中获取该文件:/etc/init.d/syslog
但在其中您传递了两个参数ROTATESIZE
,并且ROTATEGENS
当这些参数未设置为:
if [ -n "$ROTATESIZE" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -s $ROTATESIZE"
fi
if [ -n "$ROTATEGENS" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -b $ROTATEGENS"
这意味着当系统日志启动时,空值将传递到这些参数中。
你需要做的是在未设置时设置一个固定值,如下所示(当 200K 和 4 个旋转文件时旋转):
if [ -n "$ROTATESIZE" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -s 200"
fi
if [ -n "$ROTATEGENS" ]; then
SYSLOG_ARGS="$SYSLOG_ARGS -b 4"
...或将所有更改[ -n $variable ]
为[ ! -n $variable ]
AND 注释掉中的这些参数(以及其他参数)ROTATESIZE
,然后当它为非空值时,它将从启动配置文件中读取并设置这些值。ROTATEGENS
/etc/syslog-startup.conf