由于 "Failed password for root from ...",Apache 无法启动

Apache won't start due to "Failed password for root from ..."

我在尝试启动 apache 时遇到此错误:

balter@balterbox:/etc/apache2$ sudo service apache2 restart
Job for apache2.service failed because the control process exited with error code.
See "systemctl  status apache2.service" and "journalctl  -xe" for details.

这是日志:

balter@balterbox:/etc/apache2$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Fri 2018-02-16 14:45:58 PST; 33s ago
  Process: 2534 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
      CPU: 34ms

balter@balterbox:~$ sudo journalctl -xe | tail
Feb 16 15:05:17 balterbox sshd[2777]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=###.###.###.###  user=root
Feb 16 15:05:19 balterbox sshd[2777]: Failed password for root from ###.###.###.### port 33812 ssh2
Feb 16 15:05:19 balterbox sshd[2779]: Connection closed by 114.32.120.181 port 47696 [preauth]
Feb 16 15:05:21 balterbox sshd[2777]: Failed password for root from ###.###.###.### port 33812 ssh2
Feb 16 15:05:24 balterbox sshd[2777]: Failed password for root from ###.###.###.### port 33812 ssh2
Feb 16 15:05:24 balterbox sshd[2777]: Received disconnect from ###.###.###.### port 33812:11:  [preauth]
Feb 16 15:05:24 balterbox sshd[2777]: Disconnected from authenticating user root 121.18.238.39 port 33812 [preauth]
Feb 16 15:05:24 balterbox sshd[2777]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=###.###.###.###  user=root
Feb 16 15:05:29 balterbox sudo[2781]:   balter : TTY=pts/2 ; PWD=/home/balter ; USER=root ; COMMAND=/bin/journalctl -xe
Feb 16 15:05:29 balterbox sudo[2781]: pam_unix(sudo:session): session opened for user root by balter(uid=0)

编辑: @Carlo 建议的结果:

balter@balterbox:~$ sudo apache2ctl restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Action 'restart' failed.
The Apache error log may have more information.
balter@balterbox:~$ sudo apachectl restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Action 'restart' failed.
The Apache error log may have more information.
balter@balterbox:~$ sudo /etc/init.d/apache2 restart
[....] Restarting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code.
See "systemctl  status apache2.service" and "journalctl  -xe" for details.

为什么打开日志失败?

重新启动服务器和 post Apache 状态。

尝试

  • sudo apache2ctl restart

  • sudo apachectl restart

  • sudo /etc/init.d/apache2 restart

  • post 你的 apache 在这些命令后记录

  • 另请参阅:Restart apache - Ask Ubuntu

  • 在配置文件中设置服务器名称。
  • 使用 kill 命令终止 apache 进程(因为你的日志显示该地址已被使用)。
  • 使用 sudo apache2ctl start 启动 apache。

尝试此命令 sudo killall -9 httpd 并使用 sudo service httpd start 启动 apache。 这篇文章是关于你的问题: Apache will not restart 如果不行,重装apache。

来自 Digital Ocean 的优秀人士:

You can ignore the "Failed password for root" errors in this situation - they're for the SSH server, not the web server. For that reason, you'd need to remove tail from the journalctl command and page up or down in the file to find some lines about Apache specifically.

The output of apache2ctl restart that you added shows the issue though - something is already listening on port 80, so Apache can't start listening for connections on that port number. You can run a command like sudo netstat -tnlp to get a list of running processes that are listening for connections and look for the one whose local address ends in :80. Stop that corresponding service and then try starting Apache again.

原来我也有 Nginx 运行(我安装它是为了做一些小实验)。关闭了 Nginx,并且能够启动 Apache。

此外,特别感谢@Carlo Federico Vescovo 的坚持。