在Linux系统中常采用编译源码的方式来安装Apache,有三种方法可以让Apache在系统启动时自动启动。
1. 在/etc/rc.d/rc.local中增加启动apache的命令。
例如:
# echo "/usr/local/apache2/bin/apachectl start">>/etc/rc.d/rc.local
2. 将apache注册为系统服务
新建文件:
# vim /etc/init.d/Apache
内容如下:
#!/bin/sh
# description: http
# chkconfig: 2345 99 00
case "$1" in
'start')
/usr/local/apache2/bin/apachectl start
touch /var/lock/subsys/Apache
;;
'stop')
/usr/local/apache2/bin/apachectl stop
rm -f /var/lock/subsys/Apache
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
权限:
# chmod 755 /etc/init.d/Apache
说明:
# description: http
# chkconfig: 2345 99 00
其中2345表示运行级别 99 00是关于启动和停止的优先级配置,无关紧要。
有以上两行才能注册该服务
# chkconfig --add Apache
# chkconfig --list Apache
可以通过以下命令开启或关闭
# chkconfig Apache on
# chkconfig Apache off
一切OK了,启动服务
# /etc/init.d/Apache start
3 一位高手同事的用法
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/
# cd /etc/rc.d/rc3.d/
# ln -s ../init.d/apachectl S100apache
# shutdown -r now
说明:
S-->;start
K-->;kill
S后边的数字决定该进程启动时候的处理顺序,应该是从小到大运行。
把S改成别的字母的话,该进程开机就不会自动启动了
我想100以后,应该是由用户自己定义了
就像用户一样,500以后算是用户自己加的了
总结:
第1种方法教程中多见,比较方便好找
第2种方法,像apache这样的,可以直接
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/
开头加上
# description: http
# chkconfig: 2345 99 00
就可以使用
# chkconfig --add Apache
和mysql一样的用法
关键在于自己写,这种方法可以很方便的加一些自定义的命令
例如:
start处加
/usr/local/sbin/vsftpd &
svnserve -d -r /svn/p1/
stop处加
killall -9 vsftpd
kill -9 `ps -A|grep svnserve|awk '{print $1}'`
即使不做成服务自启动,也可以很方便的使用下面命令
# /etc/init.d/svnserve start
第3种方法,是一个同事用的方法,以我的智商目前还看不懂