Centos7

如何在 CentOS7 上首次啟動 Apache

  • July 11, 2017

sudo yum update我已經使用並安裝了yumsudo yum install httpd

我編輯了 httpd.conf,所以 ServerName 是我遠端訪問的 Web 伺服器的 IP 地址。

當我嘗試重新啟動 httpd 時,using sudo service httpd restart我收到以下錯誤消息:

httpd.service 的作業失敗,因為控制程序以錯誤程式碼退出。有關詳細資訊,請參閱“systemctl status httpd.service”和“journalctl -xe”。

systemctl -l status httpd.service 返回以下內容:

httpd.service - The Apache HTTP Server
  Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Tue 2017-07-11 14:20:39 EDT; 1min 22s ago
    Docs: man:httpd(8)
          man:apachectl(8)
 Process: 3275 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
 Process: 3273 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=0/SUCCESS)
Main PID: 3273 (code=exited, status=0/SUCCESS)

Jul 11 14:20:39 blondie systemd[1]: Starting The Apache HTTP Server...
Jul 11 14:20:39 blondie httpd[3273]: httpd (pid 2260) already running
Jul 11 14:20:39 blondie kill[3275]: kill: cannot find process ""
Jul 11 14:20:39 blondie systemd[1]: httpd.service: control process exited, code=exited status=1
Jul 11 14:20:39 blondie systemd[1]: Failed to start The Apache HTTP Server.
Jul 11 14:20:39 blondie systemd[1]: Unit httpd.service entered failed state.
Jul 11 14:20:39 blondie systemd[1]: httpd.service failed.

執行 journalctl -xe 返回:

Unit user-0.slice has begun starting up.
Jul 11 14:10:01 blondie systemd[1]: Started Session 7 of user root.
-- Subject: Unit session-7.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-7.scope has finished starting up.
-- 
-- The start-up result is done.
Jul 11 14:10:01 blondie systemd[1]: Starting Session 7 of user root.
-- Subject: Unit session-7.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-7.scope has begun starting up.
Jul 11 14:10:01 blondie CROND[3154]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 11 14:10:01 blondie systemd[1]: Removed slice user-0.slice.
-- Subject: Unit user-0.slice has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has finished shutting down.
Jul 11 14:10:01 blondie systemd[1]: Stopping user-0.slice.
-- Subject: Unit user-0.slice has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has begun shutting down.
Jul 11 14:10:40 blondie sudo[3162]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/bin/systemctl status
Jul 11 14:13:09 blondie sudo[3164]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/sbin/service httpd -
Jul 11 14:16:19 blondie sudo[3195]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/bin/nano /etc/httpd/
Jul 11 14:16:40 blondie sudo[3212]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/bin/nano /etc/httpd/
Jul 11 14:18:19 blondie sudo[3215]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/sbin/apachectl confi
Jul 11 14:19:14 blondie sudo[3221]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/bin/nano /etc/httpd/
Jul 11 14:20:01 blondie systemd[1]: Created slice user-0.slice.
-- Subject: Unit user-0.slice has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has finished starting up.
-- 
-- The start-up result is done.
Jul 11 14:20:01 blondie systemd[1]: Starting user-0.slice.
-- Subject: Unit user-0.slice has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has begun starting up.
Jul 11 14:20:01 blondie systemd[1]: Started Session 8 of user root.
-- Subject: Unit session-8.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-8.scope has finished starting up.
-- 
-- The start-up result is done.
Jul 11 14:20:01 blondie systemd[1]: Starting Session 8 of user root.
-- Subject: Unit session-8.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit session-8.scope has begun starting up.
Jul 11 14:20:01 blondie CROND[3225]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 11 14:20:01 blondie systemd[1]: Removed slice user-0.slice.
-- Subject: Unit user-0.slice has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has finished shutting down.
Jul 11 14:20:01 blondie systemd[1]: Stopping user-0.slice.
-- Subject: Unit user-0.slice has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit user-0.slice has begun shutting down.
Jul 11 14:20:14 blondie sudo[3251]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/bin/nano /etc/httpd/
Jul 11 14:20:39 blondie sudo[3255]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/sbin/service httpd r
Jul 11 14:20:39 blondie polkitd[637]: Registered Authentication Agent for unix-process:3256:362038 (system bus name :1.63 [/usr
Jul 11 14:20:39 blondie systemd[1]: Starting The Apache HTTP Server...
-- Subject: Unit httpd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has begun starting up.
Jul 11 14:20:39 blondie httpd[3273]: httpd (pid 2260) already running
Jul 11 14:20:39 blondie kill[3275]: kill: cannot find process ""
Jul 11 14:20:39 blondie systemd[1]: httpd.service: control process exited, code=exited status=1
Jul 11 14:20:39 blondie systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit httpd.service has failed.
-- 
-- The result is failed.
Jul 11 14:20:39 blondie systemd[1]: Unit httpd.service entered failed state.
Jul 11 14:20:39 blondie systemd[1]: httpd.service failed.
Jul 11 14:20:39 blondie polkitd[637]: Unregistered Authentication Agent for unix-process:3256:362038 (system bus name :1.63, ob
Jul 11 14:22:01 blondie sudo[3280]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/bin/systemctl -l sta
Jul 11 14:23:13 blondie sudo[3283]: admin1 : TTY=pts/0 ; PWD=/home/admin1 ; USER=root ; COMMAND=/bin/journalctl -xe

我已經嘗試刪除 httpd 並重新安裝,但我無法讓 httpd 重新啟動

看起來您可能有一個孤立的 PID 文件。httpd 有一個 PID,但 kill 沒有看到它的程序。

檢查top是否有任何殭屍程序。也ps aux | grep httpd只是看看正在執行什麼。

如果是這種情況,您將不得不殺死父程序以清理它(ps -Hfwepstree -paul找到它),或重新啟動。

希望你可以做一個 systemctl start。

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