我在 DigitalOcean 有一台服务器,它主要用于运行几个低流量的 WP 网站,其中 90% 的网站运行良好。但!其中一个站点经常有 5-20 个进程(取决于我设置的最大子进程数),每个进程占用的 CPU 比例在 5%-20% 之间看到这里。它一天中所有时间都处于这种状态,但我怀疑活跃用户越多,情况就越糟。
重新启动 php-fpm 或任何其他服务都无济于事 - 我查看了日志,但找不到任何我认为会导致此问题的原因。
我对整个服务器还很陌生,我不得不说我不太清楚是什么原因造成的。但如果有人能给我指明正确的方向,我将不胜感激!
一些信息:
DigitalOcean Droplet (4gb ram, 2 CPUs)
CentOS 7.3.1611 x64
nginx / php-fpm
Running WP sites (6-7 sites)
PHP-fpm.conf
listen = 127.0.0.1:9001
listen.allowed_clients = 127.0.0.1
user = int
group = int
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.max_requests = 300
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
Nginx.conf:
limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:40m;
limit_req_zone $binary_remote_addr zone=req_limit_per_ip:40m rate=20r/s;
server {
listen 114.242.22.180:80;
server_name int www.int;
root /home/int/web/int/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/int.log combined;
access_log /var/log/nginx/domains/int.bytes bytes;
error_log /var/log/nginx/domains/int.error.log error;
limit_conn conn_limit_per_ip 40;
limit_req zone=req_limit_per_ip burst=40 nodelay;
location = /wp-login.php {
allow xxx.xxx.xxx.xxx;
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ ^(.+\.php)(.*)$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/int/web/int/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias /home/int/web/int/stats/;
include /home/int/web/int/stats/auth.conf*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/int/conf/web/nginx.int.conf*;
}
答案1
我们可以看到 CPU 正在使用中,但是哪个进程正在使用它呢?PHP-FPM?MySQL?NginX?您多久从 NginX 获取一次 access.log 文件中的日志?它不是恒定的吗?如果它是恒定的,那么您可能遭受了 DDoS 攻击。
如果以上都是:是的,则需要 Cloudflare 或 Fail2Ban(对我来说,我两者都有)