使用 logadm 命令
限制 /var/adm/wtmpx 大小的最合适方法是使用 logadm 。
例如,要将日志文件的大小限制为 300MB 并在大于 300MB 时轮换日志文件:
# logadm -C 4 -c -s 300m -w /var/adm/wtmpx
其中:
-C count Delete the oldest versions until there are not more than count files left. -p period Rotate a log file after the specified time period (period) . -c Rotate the log file by copying it and truncating the oroirnal logfile to zero length, rather than renaming the file. -w entryname Write an entry into the config file (that is, /etc/logadm.conf) -s size Rotate the log file only if its size is greater than or equal to size. -z count Compress old log files after all other commands have been executed.
由于使用了 -w 选项,我们还会在 /etc/logadm.conf 文件中获得如下条目:
# tail -1 /etc/logadm.conf wtmpx -C 4 -c -s 300m /var/adm/wtmpx
要运行我们刚刚使用 logadm 创建的规则,请使用 -v 选项,该选项将以详细模式打印输出。
# logadm -v --lines omitted- # processing logname: /var/adm/wtmpx # using default template: $file.$n mkdir -p /var/adm # verify directory exists # cp -fp /var/adm/wtmpx /var/adm/wtmpx.0 # rotate log file via copy (-c flag) # cp -f /dev/null /var/adm/wtmpx # trucate log file (-c flag) touch /var/adm/wtmpx chown 4:4 /var/adm/wtmpx chmod 644 /var/adm/wtmpx # recording rotation date Tue Nov 25 13:51:14 2014 for /var/adm/wtmpx # writing changes to /var/logadm.conf
验证结果:
# ls -l /var/adm/wtmpx* -rw-r--r-- 1 adm adm 0 Dec 25 13:51 /var/adm/wtmpx -rw-r--r-- 1 adm adm 362328000 Dec 25 12:54 /var/adm/wtmpx.0
欢迎来到之路教程(on itroad-com)
将文件清零
转换 wtmpx 文件的另一种最简单的方法是将其清空:
# > /var/adm/wtmpx
Solaris wtmpx文件很大,是否可以清除?
如何清理Solaris wtmpx文件?
如何清除wtmpx文件,只保留最近一段时间的记录?
如果登录系统时,很慢。可能的原因是,wtmpx 文件在增长,填满 /var 分区(通常是根分区的一部分)。
在极端情况下,它甚至可能阻止登录的可能性,因为无法进行 utmpx 条目,并且 login 要求用户从最低级别的 shell 执行登录。
在这种情况下,/var/adm/wtmpx 需要被截断而不引起问题。
日期:2020-09-17 00:15:26 来源:oir作者:oir