サーバーの再起動後にApacheサーバーが自動的に起動しないのはなぜですか?

サーバーの再起動後にApacheサーバーが自動的に起動しないのはなぜですか?

私はAmazon Linuxを使用しています。私はyum経由でApacheを起動しましたが、サーバーを再起動すると、コマンドラインから起動しても自動的に起動しません。

[myuser@mymachine ~]$ sudo service httpd start
[sudo] password for myuser:
Starting httpd: httpd: apr_sockaddr_info_get() failed for mymachine
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
[myuser@mymachine ~]$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

以下の権限で以下のリンクを設定しました。設定ファイルはインストール時に自動的に作成されました。

[myuser@mymachine ~]$ ls -al /etc/init.d/httpd
-rwxr-xr-x 1 root root 3371 Sep 15 20:58 /etc/init.d/httpd


[myuser@mymachine ~]$ ls -al /etc/rc3.d/*httpd*
lrwxrwxrwx 1 root root 15 Oct 18 22:03 /etc/rc3.d/K15httpd -> ../init.d/httpd


[myuser@mymachine ~]$ cat /etc/init.d/httpd
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#          server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
#  implementing the current HTTP standards.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/sbin/apachectl
httpd=${HTTPD-/usr/sbin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
        status -p ${pidfile} $httpd
    RETVAL=$?
    ;;
  restart)
    stop
    start
    ;;
  condrestart|try-restart)
    if status -p ${pidfile} $httpd >&/dev/null; then
        stop
        start
    fi
    ;;
  force-reload|reload)
        reload
    ;;
  graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
    RETVAL=2
esac

exit $RETVAL

ただし、サーバーを再起動した後は何も実行されませんでした(ポート80ではTelnet経由で接続できませんでした)。再起動後に始めるにはどうすればよいですか?

ベストアンサー1

[myuser@mymachine ~]$ ls -al /etc/rc3.d/*httpd*
lrwxrwxrwx 1 root root 15 Oct 18 22:03 /etc/rc3.d/K15httpd -> ../init.d/httpd

それはあなたの問題です。 /etc/rc3.dでK(kill)で始まるスクリプトは起動時に起動されませんが、Sで始まるスクリプトは起動します。

これにより:

[myuser@mymachine ~]$ mv /etc/rc3.d/K15httpd /etc/rc3.d/S15httpd

あなたの問題は解決されます。ただし、これは手動で実行する必要がある作業です。最善の方法は、次のようにchkconfigコマンドを使用することです。

[myuser@mymachine ~]$ chkconfig httpd on

おすすめ記事