/var/log/messages迅速增大的问题

本文详细记录了如何解决由SpringBoot项目导致的/var/log/messages日志文件迅速增长,占用大量磁盘空间的问题。通过调整rsyslog配置,成功避免了系统将SpringBoot日志误判为系统信息日志。

近期阿里云磁盘总在报警,使用df和du逐一排查,发现问题出在 /var/log/messages 每天都在迅速增加,而且此日志跟我springboot指定的日志完全一致。
解决步骤:
1、检查springboot的logback设置。
未找到将log写到 linux syslog的相关配置。
2、查看系统日志的配置。
打开 /etc/rsyslog.conf
找到关于 messages的配置信息:

*.info;mail.none;authpriv.none;cron.none /var/log/messages

将其直接改为

*.none /var/log/messages

保存后,重启 rsyslog

systemctl restart rsyslog

使用 tail -f /var/log/messages 查看日志实时的写入,发现已经停止,问题解决。
猜测可能是由于我的springboot项目是由systemctl启动的,系统可能把这部分日志当成系统的info。

[root@localhost work]# sudo find / -xdev -type f -size +100M -exec ls -lh {} \; -rw-r--r--. 1 root root 101M Feb 28 2025 /var/lib/rpm/Packages -rw-r--r--. 1 root root 156M Jun 22 2024 /var/cache/yum/x86_64/7/updates/gen/primary_db.sqlite -rw-r--r--. 1 root root 149M Jun 22 2024 /var/cache/yum/x86_64/7/updates/gen/filelists_db.sqlite -rw-r--r--. 1 root root 117M Jun 21 2024 /var/cache/yum/x86_64/7/updates/packages/firefox-115.12.0-1.el7.centos.x86_64.rpm -rw-r--r--. 1 root root 1.1G Oct 4 23:45 /tmp/spring.log.2025-10-04.128181976214538690.tmp -rw-r--r--. 1 root root 1.7G Oct 5 15:00 /tmp/spring.log.2025-10-04.228213919973839816.tmp -rw-r--r--. 1 root root 2.3G Oct 10 23:45 /tmp/spring.log.2025-10-10.028656801304903358.tmp -rw-r--r--. 1 root root 2.7G Oct 11 23:45 /tmp/spring.log.2025-10-10.228732319985996298.tmp -rw-r--r--. 1 root root 1.5G Oct 4 15:03 /tmp/spring.log.2025-10-04.028138434113501828.tmp -rw-r--r--. 1 root root 1.4G Oct 12 15:03 /tmp/spring.log.2025-10-12.028829562166827530.tmp -rw-r--r--. 1 root root 722M Oct 9 23:45 /tmp/spring.log.2025-10-09.028624370054257272.tmp -rw-r--r--. 1 root root 681M Oct 7 23:45 /tmp/spring.log.2025-10-07.228451583042218185.tmp -rw-r--r--. 1 root root 1.1G Oct 12 23:45 /tmp/spring.log.2025-10-12.128873138133991399.tmp -rw-r--r--. 1 root root 1.1G Oct 5 23:45 /tmp/spring.log.2025-10-05.028268051194354719.tmp -rw-r--r--. 1 root root 2.8G Oct 3 23:45 /tmp/spring.log.2025-10-03.028041361425305587.tmp -rw-r--r--. 1 root root 2.7G Oct 8 23:45 /tmp/spring.log.2025-10-07.328473120035804793.tmp -rw-r--r--. 1 root root 1.7G Oct 13 15:02 /tmp/spring.log.2025-10-12.228905120362616249.tmp -rw-r--r--. 1 root root 360M Oct 13 16:04 /tmp/spring.log.2025-10-13.028959350972534024.tmp -rw-r--r--. 1 root root 739M Oct 13 23:45 /tmp/spring.log.2025-10-13.128970115527045867.tmp -rw-r--r--. 1 root root 674M Oct 14 06:53 /tmp/spring.log.2025-10-14.029002515536531512.tmp -rw-r--r--. 1 root root 102M Nov 12 2024 /usr/lib/locale/locale-archive -rw-r--r--. 1 root root 208M Sep 23 10:25 /opt/nubosh/vmsec-host/pat/av/qowl.tgz 执行结果
10-15
配置中删去source(s_system);source(s_kernel);后没有coredumproot@prplOS:/etc# cat syslog-ng.conf ############################################# # tr181-syslog generated syslog-ng.conf file ############################################# @version: 4.7 @include "scl.conf" options { chain_hostnames(no); keep_hostname(yes); use_fqdn(no); create_dirs(yes); flush_lines(0); log_fifo_size(256); log_msg_size(1024); stats(freq(0)); }; template t_default_template { template("${FULLDATE} ${HOST} [${LEVEL}] ${MSGHDR}${MSG}\n"); }; template t_json_template { template("$(format-json timestamp=${FULLDATE} host=${HOST} level=${LEVEL} program=${PROGRAM} message=${MESSAGE}), "); }; filter f_wifi { match("^((wld|wlan(-manager)?|(gmap-mod-)?ssw|csm): |kernel: .*wlan)" template("${PROGRAM}: ${MESSAGE}") flags(disable-jit)); }; filter f_dhcp { match("^(o|tr181-|dnsmasq-)?dhcp" template("${PROGRAM}: ${MESSAGE}") flags(disable-jit)); }; filter f_xtp_remote { match("^.*xtp_.*$" template("${PROGRAM}: ${MESSAGE}") flags(disable-jit)); }; filter f_firewall { match("^(tr181-firewall: |kernel: \\[ *[0-9]+(\\.[0-9]+)?\\] \\[Firewall\\] \\[)" template("${PROGRAM}: ${MESSAGE}") flags(disable-jit)); }; filter f_lcm { match("^.*(lcm|cthulhu|timingila|rlyeh|ocitar):.*$" template("${PROGRAM}: ${MESSAGE}") flags(disable-jit)); }; filter f_xtp_local { match("^.*xtp_.*$" template("${PROGRAM}: ${MESSAGE}") flags(disable-jit)); }; source s_system { unix-dgram("/dev/log" keep-timestamp(no) ); }; source s_kernel { file("/proc/kmsg" program_override("kernel") flags(kernel) default-facility(Kern) ); }; source s_localhost { }; destination d_action_3_file { file("/var/log/messages_dhcp" template(t_default_template) ); }; destination d_action_2_file { file("/var/log/messages_firewall" template(t_default_template) ); }; destination d_action_5_file { file("/var/log/messages" template(t_default_template) ); }; destination d_action_1_file { file("/var/log/messages_wifi" template(t_default_template) ); }; destination d_action_4_file { file("/var/log/messages_lcm.log" template(t_default_template) ); }; destination d_action_7_file { file("/var/log/messages_xtp" template(t_json_template) ); }; log { source(s_localhost); destination(d_action_5_file); }; log { filter(f_wifi); destination(d_action_1_file); }; log { filter(f_dhcp); destination(d_action_3_file); }; log { filter(f_firewall); destination(d_action_2_file); }; log { filter(f_lcm); destination(d_action_4_file); }; log { source(s_localhost); filter(f_xtp_local); destination(d_action_7_file); }; @include "/etc/syslog-ng.d"
最新发布
11-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值