重载生产服务器上的php-fpm,而不影响当前请求。

huangapple go评论73阅读模式
英文:

Reloading php-fpm on a production server without affecting current requests

问题

我们有一台配置非常高的生产服务器,为了充分利用这些资源,我们想要更改默认的php-fpm设置,比如pm.max_children, pm.max_spare_servers, pm.start_servers和pm.min_spare_servers

我们想尽快应用这些更改,但有很多请求,我们希望在不引起混乱的情况下进行更改。

systemctl reload命令是否可以在不影响当前请求的情况下完成这项任务?
我对重新加载如何工作感到困惑,它会等待所有活动请求完成吗?在这种情况下,我认为我们将等待很长时间。

使用重新加载命令安全吗?是否有其他方法来执行此任务?

编辑: 我还不太信任Chat-GPT。

英文:

We have a production server with very high specs and to utilize these resources, we want to change the default php-fpm settings like pm.max_children, pm.max_spare_servers, pm.start_servers, and pm.min_spare_servers.

We want to apply this change ASAP, but there are many requests, and we want to make the change without causing a mess.

Can systemctl reload command do this without affecting the current requests?
I'm confused about how the reload works actually, will it wait until all the active requests finish? in this case, I think we will wait a long time.

Is it safe to use reload command? Are there rather ways to do this task?

Edit: I don't trust Chat-GPT yet

答案1

得分: 2

根据man页面,'systemctl reload php-fpm' 应该是你要找的:

reload PATTERN...

要求命令行上列出的所有单元重新加载其配置。请注意,这将重新加载特定于服务的配置,而不是systemd的单元配置文件。如果您想要systemd重新加载一个单元的配置文件,请使用daemon-reload命令。换句话说,在Apache的示例中,这将重新加载Web服务器中的Apache的httpd.conf文件,而不是apache.service systemd单元文件。
此命令不应与daemon-reload命令混淆。

restart PATTERN...

停止然后启动命令行上指定的一个或多个单元。如果单元尚未运行,它们将被启动。
请注意,使用此命令重新启动一个单元不一定会在再次启动之前清除所有单元的资源。例如,只要单元有一个挂起的作业,每个服务文件描述符存储设施(请参见systemd.service(5)中的FileDescriptoreStoreMax=)将保持完整,并且仅在单元完全停止并不再挂起作业时才会清除。如果打算在重新启动操作期间刷新文件描述符存储,应该发出显式的systemctl stop命令,然后是systemctl start。

还有一个这个旧帖子显示php-fpm支持使用reload选项在SysV系统上进行优雅重启。

英文:

Based on the man page 'systemctl reload php-fpm' should be what you're looking for :

reload PATTERN...
>Asks all units listed on the command line to reload their
configuration. Note that this will reload the service-specific
configuration, not the unit configuration file of systemd. If you
want systemd to reload the configuration file of a unit, use the
daemon-reload command. In other words: for the example case of
Apache, this will reload Apache's httpd.conf in the web server, not
the apache.service systemd unit file.
This command should not be confused with the daemon-reload command.

restart PATTERN...
>Stop and then start one or more units specified on the command
line. If the units are not running yet, they will be started.
Note that restarting a unit with this command does not necessarily
flush out all of the unit's resources before it is started again.
For example, the per-service file descriptor storage facility (see
FileDescriptoreStoreMax= in systemd.service(5)) will remain intact
as long as the unit has a job pending, and is only cleared when the
unit is fully stopped and no jobs are pending anymore. If it is
intended that the file descriptor store is flushed out, too, during
a restart operation an explicit systemctl stop command followed by
systemctl start should be issued.

There's also this old post showing that php-fpm supports graceful restart on SysV systems using the reload option.

huangapple
  • 本文由 发表于 2023年4月20日 04:13:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058462.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定