systemctl start httpd 卡住
systemctl start httpd 卡住
根据 Apache Module mod_systemd 模块的说明,编译时添加了 --enable-systemd
参数;
安装完成之后,注册为 systemd 服务,通过 systemctl start httpd 启动时命令行卡住:
[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost ~]#
[root@localhost ~]# systemctl start httpd.service
^C
[root@localhost ~]#
通过 status 查看服务状态,刚开始是 activating (start)
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: activating (start) since Thu 2024-12-14 09:58:25 CST; 12s ago
Main PID: 1792 (httpd)
Tasks: 82 (limit: 23008)
Memory: 33.6M
CGroup: /system.slice/httpd.service
├─1792 /www/server/apache2/bin/httpd -D FOREGROUND -k start
├─1793 /www/server/apache2/bin/httpd -D FOREGROUND -k start
├─1794 /www/server/apache2/bin/httpd -D FOREGROUND -k start
└─1795 /www/server/apache2/bin/httpd -D FOREGROUND -k start
Dec 12 09:58:25 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
[root@localhost ~]#
过了一段时间再查看变成了 failed (Result: timeout)
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: failed (Result: timeout) since Thu 2024-12-14 09:59:55 CST; 49s ago
Process: 1792 ExecStart=/www/server/apache2/bin/httpd -D FOREGROUND -k start (code=exited, status=0/SUCCESS)
Main PID: 1792 (code=exited, status=0/SUCCESS)
Dec 14 09:58:25 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Dec 14 09:59:55 localhost.localdomain systemd[1]: httpd.service: start operation timed out. Terminating.
Dec 14 09:59:55 localhost.localdomain systemd[1]: httpd.service: Failed with result 'timeout'.
Dec 14 09:59:55 localhost.localdomain systemd[1]: Failed to start The Apache HTTP Server.
[root@localhost ~]#
[root@localhost ~]# journalctl -xe
-- Subject: Unit succeeded
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The unit NetworkManager-dispatcher.service has successfully entered the 'dead' state.
Dec 14 09:57:32 localhost.localdomain systemd[1]: systemd-hostnamed.service: Succeeded.
-- Subject: Unit succeeded
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The unit systemd-hostnamed.service has successfully entered the 'dead' state.
Dec 14 09:58:16 localhost.localdomain systemd[1]: Reloading.
Dec 14 09:58:25 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit httpd.service has begun start-up
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has begun starting up.
Dec 14 09:59:55 localhost.localdomain systemd[1]: httpd.service: start operation timed out. Terminating.
Dec 14 09:59:55 localhost.localdomain systemd[1]: httpd.service: Failed with result 'timeout'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The unit httpd.service has entered the 'failed' state with result 'timeout'.
Dec 14 09:59:55 localhost.localdomain systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
--
-- The result is failed.
Dec 14 10:01:01 localhost.localdomain CROND[1898]: (root) CMD (run-parts /etc/cron.hourly)
Dec 14 10:01:01 localhost.localdomain run-parts[1901]: (/etc/cron.hourly) starting 0anacron
Dec 14 10:01:01 localhost.localdomain anacron[1907]: Anacron started on 2024-12-14
Dec 14 10:01:01 localhost.localdomain anacron[1907]: Will run job `cron.daily' in 36 min.
Dec 14 10:01:01 localhost.localdomain anacron[1907]: Will run job `cron.weekly' in 56 min.
Dec 14 10:01:01 localhost.localdomain anacron[1907]: Will run job `cron.monthly' in 76 min.
Dec 14 10:01:01 localhost.localdomain anacron[1907]: Jobs will be executed sequentially
Dec 14 10:01:02 localhost.localdomain run-parts[1909]: (/etc/cron.hourly) finished 0anacron
lines 2288-2328/2328 (END)
httpd.service: start operation timed out. Terminating.
启动超时,一般情况下是 apache 加载模块或者配置导致的,编译安装时添加了 --enable-systemd
参数,检查下 apache 的配置文件:
[root@localhost ~]# grep systemd /www/server/etc/httpd/httpd.conf
#LoadModule systemd_module modules/mod_systemd.so
[root@localhost ~]#
并没有开启 systemd_module 模块,注册为 systemd 服务时需要加载此模块,修改配置文件,打开 systemd_module 模块,再启动 httpd 服务就正常了,服务状态为 active (running):
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]#
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2024-12-14 10:06:08 CST; 2s ago
Main PID: 1955 (httpd)
Status: "Processing requests..."
Tasks: 82 (limit: 23008)
Memory: 31.5M
CGroup: /system.slice/httpd.service
├─1955 /www/server/apache2/bin/httpd -D FOREGROUND -k start
├─1956 /www/server/apache2/bin/httpd -D FOREGROUND -k start
├─1957 /www/server/apache2/bin/httpd -D FOREGROUND -k start
└─1958 /www/server/apache2/bin/httpd -D FOREGROUND -k start
Dec 14 10:06:08 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Dec 14 10:06:08 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
[root@localhost ~]#
作者:zhpj
出处:https://www.cnblogs.com/zhpj/p/18606957/systemctl-start-httpd-stuck-z1xch7c
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库