2013-07-08 138 views
2

我有一台服务器(Ubuntu的),该服务器上的多个域和运行一系列的cron脚本。但是无法预测服务器上的负载,因此我无法在cron脚本中设置正确的负载量。服务器负载均衡脚本

然而,在cron运行的脚本,从时间过载时间和生成CPU和内存在巨大的负荷,从而导致服务器的几个服务的停止(如邮件服务器为例)。

的问题是:我怎么能写在运行,现在都在cron仅在服务器负载最小阈值以下的程序脚本?有什么应用程序可以在Linux下执行此操作吗?

谢谢您的时间!

+0

您是否尝试过重新整理流程? – mnagel

+0

是的,实际上我试图简化脚本很多,但我无法预测是否有任何迭代需要花费1分钟或15分钟,因此当在cron中运行的几个脚本同时运行时,服务器上会出现巨大的负载 – Mike

回答

1

可以检查monit系统管理。 您可以添加到这个配置文件:

 


    # Monitoring the apache2 web services. 
    # It will check process apache2 with given pid file. 
    # If process name or pidfile path is wrong then monit will 
    # give the error of failed. tough apache2 is running. 
    check process apache2 with pidfile /var/run/apache2.pid 
    start program = "/etc/init.d/apache2 start" 
    stop program = "/etc/init.d/apache2 stop" 
    # Admin will notify by mail if below of the condition satisfied. 
    if cpu is greater than 60% for 2 cycles then alert 
    if cpu > 80% for 5 cycles then restart 
    if totalmem > 200.0 MB for 5 cycles then restart 
    if children > 250 then restart 
    if loadavg(5min) greater than 10 for 8 cycles then stop 
    if 3 restarts within 5 cycles then timeout 
    group server 

这是一个很好的工具,你可以搜索如何执行自己的脚本,当条件满足。