我在安装apache2 Ubuntu 12.10时遇到了这个错误。
这是apache2的一个bug。它在后台卡住了。以下是我对软件中可能存在的bug的解释。
这是我遇到的错误:
el@titan:~$ sudo service apache2 start
* Starting web server apache2
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
[fail]
地址已被使用?是什么在使用它?快来检查一下:
el@titan:~$ grep -ri listen /etc/apache2
/etc/apache2/apache2.conf:# supposed to determine listening ports for incoming connections, and which
/etc/apache2/apache2.conf:# Include list of ports to listen on and which to use for name based vhosts
/etc/apache2/ports.conf:Listen 80
/etc/apache2/ports.conf: Listen 443
/etc/apache2/ports.conf: Listen 443
这意味着apache2正在阻止apache2启动。真是奇怪。这将确认:
el@titan:~$ ps -ef | grep apache2
root 1146 954 0 15:51 ? 00:00:00 /bin/sh /etc/rc2.d/S91apache2 start
root 1172 1146 0 15:51 ? 00:00:00 /bin/sh /usr/sbin/apache2ctl start
root 1181 1172 0 15:51 ? 00:00:00 /usr/sbin/apache2 -k start
root 1193 1181 0 15:51 ? 00:00:00 /bin/bash /usr/share/apache2/ask-for-passphrase 127.0.1.1:443 RSA
el 5439 5326 0 16:23 pts/2 00:00:00 grep --color=auto apache2
是的,在这种情况下,apache2正在运行,我试图在同一个端口上第二次启动apache2。
让我困惑的是,"service"报告说apache2没有运行:
el@titan:~$ sudo service apache2 status
Apache2 is NOT running.
当你查询apache2ctl的状态时,它会卡住。
root@titan:~# /usr/sbin/apache2ctl status
**hangs until Ctrl-C is pressed.
所以Ubuntu似乎在启动时无法正确管理apache2。是时候停止apache2了:
root@titan:~# /usr/sbin/apache2ctl stop
httpd (no pid file) not running
一个重要的线索!你试图停止apache2,但它丢失了进程ID!所以Ubuntu无法停止apache2,因为它不知道它在哪里!
你可能会认为重新启动会解决问题,但实际上并不会,因为apache2会在启动时自动运行并卡住。apache2的正常启动过程出现了问题。
那么如何修复呢?
我通过分析ps命令的输出来解决了这个问题。注意到ps命令告诉我们该进程是由"/etc/rc2.d/S91apache2 start"启动的。
这就是需要解决的问题程序。
/etc/rc2.d/S91apache2是用于在计算机启动时为您启动apache2的符号链接。由于某种原因,它似乎会启动apache2然后卡住。所以我们需要告诉它不要这样做。
所以去看一下那个/etc/rc2.d/S91apache2吧。
el@titan:/etc/rc2.d$ ls -l
lrwxrwxrwx 1 root root 17 Nov 7 21:45 S91apache2 -> ../init.d/apache2*
这是一个我们不希望存在的符号链接。为了防止apache2在启动时自动运行,请执行以下操作:
root@titan:~# sudo update-rc.d -f apache2 remove
Removing any system startup links for /etc/init.d/apache2 ...
/etc/rc0.d/K09apache2
/etc/rc1.d/K09apache2
/etc/rc2.d/S91apache2
/etc/rc3.d/S91apache2
/etc/rc4.d/S91apache2
/etc/rc5.d/S91apache2
/etc/rc6.d/K09apache2
重新启动计算机,确保apache2不会启动和挂起。好的,现在你可以把apache2恢复到原来的状态,但那样会再次导致它失败。
root@titan:~$ sudo update-rc.d apache2 defaults //(don't do this)
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K20apache2 -> ../init.d/apache2
/etc/rc1.d/K20apache2 -> ../init.d/apache2
/etc/rc6.d/K20apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S20apache2 -> ../init.d/apache2
相反,像这样启动apache2:
sudo service apache2 start
Apache2已经恢复并再次提供页面服务。似乎apache2/Ubuntu 12.10存在一些严重的bug,导致apache2启动后卡住。这是一个解决方法,我想修复的办法是获取更新版本的apache2和Ubuntu,并希望能够解决问题。
和
sudo netstat -ntlp | grep 80`的输出。 - gertvdijkgrep -ri listen /etc/apache2
输出: etc/apache2/httpd.conf:Listen 80 /etc/apache2/httpd.conf:Listen 443 /etc/apache2/ports.conf:Listen 80 /etc/apache2/httpd.conf:Listen 443 /etc/apache2/httpd.conf:Listen 443sudo netstat -ntlp | grep 80
没有任何输出。 - Gunner Barnes