LINUX过滤系统无用日志

概述

在日常运维中发现,系统日志里记录了大量的无用信息,使查看日志非常麻烦,可以设置一些过滤条件,使这些无用的日志不再出现在日志当中

问题描述

在/var/log/messages中,出现大量无用信息,如下:

Sep 14 14:20:01 timescale systemd: Started Session 38043 of user root.
Sep 14 14:20:01 timescale systemd: Starting Session 38043 of user root.
Sep 14 14:30:01 timescale systemd: Started Session 38044 of user root.
Sep 14 14:30:01 timescale systemd: Starting Session 38044 of user root.
Sep 14 14:40:01 timescale systemd: Started Session 38045 of user root.
Sep 14 14:40:01 timescale systemd: Starting Session 38045 of user root.
Sep 14 14:50:01 timescale systemd: Started Session 38046 of user root.
Sep 14 14:50:01 timescale systemd: Starting Session 38046 of user root.
Sep 14 15:00:01 timescale systemd: Started Session 38047 of user root.
Sep 14 15:00:01 timescale systemd: Starting Session 38047 of user root.
Sep 14 15:01:01 timescale systemd: Started Session 38048 of user root.
Sep 14 15:01:01 timescale systemd: Starting Session 38048 of user root.
Sep 14 15:10:01 timescale systemd: Started Session 38049 of user root.
Sep 14 15:10:01 timescale systemd: Starting Session 38049 of user root.
Sep 14 15:20:01 timescale systemd: Started Session 38050 of user root.
Sep 14 15:20:01 timescale systemd: Starting Session 38050 of user root.
Sep 14 15:30:01 timescale systemd: Started Session 38051 of user root.
Sep 14 15:30:01 timescale systemd: Starting Session 38051 of user root.
Sep 14 15:38:12 timescale systemd: Started Session 38052 of user root.
Sep 14 15:38:12 timescale systemd: Starting Session 38052 of user root.
Sep 14 15:38:12 timescale systemd-logind: New session 38052 of user root.
Sep 14 15:40:01 timescale systemd: Started Session 38053 of user root.
Sep 14 15:40:01 timescale systemd: Starting Session 38053 of user root.
Sep 14 15:50:01 timescale systemd: Started Session 38054 of user root.
Sep 14 15:50:01 timescale systemd: Starting Session 38054 of user root.

操作步骤

将过滤的条件加入#Add Filter

echo 'if ($programname == "systemd-logind" or $programname == "systemd") and ($msg contains "Starting Session" or $msg contains "Started Session" or $msg contains "Removed session" or $msg contains "New session" or $msg contains "Created slice" or $msg contains "Starting user-") then stop' >/etc/rsyslog.d/ignore-systemd-session-slice.conf

重启日志服务#Restart Syslog

systemctl restart rsyslog
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值