php7.0-fpm启动,PHP-FPM 故障重现与排除及开启php-debug日志的方法

起因

之前在网上看到了这个报错,对此很感兴趣,于是决定学习一下这个点,报错如下

Shell

[19-Oct-2016 15:57:14] ERROR: [/etc/php5/fpm/php-fpm.conf:27] unknown entry 'catch_workers_output'

[19-Oct-2016 15:57:14] ERROR: failed to load configuration file '/etc/php5/fpm/php-fpm.conf'

[19-Oct-2016 15:57:14] ERROR: FPM initialization failed

1

2

3[19-Oct-201615:57:14]ERROR:[/etc/php5/fpm/php-fpm.conf:27]unknownentry'catch_workers_output'

[19-Oct-201615:57:14]ERROR:failedtoloadconfigurationfile'/etc/php5/fpm/php-fpm.conf'

[19-Oct-201615:57:14]ERROR:FPMinitializationfailed

思路

当我们遇到问题是先确认故障的程序和实例是那个,nginx返回值为502badgartway,php-fpm不正常,重启php-fpm进程无效果,检查端口,发现端口没有启动寻找报错只能通过dmesg 查询至如下(why?点我知晓):

[6819070.815161]init: php5-fpm main process ended, respawning

[6819070.861943]init: php5-fpm main process (25401) terminated with status 78

[6819070.861955]init: php5-fpm main process ended, respawning

[6819070.910152]init: php5-fpm main process (25409) terminated with status 78

由上面报错可以看出是进程故障退出,一般是配置问题

需要使用php(5)-fpm --fpm-config 配置文件 确认报错,类似 nginx -t

经过就求证是参数设定的组出错了可以发现:

1

2

3

4

5

6

7

8[6819070.815161]init:php5-fpmmainprocessended,respawning

[6819070.861943]init:php5-fpmmainprocess(25401)terminatedwithstatus78

[6819070.861955]init:php5-fpmmainprocessended,respawning

[6819070.910152]init:php5-fpmmainprocess(25409)terminatedwithstatus78

由上面报错可以看出是进程故障退出,一般是配置问题

需要使用php(5)-fpm--fpm-config配置文件确认报错,类似nginx-t

经过就求证是参数设定的组出错了可以发现:

[root@web-lnmp-01 etc]# grep '\[' php-fpm.conf

[global]

[www]

; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on

; '[::]:port' - to listen on a TCP socket to all addresses

;env[HOSTNAME] = $HOSTNAME

;env[PATH] = /usr/local/bin:/usr/bin:/bin

;env[TMP] = /tmp

;env[TMPDIR] = /tmp

;env[TEMP] = /tmp

;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com

;php_flag[display_errors] = off

;php_admin_value[error_log] = /var/log/fpm-php.www.log

;php_admin_flag[log_errors] = on

;php_admin_value[memory_limit] = 32M

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15[root@web-lnmp-01etc]# grep '\[' php-fpm.conf

[global]

[www]

;'[ip:6:addr:ess]:port'-tolistenonaTCPsockettoaspecificIPv6addresson

;'[::]:port'-tolistenonaTCPsockettoalladdresses

;env[HOSTNAME]=$HOSTNAME

;env[PATH]=/usr/local/bin:/usr/bin:/bin

;env[TMP]=/tmp

;env[TMPDIR]=/tmp

;env[TEMP]=/tmp

;php_admin_value[sendmail_path]=/usr/sbin/sendmail-t-i-fwww@my.domain.com

;php_flag[display_errors]=off

;php_admin_value[error_log]=/var/log/fpm-php.www.log

;php_admin_flag[log_errors]=on

;php_admin_value[memory_limit]=32M

php-fpm.conf 配置有两个组:[global ][www]

当配置在[global]组中时,catch_workers_output无法生效并且无法正常启动运行php-fpm

[root@web-lnmp-01 etc]# /application/php/sbin/php-fpm --fpm-config /application/php/etc/php-fpm.conf

[19-Oct-2017 22:28:13] ERROR: [/application/php/etc/php-fpm.conf:26] unknown entry 'catch_workers_output'

[19-Oct-2017 22:28:13] ERROR: failed to load configuration file '/application/php/etc/php-fpm.conf'

[19-Oct-2017 22:28:13] ERROR: FPM initialization failed

1

2

3

4[root@web-lnmp-01etc]# /application/php/sbin/php-fpm --fpm-config /application/php/etc/php-fpm.conf

[19-Oct-201722:28:13]ERROR:[/application/php/etc/php-fpm.conf:26]unknownentry'catch_workers_output'

[19-Oct-201722:28:13]ERROR:failedtoloadconfigurationfile'/application/php/etc/php-fpm.conf'

[19-Oct-201722:28:13]ERROR:FPMinitializationfailed

patch--文件设置

直接扒日志无需在系统输出中寻找报错的方法

nginx与apache不一样,由于在apache中一般使用modphp调用的模式而非fastcgi可以直接指定php的错误日志,那样在php执行中的错误信息

就直接输入到php的错误日志中,可以方便查询。在nginx中事情就变成另一回事了:nginx只对页面的访问做access记录日志。不会有php的error log

信息。nginx把对php的请求发给php-fpm fastcgi进程来处理,默认的php-fpm只会输出php-fpm的错误信息,在php-fpm的errors log里 也看不到php的errorlog。原因是php-fpm的配置文件php-fpm.conf中默认是关闭worker进程的错误输出,直接把他们重定向到/dev/null, 所以我们在nginx的error log 和php-fpm的errorlog都看不到php的错误日志。 所以我们要进行如下的设置就能查看到nginx下php-fpm不记录php错误日志的方法:

1.修改php-fpm.conf中的配置,如果没有请增加:

Shell

[global]

; Note: the default prefix is /usr/local/php/var

error_log = log/php_error_log

[www]

catch_workers_output = yes

1

2

3

4

5[global]

;Note:thedefaultprefixis/usr/local/php/var

error_log=log/php_error_log

[www]

catch_workers_output=yes

2.修改php.ini中配置,没有则增加

log_errors = On

error_log = "/usr/local/php/var/log/error_log"

error_reporting=E_ALL&~E_NOTICE

1

2

3log_errors=On

error_log="/usr/local/php/var/log/error_log"

error_reporting=E_ALL&~E_NOTICE

3.重启php-fpm, 当PHP执行错误时就能看到错误日志在”/usr/local/lnmp/php/var/log/php_error_log”中了

如果出现:

[root@localhost etc]# service php-fpm restart

Gracefully shutting down php-fpm . done

Starting php-fpm [17-Apr-2014 18:40:52] ERROR: [/usr/local/php/etc/php-fpm.conf:5] unknown entry 'catch_workers_

[17-Apr-2014 18:40:52] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'

[17-Apr-2014 18:40:52] ERROR: FPM initialization failed

failed

1

2

3

4

5

6[root@localhostetc]# service php-fpm restart

Gracefullyshuttingdownphp-fpm.done

Startingphp-fpm[17-Apr-201418:40:52]ERROR:[/usr/local/php/etc/php-fpm.conf:5]unknownentry'catch_workers_

[17-Apr-2014 18:40:52] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'

[17-Apr-201418:40:52]ERROR:FPMinitializationfailed

failed

那请在第一步的时候,认真将配置写入相对应的组中,不然就出现上面的:ERROR: [/usr/local/php/etc/php-fpm.conf:5] unknown entry‘catch_workers_output’

总结

1、当系统实例出现问题是先确认报错码和日志,对服务要检测端口。

2、服务的配置文件,要注意参数不要放错组、模块,如php、mysql的组,nginx的server、标签模块

3、学习运维有余力要分析具体原因,会重现故障,并且善于总结

4、学会不断学习,比如本次添加的直接输出php日志的方法

历史上的今天:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值