赞
踩
du -sh *
31M syslog # syslog日志
61M syslog.1
2.5G journal/ # systemd service日志
最终使用方案3, logrotate 管理日志大小,备份,清理, 符合项目开发与运行需求.
安装前置依赖 sudo apt install cron rsyslog
安装 sudo apt instlal logrotate
教程 https://www.cnblogs.com/carsonzhu/p/16904219.html
ls /etc/logrotate.d
alternatives apt aptitude btmp dpkg pm-utils rsyslog wtmp
cat /etc/logrotate.d/rsyslog
/var/log/syslog { rotate 7 daily missingok notifempty delaycompress compress postrotate /usr/lib/rsyslog/rsyslog-rotate endscript } /var/log/mail.info /var/log/mail.warn /var/log/mail.err /var/log/mail.log /var/log/daemon.log /var/log/kern.log /var/log/auth.log /var/log/user.log /var/log/lpr.log /var/log/cron.log /var/log/debug /var/log/messages { rotate 4 weekly missingok notifempty compress delaycompress sharedscripts postrotate /usr/lib/rsyslog/rsyslog-rotate endscript }
配置脚本
vim /etc/logrotate.d/liuj_tmp_log
/tmp/liuj/*.log {
size=50K
daily
rotate 5
compress
missingok
notifempty
create 664 liuj liuj
}
生成日志
cd /tmp/liuj; dd if=/dev/zero of=xxx.log bs=1M count=1
du -sh *
1.0M xxx.log
或用脚本生成日志.
手动整理日志
logrotate -vf /etc/logrotate.d/liuj_tmp_log
查看整理之后的结果 du -sh *
0 xxx.log
4.0K xxx.log.1.gz -->整理之后的文件大小
vim /etc/logrotate.d/rsyslog
/var/log/syslog
{
rotate 7
daily
++ size=50M
missingok
notifempty
delaycompress
compress
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
设置系统 ros 日志位置
/etc/profile.d/ros_env.sh
source /opt/ros/noetic/setup.bash
export ROS_LOG_DIR=/userdata/workdir/ros_log
查看环境变量是否生效
echo $ROS_LOG_DIR
/userdata/workdir/ros_log
限制 ros 程序日志规则
vim /etc/logrotate.d/ros_log
/userdata/workdir/ros_log/*.log
{
rotate 5
daily
size=20M
missingok
notifempty
delaycompress
compress
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
ls /var/log/journal/6d021ad1f019488facfc7e6e7ec8236f
system.journal
system@faa337787dbc4bd49fdcaa0ceea09a96-00000000000871b0-0006123fac856242.journal
system@583db54cb7cb466c9a3c7678bc0766f2-0000000000012a2c-00060f97925e7c17.journal
user-1000.journal
user-1000@b4fe8171a42f4f60a0a05c69bcfe1a5d-000000000009617d-0006124487b7d8a8.journal
user-1000@3ecd5eb819b04efb9e9bba24908511e4-0000000000083c8a-0006109ff49ba016.journal
目前使用的方案是:
/lib/systemd/system/logrotate.service
/lib/systemd/system/logrotate.timer
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。