抱歉,评论被关闭
如何实现PHP的php-fpm多实例负载均衡?
实现PHP的php-fpm多实例负载均衡、把多个网站实例分开来运行、更加安全可靠
原本已经部署了再php-fpm基础上新增 (
一次增加了两个实例 shell实现如下:)
cd /home/lanmp-mm/php/etc/
cp php-fpm.conf php-fpm-1.conf
sed -i ‘s#listen = 127.0.0.1:9000#listen = 127.0.0.1:9001#’ php-fpm-1.conf
sed -i ‘s#[www]#[php-fpm-pool-1]#’ php-fpm-1.conf
sed -i ‘s#pid = run/php-fpm.pid#pid = run/php-fpm-1.pid#’ php-fpm-1.conf
cp php-fpm.conf php-fpm-2.conf
sed -i ‘s#listen = 127.0.0.1:9000#listen = 127.0.0.1:9002#’ php-fpm-2.conf
sed -i ‘s#[www]#[php-fpm-pool-2]#’ php-fpm-2.conf
sed -i ‘s#pid = run/php-fpm.pid#pid = run/php-fpm-2.pid#’ php-fpm-2.conf
cd /etc/init.d/
cp php-fpm php-fpm-1
sed -i ‘s#/etc/php-fpm.conf#/etc/php-fpm-1.conf#’ php-fpm-1
sed -i ‘s#/var/run/php-fpm.pid#/var/run/php-fpm-1.pid#’ php-fpm-1
cp php-fpm php-fpm-2
sed -i ‘s#/etc/php-fpm.conf#/etc/php-fpm-2.conf#’ php-fpm-2
sed -i ‘s#/var/run/php-fpm.pid#/var/run/php-fpm-2.pid#’ php-fpm-2
touch /home/sh/restart-php-fpm
chmod a+x /home/sh/restart-php-fpm
echo “#!/bin/bash
service php-fpm restart
service php-fpm-1 restart
service php-fpm-2 restart
” > /home/sh/restart-php-fpm
nginx下修改相应站点配置:
比如站点里:fastcgi_pass 127.0.0.1:9000; 修改为
fastcgi_pass 127.0.0.1:9001;
意思就是把实例9000端口 修改为9001端口php-fpm实例
当然也可以用负载均衡的方式:
upstream phps{
server 127.0.0.1:9000 weight=1;
server 127.0.0.1:9001 weight=1;
server 127.0.0.1:9002 weight=1;
}
同样把上面
fastcgi_pass 127.0.0.1:9000; 修改为
fastcgi_pass phps;
文出自 “凹凸曼” 博客,请务必保留此出处 http://www.apoyl.com/?p=2386