50次課 php-fpm的(pool、慢執行日誌、open_basedir、進程管理)
阿新 • • 發佈:2018-08-17
referer oot stc acc not tin cati access local php-fpm的pool
它的pool就是它的池子
[root@100xuni1 etc]# cd /usr/local/php-fpm/etc/ [root@100xuni1 etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php.ini [root@100xuni1 etc]# cat 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 [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
設置多個pool
* 進入/usr/local/php-fpm/etc/下編輯php-fpm.conf
[root@100xuni1 etc]# cd /usr/local/php-fpm/etc/
[root@100xuni1 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@100xuni1 etc]# vim php-fpm.conf
以上添加完成後查看是否有語法錯誤
[root@100xuni1 etc]# /usr/local/php-fpm/sbin/php-fpm -t [17-Aug-2018 11:03:39] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
沒有語法錯誤然後重啟
[root@100xuni1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
然後用ps看一下
[root@100xuni1 etc]# ps aux |grep php-fpm
怎麽用兩個pool
進入 /usr/local/nginx/conf/vhost/目錄下編輯test.com.conf
[root@100xuni1 etc]# cd /usr/local/nginx/conf/vhost/ [root@100xuni1 vhost]# ls aaa.com.conf ld.conf proxy.conf ssl.conf test.com.conf [root@100xuni1 vhost]# vim test.com.conf
[root@100xuni1 vhost]# vim test.com.conf
expires 7d;
valid_referers none blocked server_names *.test.com ;
if ($invalid_referer) {
return 403;
}
access_log off;
}
location ~ .*\.(js|css)$
{
# expires 12h;
access_log off;
}
location /admin/
{
allow 192.168.63.100;
allow 127.0.0.1;
deny all;
}
location ~ .*(upload|image)/.*\.php$
{
deny all;
}
if ($http_user_agent ~* ‘Spider/3.0|YoudaoBot|Tomato‘)
{
return 403;
}
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock; ##**這裏定義成php-fcgi.sock**
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
}
access_log /tmp/test.com.log hanshuo;
}
然後再去定義另外一個pool
[root@100xuni1 vhost]# ls
aaa.com.conf ld.conf proxy.conf ssl.conf test.com.conf
[root@100xuni1 vhost]# vim aaa.com.conf
[root@100xuni1 vhost]# vim aaa.com.conf
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/han.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
}
}
php也支持include進入php-fpm.conf下編輯
[root@100xuni1 etc]# mkdir php-fpm.d ##創建php-fpm.d因為include = etc/php-fpm.d/*.conf!
[root@100xuni1 etc]# cd php-fpm.d/ ##進入
[root@100xuni1 php-fpm.d]# vim www.conf ##編輯
[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@100xuni1 php-fpm.d]# vim han.com ##然後在創建一個目錄han.com
[han.com] ##寫入內容
listen = /tmp/han.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@100xuni1 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2018 11:44:58] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
*重啟效果跟以前沒有加include = etc/php-fpm.d/.conf是一樣的**
[root@100xuni1 php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
php-fpm慢執行日誌
php-fpm的慢執行日誌非常有用lamp是沒有的,lnmp有,為什麽分析慢執行日誌,在運維工作當中經常會遇到一個問題,有人經常反饋網站訪問慢了,為什麽慢要知道根本原因,慢在什麽地方,php網站有辦法查他到底慢在哪裏,用慢執行日誌查看
配置php-fpm慢執行日誌比如說針對www.conf
編輯/usr/local/php-fpm/etc/php-fpm.d/下的www.conf,添加一下內容
[root@100xuni1 php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf ##加入下邊的兩行
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
檢測和重新加載
[root@100xuni1 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[17-Aug-2018 13:29:11] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@100xuni1 php-fpm.d]# /etc/init.d/php-fpm reload
Reload service php-fpm done
查看有沒有生成日誌文件如果已生成用cat查看日誌
[root@100xuni1 php-fpm.d]# ls /usr/local/php-fpm/var/log/www-slow.log ##已生成
/usr/local/php-fpm/var/log/www-slow.log
模擬慢執行日誌的php寫個腳本
[root@100xuni1 php-fpm.d]# vim /data/wwwroot/test.com/sleep.php 編輯個腳本寫入下邊的代碼
<?php echo “test slow log”;sleep(2);echo “done”;?> ##故意休眠兩秒鐘
~
~
open_basedir
編輯配置文件
[root@100xuni1 php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf ##加入以下配置
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
啟動
測試
查看錯誤日誌
把php-fpm的錯誤日誌定義上
[root@100xuni1 php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
12.24 php-fpm進程管理
50次課 php-fpm的(pool、慢執行日誌、open_basedir、進程管理)