The configuration of LNMP or LNAMP environment is not described here, only the process of configuring multiple instances on the basis of a LNMP environment. Because I am using the lnamp environment, I compile an extra copy of PHP to/usr/local/php-fpm/, configuration file in/etc/php-fpm/, and make notes on this basis.
Modify three values First:
1, in static mode, that is, the number of fixed processes running PHP-FPM.
2, each instance establishes 100 worker processes. (unfavorable too much, avoid instability)
3, each process exits after executing 200 requests. (Avoid the memory leak problem in PHP, that is, the more memory used)
Sed-i ' s#pm = dynamic#pm = Static# '/etc/php-fpm/php-fpm.conf
Sed-i ' S#pm.max_children = 5#pm.max_children = 100# '/etc/php-fpm/php-fpm.conf
Sed-i ' s#;p m.max_requests = 500#pm.max_requests = 200# '/etc/php-fpm/php-fpm.conf
The following are the commands for replicating php-fpm.conf and PHP-FPM service management scripts
cd/etc/php-fpm/
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
cd/etc/init.d/
CP PHP-FPM Php-fpm-1
Sed-i ' s#/etc/php-fpm/php-fpm.conf#/etc/php-fpm/php-fpm-1.conf# ' php-fpm-1
Sed-i ' s#/var/run/php-fpm.pid#/var/run/php-fpm-1.pid# ' php-fpm-1
Service Php-fpm-1 Restart
After executing the above command, a copy of the PHP-FPM is copied, and the service name and configuration filename are php-fpm-1.
To copy more copies, replace the 1 on the above command with the -2,listen listening port, and then execute it again.
Then write a restart_php_fpm.sh file that reads
Service Php-fpm-1 Restart
Service Php-fpm-2 Restart
Service php-fpm-3 Restart
... ...
Can be used to start and restart all PHP-FPM instances. Close with command Killall PHP-FPM.
Then the Nginx configuration.
In the HTTP segment join:
Upstream Php-fpm-pool {
Server 127.0.0.1:9001;
Server 127.0.0.1:9002;
Server 127.0.0.1:9003;
Server 127.0.0.1:9004;
Server 127.0.0.1:9005;
}
To modify the server segment:
Location ~. *\. (PHP|PHP5)? $ {
Fastcgi_pass Php-fpm-pool;
Fastcgi_index index.php;
Include fastcgi.conf;
}
Configuration ended.
Multiple instances in the effect is basically equal to the load balance of multiple machines, but I personally prefer to configure multiple instances on a single table (the cumulative resources are equal), in a machine configuration, maintenance, use are more convenient.