目前我有一台具有以下规格的服务器:
32 core
128gb RAM
1TB SSD hardisk
5Gbps network uplink
当前设置是 nginx+php-fpm,没有任何负载平衡设置
nginx.conf
fastcgi_connect_timeout 9000;
fastcgi_send_timeout 9000;
fastcgi_read_timeout 9000;
fastcgi_buffer_size 256k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 512k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi-56.sock;
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
}
php-fpm.conf
[www]
listen = /tmp/php-cgi-56.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.status_path = /phpfpm_56_status
pm.max_children = 2000
pm.start_servers = 40
pm.min_spare_servers = 40
pm.max_spare_servers = 300
request_terminate_timeout = 9000
request_slowlog_timeout = 0s
slowlog = var/log/slow.log
无论我如何更改配置,php-fpm 仍然会出现 502 错误,服务器上的 RAM 使用量最多为 12-15GB,我们有足够的 RAM,但 php-fpm 的 CPU 使用率很高。如果您对配置有任何想法,请提出建议或评论。
否则,我正在考虑设置如下所示的负载平衡,可能需要您的想法:
1)使用HaProxy
2)使用 Nginx 和多个服务器作为 PHP-FPM 池:
3)使用具有多个 php-fpm 池的当前服务器
upstream php {
server 127.0.0.1:9001 max_fails=3 fail_timeout=30s;
server 127.0.0.1:9002 max_fails=3 fail_timeout=30s;
server 127.0.0.1:9003 max_fails=3 fail_timeout=30s;
}
您认为哪一个更合适?我只需要摆脱 502 问题。