이 글에서는 php-fpm 풀, PHP 느린 실행 로그, open_basedir, php-fpm 프로세스 관리에 대한 내용을 소개합니다. 이제 필요한 친구들이 참고할 수 있도록 공유하겠습니다. fpm의 풀 구성
nginx에서 여러 가상 머신을 열 수 있으며, 모두 서비스를 제공하려면 PHP가 필요합니다. 따라서 각각의 서로 다른 가상 머신의 성능을 보장하기 위해 여러 php-fpm 풀 서비스를 활성화할 수 있습니다. 각 풀은 하나의 사이트를 제공합니다.
방법 1:
/usr/local/php-fpm/etc/php-fpm.conf에 콘텐츠 추가://两个模块命名为不同名字,监听的socket名字也不一样。在vhost相应的conf的中设置对应路径即可。 [www] listen = /tmp/www.sock 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 [shuai。com] listen = /tmp/shuai.sock 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 /usr/local/php-fpm/sbin/php-fpm -t //验证配置是否正确 service php-fpm restart //重启 [root@shuai-01 etc]# ps aux |grep php-fpm root 5854 1.2 0.4 227212 4972 ? Ss 01:41 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 5855 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5856 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5857 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5858 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5859 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5860 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5861 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5862 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5863 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5864 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5865 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5866 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5867 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5868 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5869 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5870 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5871 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5872 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5873 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5874 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5875 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5876 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5877 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5878 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5879 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5880 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5881 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5882 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5883 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5884 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5885 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5886 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5887 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5888 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5889 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5890 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5891 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5892 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5893 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5894 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com root 5897 0.0 0.0 112684 976 pts/0 S+ 01:42 0:00 grep --color=auto php-fpm
[root@shuai-01 etc]# cd /usr/local/nginx/conf/vhost/ [root@shuai-01 vhost]# ls aaa.com.conf ld.conf proxy.conf ssl.conf test.com.conf
한 가지 정의:
[root@shuai-01 vhost]# vi test.com.conf
한 가지 정의는 다음과 같습니다.
[root@shuai-01 vhost]# vi aaa.com.conf
방법 2:
첫 번째 방법은 그다지 깔끔하지 않은 것 같습니다. nginx에 가상 머신을 추가할 때 include 문과 유사할 수 있습니다.
/usr/local/php-fpm/etc/php-fpm.conf에 콘텐츠를 추가하세요:
그런 다음 다음 구성 문을 삭제하세요.
mkdir /usr/local/php-fpm/etc/php-fpm.d/ cd /usr/local/php-fpm/etc/php-fpm.d/ vim www.conf //内容如下 [www] listen = /tmp/www.sock 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 vim aming.conf //内容如下 [aming] listen = /tmp/aming.sock //监听的sock名字互不相同 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 //检查vhost的conf文件,相应的更改监听sock /usr/local/php-fpm/sbin/php-fpm -t //验证配置是否正确 service php-fpm restart //重启 ps aux |grep php-fpm //发现aming和www都出现了
vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
//다음 내용 추가request_slowlog_timeout = 1 //프로덕션 환경에서 1초 이상 실행된 명령문을 기록합니다. 일반적으로 2초 동안 작성합니다.
slowlog = /usr/local/php-fpm/var/log/www-slow.log //로그 저장 디렉터리
vim /data/wwwroot/test.com/sleep.php //写入如下内容 <?php echo "test slow log"; sleep(2); echo "done"; ?> [root@cent01 vhost]# curl -x127.0.0.1:80 test.com/sleep.php //测试
test slow logdone [root@cent01 vhost]# cat /usr/local/php-fpm/var/log/www-slow.log //慢日志提示第三行花费的时间太多 [16-Nov-2017 20:20:39] [pool www] pid 14208 script_filename = /data/nginx/test.com/sleep.php [0x00007f630f62f270] sleep() /data/nginx/test.com/sleep.php:3
当php文件遇到错误时,查错可以在/etc/init.d/php-fpm.ini 文件中打开display_error功能,这样错误就能直接在浏览器上显示。
open_basedir如果在php.ini中定义就不合适,在pool中定义刚刚好,在Apache中定义在虚拟主机配置文件。
可以直接在/usr/local/php-fpm/etc/php-fpm.d/www.conf中添加如下语句:
php_admin_value[open_basedir]=/data/nginx/aming.com:/tmp/
配置完成后重启服务 service php-fpm restart 或者 /etc/init.d/php-fpm restart
其中路径需要配置正确。否则会报错。
将配置文件改为如下几行。
[root@shuai-01 php-fpm.d]# vi /usr/local/php-fpm/etc/php.ini error_log=/usr/local/php-fpm/var/log/php_errors.log error_reporting=E_ALL display_errors = Off log_errors = On
创建一个存放错误日志的文件
[root@shuai-01 php-fpm.d]# touch /usr/local/php-fpm/var/log/php_errors.log [root@shuai-01 php-fpm.d]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log
[root@shuai-01 php-fpm.d]# cat www.conf [www] listen = /tmp/www.sock listen.mode=666 user = php-fpm group = php-fpm pm = dynamic //动态的 ;pm = static pm.max_children = 50 //最大子进程50个 pm.start_servers = 20 // 启动的时候20个 pm.min_spare_servers = 5 //空闲时,最少有5个 pm.max_spare_servers = 35 //空闲时,最大有35个 pm.max_requests = 500 // 一个进程最多的请求数 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www-slow.log php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
相关推荐:
위 내용은 php-fpm 풀, PHP 느린 실행 로그, open_basedir, php-fpm 프로세스 관리의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!