VPS/云主机等
优惠信息分享

liunx宝塔面板解决rsyslogd内存占用很高的问题

大鸟博客用的vps是瓦工的3核2G,cn2 gia线路的vps方案,按理说这么个小博客2G内存是足够使用了。可以是最近常常发现内存占用一度达到90%。一度怀疑是缓存所致,但是我的menmcached的缓存也就开了128M,算了不猜了,打开宝塔任务管理器看看内存占用,就一目了然。额,没有这个插件的,可以用top命令也是一样。

宝塔服务器面板,一键全能部署及管理,送你3188元礼包,点我领取https://www.bt.cn/?invite_code=MV9ub2NxdmI=

1、查看进程

点开了宝塔任务管理器,查看了内存占用,发现rsyslogd这货占用了很高的内存,达到了594M。我了个擦擦,太可怕了,那么内存占用的元凶,肯定是这货了。解决方法就是把这个玩意设置的内存设置小点,应该就可以了!在解决这个问题之前,我们先看看元凶~~

2、根本原因

查看rsyslog输出的日志/var/log/

发现rsyslog把Journal的log都进行的输出和汇总。log也就会也多,内存占用也就越多。

同时也可能导致systemd-journald内存占用过高

这个问题就简单提及,感兴趣自己去搜索吧。

3、rsyslogd设置

1)修改rsyslogd服务配置文件

nano /usr/lib/systemd/system/rsyslog.service

2)在Service配置中添加这三项,如下所示:

  • MemoryAccounting=yes
  • MemoryMax=80M
  • MemoryHigh=8M

具体如下如下,仔细看放置的位置。

[reply]

[Unit]Description=System Logging Service;Requires=syslog.socketWants=network.target network-online.targetAfter=network.target network-online.targetDocumentation=man:rsyslogd(8)Documentation=http://www.rsyslog.com/doc/[Service]Type=notifyEnvironmentFile=-/etc/sysconfig/rsyslogExecStart=/usr/sbin/rsyslogd -n $SYSLOGD_OPTIONSRestart=on-failureUMask=0066StandardOutput=nullRestart=on-failureMemoryAccounting=yesMemoryMax=80MMemoryHigh=8M[Install]WantedBy=multi-user.target;Alias=syslog.service

3)注意,通常情况下rsyslogd大小只有5M,所以将内存上限设置为8M,然后将绝对内存限制为80M。

4)重启服务

systemctl daemon-reloadsystemctl restart rsyslog

4、修改Journal的配置

修改Journal的配置/etc/systemd/journald.conf

1)把Storage改为none,如下

#  This file is part of systemd.##  systemd is free software; you can redistribute it and/or modify it#  under the terms of the GNU Lesser General Public License as published by#  the Free Software Foundation; either version 2.1 of the License, or#  (at your option) any later version.## Entries in this file show the compile time defaults.# You can change settings by editing this file.# Defaults can be restored by simply deleting this file.## See journald.conf(5) for details.[Journal]Storage=none#Compress=yes#Seal=yes#SplitMode=uid#SyncIntervalSec=5m#RateLimitInterval=30s#RateLimitBurst=1000SystemMaxUse=16M#SystemKeepFree=#SystemMaxFileSize=#RuntimeMaxUse=#RuntimeKeepFree=#RuntimeMaxFileSize=#MaxRetentionSec=#MaxFileSec=1monthForwardToSyslog=no#ForwardToKMsg=no#ForwardToConsole=no#ForwardToWall=yes#TTYPath=/dev/console#MaxLevelStore=debug#MaxLevelSyslog=debug#MaxLevelKMsg=notice#MaxLevelConsole=info#MaxLevelWall=emerg#LineMax=48K

2)重启生效

systemctl restart systemd-journald

3)Storage选项扩展

通过查看man手册,#man 5 journald.conf 你会发现,Storage=的值可以是volatile,persistent, autoandnone,但是,默认的是auto,

  • volatile代表日志只存在内存中,即/run/log/journal/
  • persistent代表日志只存在磁盘中,即/var/log/journal/
  • auto代表日志存在磁盘中,或者内存中,这个取决于你是否创建/var/log/journal/目录!!这个也算是一个坑吧,看来大家都需要手动mkdir -p /var/log/journal/,systemctl restart systemd-journald来解放自己的内存了!!!
  • none,表示,日志不保留,全部drop,只有当你决定不使用systemd-journald的时候,你可以使用!

[/reply]

5、最后

设置后,顿时内存的占用问题解决了,如果你也有这个烦恼不妨试试。看看解决后的rsyslogd内存占用:

赞(0)
未经允许不得转载:遗弃你|YIQINI.COM » liunx宝塔面板解决rsyslogd内存占用很高的问题

评论 抢沙发

评论前必须登录!

 

登录

找回密码

注册