Centos

CentOs 7:如果 http 偵聽特定的 IP 地址,它將不會在啟動時啟動

  • February 25, 2017

我的 httpd.conf 中有這個:

Listen 216.XX.YY.ZZZZ:80

只是為了確保,我確保在啟動時啟用了 httpd:

systemctl httpd enable

當系統啟動時,我有:

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.

然後我可以通過執行來啟動它:

systemctl start httpd

一切正常:

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.

使用. 中的普通網路腳本將 IP 分配給 eth0 /etc/sysconfig/network-scripts/ifcfg-eth0

檢查/lib/systemd/system/httpd.service我有:

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

網上唯一類似的問題在這裡:https ://unix.stackexchange.com/questions/207063/apache-httpd-failing-to-start-on-boot-centos-7但是,他們的建議:

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

似乎不起作用。

我完全迷路了。

事實證明,您需要使用 NetworkManager 才能工作,因為您想等待 IP實際可用。CentOs 7 預設不安裝 NetworkManager。

所以:

# yum install NetworkManager

啟用它:

systemctl enable NetworkManager-wait-online

然後:

# systemctl edit httpd.service

並添加:

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

此時,HTTPD 只會在 IP 分配給介面和 bingo 後才會啟動,它才會真正啟動。

引用自:https://serverfault.com/questions/834616