码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP架构四

时间:2018-02-13 12:27:43      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:css   grep   启动   linux   /tmp   div   nginx配置文件   ima   proxy   

php-fpm的pool(连接池)

技术分享图片

我们查看php的进程时,会发现,在最后一个pool的选项,而这个就是我们在php-fpm配置文件里写的一个连接池。

[root@bogon linux.com]# vim /usr/local/php-fpm/etc/php-fpm.conf
[root@bogon linux.com]# 
[root@bogon linux.com]# ps aux|grep php
root       3068  0.0  0.0 227144   228 ?        Ss   2月11   0:10 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm    3114  0.0  0.0 229228   124 ?        S    2月11   0:00 php-fpm: pool www

1.编辑php-fpm配置文件添加新pool命名为linux.com

[linux.com]
listen = /tmp/linux.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

2.检查php配置文件,重新加载配置文件,查看php进程发现有连个pool了

为什么要建立多个池子呢?拿www和linux.com两个池子来说,www池子最多可以同时开50个进程,当www进程满了就会报502错误,这个时候linux.com不受影响。

[root@bogon linux.com]# /usr/local/php-fpm/sbin/php-fpm -t
[13-Feb-2018 10:28:14] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

[root@bogon linux.com]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@bogon linux.com]# ps -aux|grep php-fpm
php-fpm   18117  0.0  0.5 229228  5076 ?        S    10:29   0:00 php-fpm: pool www
php-fpm   18118  0.0  0.5 229228  5076 ?        S    10:29   0:00 php-fpm: pool www
php-fpm   18119  0.0  0.5 229228  5076 ?        S    10:29   0:00 php-fpm: pool www
php-fpm   18120  0.0  0.5 229228  5072 ?        S    10:29   0:00 php-fpm: pool linux.com
php-fpm   18121  0.0  0.5 229228  5076 ?        S    10:29   0:00 php-fpm: pool linux.com
php-fpm   18122  0.0  0.5 229228  5076 ?        S    10:29   0:00 php-fpm: pool linux.com

3.新建pool,编辑aaa.com.conf配置文件添加支持php配置

[root@bogon vhost]# ls
aaa.com.conf  load.conf  proxy.conf  ssl.conf  test.com.conf
[root@bogon vhost]# vim aaa.com.conf 
[root@bogon vhost]# 

  

server
{
    listen 80 default_server;
    server_name aaa.com;
    index index.html index.htm index.php;
    root /data/wwwroot/default;

    location ~ \.php$
    {
      include fastcgi_params;
      fastcgi_pass unix:/tmp/linux.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
    }

}

4.查看nginx配置文件可以看到有个include选项,php-fpm也是支持的

[root@bogon conf]# vim nginx.conf
[root@bogon conf]# 
    gzip_types text/plain application/x-javascript text/css text/htm
    application/xml;
    include vhost/*.conf;
}

5.编辑php-fpm.conf,在global标签下添加include选项

[root@bogon conf]# vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
include = etc/php-fpm.d/*.conf

6.将www配置和linux.com配置拆分开,在etc目录下创建php-fpm.d目录并创建两个配置文件www.conf和linux.conf,在配置文件中分别将拆分出来的配置写到里面

[root@bogon conf]# cd /
[root@bogon /]# cd usr/local/php-fpm/etc/
[root@bogon etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini
[root@bogon etc]# mkdir php-fpm.d
[root@bogon etc]# cd php-fpm.d/
[root@bogon php-fpm.d]# vi www.conf
[root@bogon php-fpm.d]# 
[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@bogon php-fpm.d]# vi linux.conf
[linux.com] listen = /tmp/linux.sock #listen = 127.0.0.1:9000 listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024

7.删除php-fpm.conf配置文件中的www和linux.com配置

8.检查配置,重启php-fpm everyone ok

[root@bogon php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[13-Feb-2018 11:39:14] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

[root@bogon php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@bogon php-fpm.d]# 

9.检查服务是否启动,发现一切ok

[root@bogon php-fpm.d]# ps -aux|grep php-fpm           
root      23264  1.8  0.4 227232  4984 ?        Ss   11:39   0:01 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm   23284  0.1  0.5 229256  5080 ?        S    11:40   0:00 php-fpm: pool linux.com
php-fpm   23285  0.0  0.5 229256  5080 ?        S    11:40   0:00 php-fpm: pool linux.com
php-fpm   23286  0.0  0.5 229256  5076 ?        S    11:40   0:00 php-fpm: pool www
php-fpm   23287  0.0  0.5 229256  5076 ?        S    11:40   0:00 php-fpm: pool www

  

  

  

 

  

 

 

  

  

  

 

LNMP架构四

标签:css   grep   启动   linux   /tmp   div   nginx配置文件   ima   proxy   

原文地址:https://www.cnblogs.com/sunyujun/p/8446241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!