ubuntu – 有没有办法自动防止内存不足?

我经常在我的VPS ubuntu服务器上耗尽内存.我希望有一种方法可以在内存开始耗尽时简单地重启apache2,因为这似乎可以解决问题.或者我只是懒得解决这个问题?我在服务器上的内存有限……

好的,更多信息:

我正在运行apache2 prefork,这是我的内存设置(我一直在调整它们……):

StartServers         3
MinSpareServers      1
MaxSpareServers      5
MaxClients           150
MaxRequestsPerChild  1000

VPS有1 GB的ram,运行ubuntu 11.04 32位.

至于脚本,我有一个带有5个博客wordpress网络,一个AskBot(一个python / django stackexchange克隆)的安装,以及一个未真正使用的Mediawiki安装.还有一个自制的mp3脚本访问getid3库以显示播客列表的信息,它似乎抛出一些PHP错误,不知道这是否是罪魁祸首……

Monit可以做到这一点.

您可以使用配置行,例如:

check process apache 
    with pidfile "/var/lock/apache/httpd.pid"
    start program = "/etc/init.d/httpd start" with timeout 60 seconds
    stop program = "/etc/init.d/httpd stop"
    if 2 restarts within 3 cycles then timeout
    if totalmem > 100 Mb for 5 cycles then restart
    if children > 255 for 5 cycles then stop
    if cpu usage > 95% for 3 cycles then restart
    if Failed port 80 protocol http then restart
    group server
    depends on httpd.conf,httpd.bin

(自this config example on monit.com修改)

这可能会影响前面提到的ulimit选项.

重启服务是一个绑定.你应该试着找出它泄漏记忆的原因.

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...