4年前 (2015-06-14)  操作系统 系统运维 |   5 条评论  55 
百度已收录 | 文章评分 0 次,平均分 0.0

今天编译安装完LAMP后,使用service重启httpd时会出现关闭失败。

发现系统上/etc/httpd/conf/httpd.conf和/etc/httpd/httpd.conf这两个文件都有,网上搜了下发现原来安装系统默认安装了LAMP,就出现了
/etc/httpd/conf/httpd.conf,导致使用service httpd restart重启httpd会出现关闭失效,httpd -t 也不能检测到语法错误。

解决方法:

1,提供SysV服务脚本/etc/init.d/httpd,内容如下:

[root@www ~]# vim /etc/init.d/httpd
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# 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/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $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=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac

exit $RETVAL

2,生效apachectl:将其制作为一个模块加入到环境变量中去。

<code><span class="pun">[</span><span class="pln">root@www </span><span class="kwd">local</span><span class="pun">]</span><span class="com"># vim  /etc/profile.d/httpd.sh</span></code>
<code><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="pln">$PATH</span><span class="pun">:</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">apache</span><span class="pun">/</span><span class="pln">bin     </span><span class="pun">------&gt;</span> <span class="pun">添加此句,保存退出</span></code>

3,而后为此脚本赋予执行权限:

<code><span class="pun">[</span><span class="pln">root@www </span><span class="kwd">local</span><span class="pun">]</span><span class="com"># chmod +x /etc/init.d/httpd</span></code>

加入服务列表:

<code><span class="pun">[</span><span class="pln">root@www </span><span class="kwd">local</span><span class="pun">]</span><span class="com"># chkconfig --add httpd</span></code>

 

 

除特别注明外,本站所有文章均为张子豪博客(ZihaoBlog)原创,转载请注明出处来自https://www.zihao123.com/239.html

关于
93年菜鸟云主机运维。

发表评论

表情 格式

暂无评论

切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

×
订阅图标按钮