在过去的10天里,我的网站突然出现了CPU使用率的上升,CPU使用率达到了100%的三倍。 在那段时间里,我无法SSH连接到我的网站,所以我一直无法弄清楚实际上使用了那么多的CPU,但是我有一种感觉,它需要对Apache做些什么。 我的网站是一个Django应用程序,使用DigitalOcean上的Apache2,PostgreSQL和Memcached(512MB Ram,20GB SSD Disk,Ubuntu 14.04 x64)。
这是当前顶部的输出。
top - 16:15:31 up 19:12, 1 user, load average: 0.01, 0.09, 0.46 Tasks: 78 total, 2 running, 76 sleeping, 0 stopped, 0 zombie %Cpu(s): 9.5 us, 1.9 sy, 0.0 ni, 85.0 id, 3.3 wa, 0.3 hi, 0.0 si, 0.0 st KiB Mem: 501868 total, 495576 used, 6292 free, 41836 buffers KiB Swap: 0 total, 0 used, 0 free. 152976 cached Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 15036 www-data 20 0 906084 156828 2448 S 19.3 31.2 12:08.08 apache2 1 root 20 0 33472 1300 0 S 0.0 0.3 0:02.09 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:01.63 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root 20 0 0 0 0 S 0.0 0.0 0:10.60 rcu_sched 8 root 20 0 0 0 0 R 0.0 0.0 0:29.05 rcuos/0 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/0 11 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 12 root rt 0 0 0 0 S 0.0 0.0 0:01.07 watchdog/0 13 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper 14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs 15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback 17 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd 18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/u3:0
这里是Apache conf文件
<VirtualHost *:80> RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [nocase] RewriteRule ^(.*) http://www.example.com$1 [last,redirect=301] ServerName example.com ServerAlias www.example.com ServerAdmin [email protected] WSGIDaemonProcess example python-path=/home/abc/example:/home/abc/example/env/lib/python2.7/site-packages WSGIProcessGroup example WSGIApplicationGroup %{GLOBAL} WSGIScriptAlias / /home/abc/example/wsgi.py DocumentRoot /home/abc/example <Directory /> Require all granted </Directory> Alias /static/ /home/abc/example/static/ <Directory /home/abc/example/static> Order deny,allow Allow from all </Directory> Alias /media/ /home/abc/example/media/ <Directory /home/abc/example/media> Order deny,allow Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
以下是过去一个月CPU,磁盘和带宽使用情况的图表



正如您所看到的,在过去的几天里CPU使用率猛增了3倍。 我不得不重新启动我的液滴把它降下来。 CPU使用率一般在0-5%之间变化,直到几天前,但现在已经增加了。
网站的响应时间也增加到4秒左右。 一切似乎都工作正常,直到10天左右,从那时起我没有对我的configuration做任何改变。 交通量没有增加,每天的访客量约为1500人。 我怎样才能找出造成这个问题的原因? 有任何想法吗?
从带宽图,它显示入站stream量增加,即stream量到服务器,也增加了磁盘写入率..这让我怀疑在服务器上的某种types的攻击..最好的安全方法是改变所有服务器的密码..这是至关重要的,以确定是否是一个软件的错误或某种成功的违反您的服务器…
如果sikas的理论是正确的,这是由外部stream量造成的,那么你需要更好地调整Apache。 将ServerLimit减半或更多,看下一次是否更好。
您一定要尝试使用Cloudflare,至less尝试免费版本,您的服务器将更加自由,而不需要提供静态资源,并且您的站点将受到最常见的攻击保护。