Multi-process pool of php-fpm in nginx

php-fpm multiple process pools

illustrate:

Each pool uses a different configuration, and the pools do not interfere with each other. By default, PHP has only one pool enabled, and all requests are executed in this pool. Once some requests are congested or the like, it is likely to cause problems in the entire pool; if multiple pools are enabled, requests can be classified into different pools for execution. At this time, if some requests are congested, etc. In this case, it will only affect the pool where it is located, so as to control the scope of the failure.

Setting up multiple process pools and assigning different sites to each process pool can avoid the embarrassing situation that one site occupies too many resources and other sites cannot access it. This makes the website run better. If a site is attacked by a small amount of CC, it will not drag across all the sites.

 

Step 1: Configuration of php-fpm:

In php-fpm.conf, there is only one pool (process pool) [www] by default. If you need to add a process pool called ajia, you can add the following configuration: (The configuration here can be increased or decreased by itself, but [ajia] word is required)

[ajia]    

user=nobody ; can use other users and user groups

group=nobody

;listen=127.0.0.1:9001 ;You can use tcp or unix socket, but it must be different from other pool configurations, such as tcp ports cannot be the same, socket files cannot be the same

listen = /dev/shm/php-fpm0.socket 

pm=dynamic ; When pm=dynamic, pm.max_children is not used, but the value must also exist, when pm=static, only pm.max_children is used

pm.max_children=10

pm.start_servers=2 

pm.min_spare_servers=1 

pm.max_spare_servers=10 

pm.process_idle_timeout=15

 

Step 2: Configure in nginx:

The value of fastcgi_pass in the corresponding fastcgi module configuration is set to the newly added ajia process pool

fastcgi_pass unix:/dev/shm/php-fpm0.socket;

or

fastcgi_pass  127.0.0.1:9001;

 

Finally: After restarting nginx and php-fpm, it will take effect. Use ps -ef | grep php-fpm to view the fpm process that will appear in 2 different process pools

 

Generally, fastcgi_pass is not defined in a specific process pool, but in a set of upstream upstream servers. This upstream has included different php-fpm process pools, and the settings are as follows:

Add upstream in the http configuration block:

upstream fzjh{

  server unix:/dev/shm/php-fpm0.socket weight=1; #weight set the weight, this is the new process pool of ajia

  server 127.0.0.1:9000 weight=2; #This is the default www process pool

}

 

The value of fastcgi_pass can be changed to fzjh, so that each time php-fpm processes a connection, it will poll different process pools. Even if one of the process pools hangs, it will not affect the php processes of other pools.

 

 

The process pool of the above method is based on the effect of php-fpm itself. It is driven by a php-fpm master process. Another way is to start multiple php-fpm master processes. These multiple master processes correspond to the connection to nginx Different methods (socket files or ports are different)

 

Step 1: Use multiple php-fpm configuration files, such as php-fpm1.conf, php-fpm2.conf

The listen configuration in php-fpm1.conf is unix:/dev/shm/php-fpm1.socket, other configuration depends on the situation

The listen configuration in php-fpm2.conf is unix:/dev/shm/php-fpm2.socket

Step 2: Start two php-fpm master processes, and bring the php-fpm configuration file through -y:

/usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm1.conf

/usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm2.conf

 

After restarting nginx and php-fpm, use ps -ef | grep php-fpm to view 2 different masters, so that's it

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939597&siteId=291194637