我正在debian服务器上运行一些web应用程序,有时还要为ddos攻击而苦恼。 这是吃掉了我所有的资源,我不能再ssh到服务器。 一个想法是,如果负载平均值过高,则放弃所有连接,所以如果负载平均值足够低,则仍有资源可用,并接受新的连接。 由于这必须在重负载下工作,恐怕cronjob不够快或占用太多资源。
tl; dr:如果负载平均值高于特定的阈值,有没有办法configuration行为?
虽然我认为您应该尝试在防火墙或networking层面解决实际问题,但是基于资源的操作的快捷方式是使用Monit实用程序 。
具体来说, Monit可以执行资源testing ,提醒您并根据这些条件采取行动。
IF resource operator value [[<X>] <Y> CYCLES] THEN action [ELSE IF SUCCEEDED [[<X>] <Y> CYCLES] THEN action]
所以…
check system example.com if loadavg (1min) > 10 then alert
或者针对Apache的某些内容:
check process apache with pidfile /var/run/httpd.pid start program = “/sbin/service httpd start” stop program = “/sbin/service httpd stop” if children > 250 then restart if loadavg(5min) greater than 10 for 8 cycles then stop if 3 restarts within 5 cycles then timeout