简体   繁体   中英

Amazon EC2 - Apache server restart issue

When i run this command

sudo /etc/init.d/httpd restart

it gives below error

Stopping httpd: [FAILED]

Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80 (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 [FAILED]


i checked running programs at port 80 by using

netstat -lnp | grep :80 (it gives below output)

tcp 0 0 :::80 :::* LISTEN 21739/httpd


why i am not able to stop stop apache by using sudo /etc/init.d/httpd restart?

below commands work without issue

sudo apachectl stop

sudo apachectl start

i am using linux micro instance of amazon ec2

I ran into this problem when I installed apache from source, but then tried to run

$ sudo /etc/init.d/httpd restart 

which was using a pre-installed version of apache. The stop directive in /etc/init.d/httpd was not removing the httpd.pid file that was created when starting the source-installed version of apache.

To determine if this is also the reason for your problem, find where the httpd.pid file is getting set when you run

$ sudo apachectl start

If you installed from source and apache2 is living in /usr/local/apache2, then the httpd.pid file should get created in /usr/local/apache2/logs. When you stop apache by running

$ sudo apachectl stop

this file should get removed. So to test if the httpd.pid file is causing your problem, start apache by calling

$ sudo apachectl start

and locate the httpd.pid file. Then try stopping apache by using

$ sudo /etc/init.d/httpd stop

If the original httpd.pid file is still present, then that is why apache is unable to start when you use

$ sudo /etc/init.d/httpd start

To get my /etc/init.d/httpd file to work correctly, I explicitly put the call to apachectl in the start and stop methods:

#!/bin/bash
# /etc/init.d/httpd
#
# Path to the apachectl script, server binary, and short-form for messages. 
apachectl=/usr/local/apache2/bin/apachectl 
httpd=/usr/local/apache2/bin/httpd 
pid=/usr/local/apache2/logs/httpd.pid 
prog=httpd 
RETVAL=0

start() {
    echo -n $"Starting $prog: "
    $apachectl -k start
    RETVAL=$?
    echo
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    $apachectl -k stop
    RETVAL=$?
    echo
}

I tried this and it works:

  1. sudo fuser -k -n tcp 80
  2. sudo service httpd start

Hope this will help you!

Cheers

我觉得最好杀死进程本身,找出进程ID并杀死它然后重新开始,它应该可以正常工作

I have had this issue very rarely over the last couple years with a server I've been managing. Unfortunately, if you are getting FAILED after trying to restart, the process that's managing the connection on port 80 won't release it's hold on that port.

I would try a full "sudo /etc/init.d/httpd stop" wait for that to finish or fail.

If that doesn't fix it you'll have to restart the server completely. Hopefully, it's configured to start everything up automatically on restart, but that isn't guaranteed.

"apachectl" is also great tool for Apache, but it may not be on this server, it depends on the install and linux distro used.

If after rebooting the server, apache still fails to start, something bad has happened. I'd consider pulling all the website and conf files for creating a new server at that point, but the apache start, and then failed message output should give you some idea of where to look in the Logs about why it cannot start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM