Httpd

對 -DFOREGROUND 和 Apache 感到困惑

  • February 18, 2022

所以我剛剛使用 Yum 在新的 CentOS 7 伺服器上安裝了 Apache。我以前安裝過 Apache 很多次,但我從來沒有見過這個:當我現在執行ps aux時,它總是顯示

/usr/sbin/httpd -DFOREGROUND

Google告訴我這意味著該程序將在前台執行並且不會與外殼分離,但我真的不明白這意味著什麼——如果我關閉我的外殼,Apache 會死嗎?

我只想獲得正常的 Apache 行為,並讓 httpd 像往常一樣執行,在後台執行,我需要禁用 DFOREGROUND 嗎?(我不知道如何順便說一句)

-DFOREGROUND選項確實意味著 Apache 不會分叉,但這並不意味著它已附加到您的 shell!

該服務在您執行時由 systemd 啟動systemctl start httpd(或舊式方式,service httpd start)。它是 Apache 所附加的 systemd,並且 systemd 將該程序作為其子程序之一進行管理。這樣做是為了讓 systemd 可以輕鬆判斷 Apache 是否崩潰,而無需輪詢 pid 文件或進行其他令人討厭的黑客行為。這也意味著systemd 能夠在Apache崩潰時自動重新啟動它。

執行systemctl status httpd以查看其狀態。一個範例如下所示:

# systemctl status httpd
httpd.service - The Apache HTTP Server
  Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
  Active: active (running) since Sat 2014-07-12 01:53:50 UTC; 1 weeks 3 days ago
 Process: 21400 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
Main PID: 390 (httpd)
  Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
  CGroup: /system.slice/httpd.service
          ├─  390 /usr/sbin/httpd -DFOREGROUND
          ├─15379 /usr/sbin/httpd -DFOREGROUND
          ├─15858 /usr/sbin/httpd -DFOREGROUND
          ├─16809 /usr/sbin/httpd -DFOREGROUND
          ├─16944 /usr/sbin/httpd -DFOREGROUND
          ├─17079 /usr/sbin/httpd -DFOREGROUND
          ├─17351 /usr/sbin/httpd -DFOREGROUND
          ├─17487 /usr/sbin/httpd -DFOREGROUND
          ├─17772 /usr/sbin/httpd -DFOREGROUND
          ├─17908 /usr/sbin/httpd -DFOREGROUND
          └─18043 /usr/sbin/httpd -DFOREGROUND

Jul 12 01:53:50 hozen httpd[390]: AH02559: The SSLCertificateChai...d
Jul 12 01:53:50 hozen httpd[390]: AH00558: httpd: Could not relia...e
Jul 12 01:53:50 hozen systemd[1]: Started The Apache HTTP Server.
Jul 13 03:30:02 hozen systemd[1]: Reloading The Apache HTTP Server.
Jul 13 03:30:02 hozen httpd[9332]: AH02559: The SSLCertificateCha...d
Jul 13 03:30:02 hozen systemd[1]: Reloaded The Apache HTTP Server.
Jul 21 03:19:02 hozen systemd[1]: Reloading The Apache HTTP Server.
Jul 21 03:19:02 hozen httpd[21400]: AH02559: The SSLCertificateCh...d
Jul 21 03:19:02 hozen systemd[1]: Reloaded The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

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