大网数据广告活动
服务器运维问答

How to optimize memory with Fail2Ban, Journal and Clamav

· 52CE 我爱测

I use VestaCP on Debian 9. Yesterday I received 3 email alerts related to cron. All three contain the same error message: /bin/sh: execle: Cannot allocate memory . So, I started with the free --mega command: total used free share…

问题原文

原帖链接 · cyclone200 · CC BY-SA 4.0

I use VestaCP on Debian 9.

Yesterday I received 3 email alerts related to cron. All three contain the same error message: /bin/sh: execle: Cannot allocate memory.

So, I started with the free --mega command:

              total        used        free      shared  buff/cache   available
Mem:           5969        5078         366         210         525         452
Swap:             0           0           0

There is clearly a RAM problem since I only have 366 Mb free.

To find out more, I used the following command ps -A --sort -rss -o comm,pmem,rss | head -n 20 to list my processes that use RAM:

fail2ban-server 35.2 2101952
systemd-journal 22.9 1370060
clamd           16.9 1014312
mysqld           2.8 169508
spamd child      1.5 95288
spamd            1.3 83448
spamd child      1.3 83048
apache2          0.6 41752
apache2          0.6 41444
apache2          0.6 40308
apache2          0.6 40276
apache2          0.6 40156
apache2          0.6 39860
apache2          0.6 39624
apache2          0.6 38696
apache2          0.6 37840
apache2          0.5 32160
apache2          0.3 17912
named            0.2 16016

So I understand right, it seems that the first 3 processes use 75% of the RAM!

I would like to have your opinion on how to optimize this:

1) Are these results normal?

2) Is there a way to fix this? Maybe by clearing the cache?

3) I have heard of the ulimit command, but is it really effective? If I configure ulimit 256 for fail2ban and clamav, won't it make these processes useless?

I did a lot of research but either it did not concern my problem, or the topics dated from 2010-2012 and therefore might not be correct in 2020.

Edit 1 : I don't know what to check for fail2ban and clamav but for journal, I imagine that the configuration file is in /etc/systemd/journald.conf. Here is mine:

[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=1000
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=100
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg

Should something be changed in this to limit the use of RAM?

Edit 2 : here is the result of cat /proc/sys/vm/swappiness : 60

已采纳解答

原帖链接 · Dom · CC BY-SA 4.0

To me, the kernel can not allocate memory as there is no swap. Your swapiness is 60, so the kernel may use swap when 60% of RAM is used. As there is no swap, it failed to allocate. You should set your swappiness to 0 with echo 0 > /proc/sys/vm/swappiness, or/and add some swap space.

Look also to change fail2ban to another port blocker, lighter. I have seen Pyruse in my docs but never test it

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-05-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。