大网数据广告活动
服务器运维问答

CentOs 7: http won't start at boot if it listens to a specific IP address

· 52CE 我爱测

I have this in my httpd.conf: Listen 216.XX.YY.ZZZZ:80 Just to make sure, I made sure httpd is enabled at boot: systemctl httpd enable When the system boots , I have: systemctl status httpd ● httpd.service - The Apache HTTP Serve…

问题原文

原帖链接 · Merc · CC BY-SA 3.0

I have this in my httpd.conf:

Listen 216.XX.YY.ZZZZ:80

Just to make sure, I made sure httpd is enabled at boot:

systemctl httpd enable

When the system boots, I have:

systemctl status httpd

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2017-02-23 22:21:03 PST; 8min ago
  Process: 719 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 719 (code=exited, status=1/FAILURE)

Feb 23 22:21:00 centosXXXXXX.aspadmin.net systemd[1]: Starting The Apache HTTP Server...
Feb 23 22:21:03 centosXXXXXX.aspadmin.net httpd[719]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address 216.XX.YY.XXX:80
Feb 23 22:21:03 centosXXXXXX.aspadmin.net httpd[719]: no listening sockets available, shutting down
Feb 23 22:21:03 centosXXXXXX.aspadmin.net httpd[719]: AH00015: Unable to open logs
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: Failed to start The Apache HTTP Server.
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: Unit httpd.service entered failed state.
Feb 23 22:21:03 centosXXXXXX.aspadmin.net systemd[1]: httpd.service failed.

I can then start it by running:

systemctl start httpd

And everything works:

systemctl status httpd


● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-02-23 22:31:53 PST; 3s ago
 Main PID: 2804 (httpd)
   Status: "Processing requests..."
   CGroup: /system.slice/httpd.service
       ├─2804 /usr/sbin/httpd -DFOREGROUND
       ├─2805 /usr/sbin/httpd -DFOREGROUND
       ├─2806 /usr/sbin/httpd -DFOREGROUND
       ├─2808 /usr/sbin/httpd -DFOREGROUND
       ├─2824 /usr/sbin/httpd -DFOREGROUND
       └─2831 /usr/sbin/httpd -DFOREGROUND

Feb 23 22:31:53 centosXXXXXX.aspadmin.net systemd[1]: Starting The Apache HTTP Server...
Feb 23 22:31:53 centosXXXXXX.aspadmin.net httpd[2804]: AH00558: httpd:     Feb 23 22:31:53 centosXXXXXX.aspadmin.net systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

The IP is assigned to eth0 using a normal network script in /etc/sysconfig/network-scripts/ifcfg-eth0.

Checking /lib/systemd/system/httpd.service I have:

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

The only similar problem on the net is here: https://unix.stackexchange.com/questions/207063/apache-httpd-failing-to-start-on-boot-centos-7 However, their advice:

systemctl enable NetworkManager-wait-online.service
Failed to execute operation: No such file or directory

Doesn't seem to work.

I am totally lost.

已采纳解答

原帖链接 · Merc · CC BY-SA 3.0

As it turns out, you need to use NetworkManager for this to work, since you want to wait for the IPs to actually be available. NetworkManager is not installed by default in CentOs 7.

So:

# yum install NetworkManager

Enable it:

systemctl enable NetworkManager-wait-online

Then:

# systemctl edit httpd.service

And add:

After=network.target NetworkManager-wait-online.service remote-fs.target nss-lookup.target

At this point, HTTPD will only start once the IP is assigned to the interface and bingo, it will actually start.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。