php-fpm启动,重启,终止操作
<div id="content_views" class="htmledit_views"><p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">转载:https://blog.csdn.net/wzx19840423/article/details/79071928</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">启动php-fpm:</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left"><span style="line-height: 1.8; font-size: 16px; color: rgba(255, 0, 0, 1)">/usr/<span class="hljs-built_in" style="color: rgba(0, 0, 255, 1); line-height: 1.8">local/php/sbin/php-fpm</span></span></p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left"> </p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">php 5.3.3 以后的php-fpm <span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">不再支持</span> php-fpm 以前具有的 /usr/local/php/sbin/php-fpm (start|stop|reload)等命令,所以不要再看这种老掉牙的命令了,需要<span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">使用信号控制</span>:</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">master进程可以理解以下信号</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left"> <span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">INT, TERM </span>立刻终止<br><span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">QUIT </span>平滑终止<br><span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">USR1</span> 重新打开日志文件<br><span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">USR2</span> 平滑重载所有worker进程并重新载入配置和二进制模块</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">
</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">
一个简单直接的重启方法:</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">
先查看php-fpm的master进程号</p>
<div class="cnblogs_code" style="border: 1px solid rgba(204, 204, 204, 1); overflow: auto; color: rgba(0, 0, 0, 1); font-family: "Courier New" !important; font-size: 12px !important">
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy" style="line-height: 1.5 !important"><img style="border-style: none !important; border-color: rgba(221, 221, 221, 1)" src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></span></div>
<pre># <span style="color: rgba(0, 0, 255, 1); line-height: 1.5 !important">ps</span> aux|<span style="color: rgba(0, 0, 255, 1); line-height: 1.5 !important">grep</span> php-<span style="line-height: 1.5 !important">fpm
root </span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">21891</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.0</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.0</span> <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">112660</span> <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">960</span> pts/<span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">3</span> R+ <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">16</span>:<span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">18</span> <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0</span>:<span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">00</span> <span style="color: rgba(0, 0, 255, 1); line-height: 1.5 !important">grep</span> --color=auto php-<span style="line-height: 1.5 !important">fpm
root </span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">42891</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.0</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.1</span> <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">182796</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">1220</span> ? Ss 4月18 <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0</span>:<span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">19</span> php-fpm: master process (/usr/local/php/etc/php-<span style="line-height: 1.5 !important">fpm.conf)
nobody </span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">42892</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.0</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.6</span> <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">183000</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">6516</span> ? S 4月18 <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0</span>:<span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">07</span> php-<span style="line-height: 1.5 !important">fpm: pool www
nobody </span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">42893</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.0</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0.6</span> <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">183000</span><span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">6508</span> ? S 4月18 <span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">0</span>:<span style="color: rgba(128, 0, 128, 1); line-height: 1.5 !important">17</span> php-fpm: pool www</pre>
<div class="cnblogs_code_toolbar"><span class="cnblogs_code_copy" style="line-height: 1.5 !important"><img style="border-style: none !important; border-color: rgba(221, 221, 221, 1)" src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码"></span></div>
</div>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">重启php-fpm:</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left"><span style="line-height: 1.8; color: rgba(255, 0, 0, 1); font-size: 16px">kill -USR2 42891</span></p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">OK了。</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left"> </p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">上面方案一般是没有生成php-fpm.pid文件时使用,如果要生成php-fpm.pid,使用下面这种方案:</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">上面master进程可以看到,matster使用的是/usr/local/php/etc/php-fpm.conf这个配置文件,<span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">cat /usr/local/php/etc/php-fpm.conf</span> 发现:</p>
<div class="cnblogs_code" style="border: 1px solid rgba(204, 204, 204, 1); overflow: auto; color: rgba(0, 0, 0, 1); font-family: "Courier New" !important; font-size: 12px !important">
<pre><span style="line-height: 1.5 !important">
; Pid </span><span style="color: rgba(0, 0, 255, 1); line-height: 1.5 !important">file</span><span style="line-height: 1.5 !important">
; Note: the default prefix is </span>/usr/local/php/<span style="line-height: 1.5 !important">var
; Default Value: none
;pid </span>= run/php-fpm.pid</pre>
</div>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left"> </p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left">pid文件路径应该位于/usr/local/php/var/run/php-fpm.pid,由于注释掉,所以没有生成,我们把注释去除,再kill -USR2 42891 重启php-fpm,便会生成pid文件,下次就可以使用以下命令重启,关闭php-fpm了:</p>
<p style="line-height: 1.8; color: rgba(51, 51, 51, 1); font-family: Georgia, "Times New Roman", Times, sans-serif; font-size: 14px; text-align: left"> php-fpm 关闭:<br><span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">kill -INT 'cat /usr/local/php/var/run/php-fpm.pid'</span><br>
php-fpm 重启:<br><span style="line-height: 1.8; color: rgba(255, 0, 0, 1)">kill -USR2 'cat /usr/local/php/var/run/php-fpm.pid'</span></p>
</div><br><br>
来源:https://www.cnblogs.com/kuangke/p/11133772.html 哇,感谢楼主的分享!刚好最近在配置服务器,这个帖子太及时了~
补充一点小经验:
如果觉得每次找PID太麻烦,可以把php-fpm加入系统服务,这样管理起来更方便:
# 添加服务
systemctl enable php-fpm
# 启动
systemctl start php-fpm
# 重启
systemctl restart php-fpm
# 停止
systemctl stop php-fpm
# 查看状态
systemctl status php-fpm
另外还有个小技巧,如果是用yum或apt安装的php-fpm,一般默认就配置好pid文件了,直接用上面的systemctl命令就行,不需要手动去找进程号~
总之谢谢楼主的总结,信号控制确实是很实用的方法! :handshake
頁:
[1]