如何在centos 7中“优雅地重启Apache”?

kit*_*irl 10 apache-2.4 centos7

我的系统是centos 7.4,apache 2.4
基于apache手册apachectl -k graceful应该是正常重启apache的方法,但我收到如下通知:

[root@localhost root]# apachectl -k graceful
Passing arguments to httpd using apachectl is no longer supported.
You can only start/stop/restart httpd using this script.
If you want to pass extra arguments to httpd, edit the
/etc/sysconfig/httpd config file.
Run Code Online (Sandbox Code Playgroud)

有什么问题?
如何Graceful Restart Apache在centos 7?

Jay*_*uer 6

请在 apachectl 上查看此页面,它似乎是一个新版本:https : //httpd.apache.org/docs/2.4/programs/apachectl.html

无需传递“-k”参数。 apachectl graceful (没有 -k)在我的 Centos7 机器和 Centos6 机器上正常重新加载/重启工作正常。

显然没有人更新她的问题中引用的手册页 OP,该页仍然存在,并且命令在整个(apachectl -k graceful、apachectl -k restart 等)中都使用“-k”参数显示。该页面上没有解释然而,关于 -k 参数实际上在做什么。

但是在较新的页面上有关于 apachectl graceful 的注释:

这相当于 apachectl -k 优雅。

在我的 Centos6 机器上,我一直在使用命令service httpd graceful. 这不再适用于 Centos7。apachectl graceful在 Centos 7 上使用它是必要的apachectl graceful。在 Centos 6 上也可以正常工作。


Rob*_*ade 5

大多数基于 systemd 的发行版都使用修补apachectl脚本 [1],将命令委托给systemctl. 修补后的apachectl命令不支持“传递”操作模式,在该模式中,参数传递到httpd. apachectl 手册页反映了上游未修补的apachectl命令,因此存在差异。

我建议使用systemctl[2] 抽象来启动和停止服务。

因此,要在 Centos 7 和其他使用 systemd 的 Linux 发行版上正常重启 Apache HTTP Server,请使用:

sudo systemctl reload httpd.service
Run Code Online (Sandbox Code Playgroud)

在幕后,这会调用httpd -k graceful. 您可以使用以下命令验证这一点:

$ systemctl cat httpd.service | grep -F ExecReload
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
Run Code Online (Sandbox Code Playgroud)

要停止 Apache HTTP 服务器:

sudo systemctl stop httpd.service
Run Code Online (Sandbox Code Playgroud)

它在幕后SIGWINCHhttpd进程发送信号。

可以使用以下命令验证这一点:

$ systemctl cat httpd.service \
  | grep -E --before-context=1 'ExecStop|KillSignal'
# Send SIGWINCH for graceful stop
KillSignal=SIGWINCH
Run Code Online (Sandbox Code Playgroud)

[3]手册systemd.service说,在这种情况下,如果ExecStop未指定该选项,“通过发送 中指定的信号来终止进程KillSignal”。

为什么SIGWINCH?因为,根据https://bz.apache.org/bugzilla/show_bug.cgi?id=50669,Apache 使用该SIGWINCH信号作为“正常关闭”触发器。

您可能会发现对探索服务选项有用的另一个命令是show-p, --property选项组合的命令,如下所示:

$ systemctl show httpd.service -p ExecStart -p ExecReload -p ExecStop -p KillSignal
Run Code Online (Sandbox Code Playgroud)

[1] https://git.centos.org/blob/rpms!httpd.git/c7/SOURCES!httpd-2.4.3-apctl-systemd.patch
[2] https://www.freedesktop.org/software /systemd/man/systemctl.html
[3] https://www.freedesktop.org/software/systemd/man/systemd.service.html