Linux中apache自启动引起的思考

在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种方法,是一个同事用的方法,以我的智商目前还看不懂

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值