简体   繁体   English

带有 /ping 路由的 php-fpm 容器 livenessProbe

[英]php-fpm container livenessProbe with /ping route

Lately we've been running into some issues with our php-fpm processes spinning out of control and causing the site to become unresponsive.最近我们遇到了一些问题,我们的 php-fpm 进程失控并导致站点无响应。 There's some obvious php-fpm configuration tooling that needs to be done, but I'd also like to implement a reasonable livenessProbe health check for the php-fpm container that will restart the container when the probe fails.有一些明显的 php-fpm 配置工具需要完成,但我还想为 php-fpm 容器实现合理的 livenessProbe 健康检查,当探测失败时,它将重新启动容器。

I've dug up several resources on how to ping the server as a health check (eg https://easyengine.io/tutorials/php/fpm-status-page/ ), but I have yet to find a good answer on what to be on the lookout for.我已经挖掘了一些关于如何ping 服务器作为健康检查的资源(例如https://easyengine.io/tutorials/php/fpm-status-page/ ),但我还没有找到关于什么的好答案需要注意。 Will the /ping route return something other than 'pong' if the server is effectively dead?如果服务器实际上已死,/ping 路由是否会返回“pong”以外的其他内容? Will it just time out?它会超时吗? Assuming the latter, what is a reasonable timeout limit?假设是后者,合理的超时限制是多少?

Running some tests of my own, I notice that a healthy php-fpm server will return the 'pong' response quickly:运行我自己的一些测试,我注意到一个健康的 php-fpm 服务器将快速返回“pong”响应:

# time curl localhost/ping
pong
real    0m0.040s
user    0m0.006s
sys 0m0.001s

I simulated heavy load and indeed it took 1-3 seconds for the 'pong' response, and that coincided with the site becoming unresponsive.我模拟了重负载,确实需要 1-3 秒的“乒乓”响应时间,而这恰逢站点变得无响应。 Based on that I drew up a draft of a livenessProbe that will fail and restart the container if the liveness probe script takes longer than 2 seconds on 2 consecutive probes:基于此,我草拟了一个 livenessProbe 的草稿,如果 liveness 探针脚本在 2 个连续的探针上花费的时间超过 2 秒,它将失败并重新启动容器:

livenessProbe:
  exec:
    command:
    - sh
    - -c
    - timeout 2 /var/www/livenessprobe.sh
  initialDelaySeconds: 15
  periodSeconds: 3
  successThreshold: 1
  failureThreshold: 2

And the probe script is simply this (There are reasons why this needs to be a shell script and not a direct httpGet from the livenessProbe that I won't get into):探针脚本就是这样(有一些原因,为什么这需要是一个 shell 脚本,而不是来自 livenessProbe 的直接 httpGet,我不会进入):

  #!/bin/bash

  curl -s localhost/ping

Now I don't know if I'm being too aggressive or too conservative.现在我不知道是我太激进还是太保守了。 I'll be running a canary deploy to test this, but in the meantime I'd like to get some feedback from others that have implemented health checks on php-fpm servers, bonus points if it's in a Kubernetes context.我将运行金丝雀部署来测试这一点,但与此同时,我想从其他人那里获得一些反馈,这些人在 php-fpm 服务器上实施了健康检查,如果它在 Kubernetes 上下文中,则可以获得奖励积分。

If someone is still interested in this topic.如果有人仍然对这个话题感兴趣。 I was looking into a sort of the same thing (php-fpm monitoring in combination with pods running in kubernetes).我正在研究类似的事情(php-fpm 监控与在 kubernetes 中运行的 pod 相结合)。

I added the following health-check setup https://github.com/renatomefi/php-fpm-healthcheck to my container (the one running php-fpm) for checking if php-fpm is playing along nicely :) works pretty simple and gets the job done (marking the the container as "bad" when some of the values are getting out of your predefined limits)我将以下运行状况检查设置https://github.com/renatomefi/php-fpm-healthcheck 添加到我的容器(运行 php-fpm 的容器)中,以检查 php-fpm 是否运行良好:) 工作起来非常简单且完成工作(当某些值超出预定义的限制时,将容器标记为“坏”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM