Apache自动启动及添加为Linux的服务 转自:http://www.51testing.com/?27242/action_viewspace_itemid_78916.html

来源:互联网 发布:c语言的注释定界符是 编辑:程序博客网 时间:2024/05/01 20:39

转自:http://www.51testing.com/?27242/action_viewspace_itemid_78916.html,根据Apache2的版本,略有修改


说明:
 Apache安装路径为:/usr/local/apache2
 Linux的启动级别为5,版本为Linux AS4

 Apache安装完后,发现Apache无法自动启动,查看/etc/rc.d/rc5.d/下,应该没有S打头,httpd结尾的链接文件。

1、将apachectl文件拷贝到/etc/rc.d/init.d 中,然后在/etc/rc.d/rc5.d/下加入链接即可。
命令如下:
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd  //如果有其他的版本的Apache存在,也可以直接覆盖掉。
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd      //建立链接(85的意义后面介绍)
此时Apache就可以自动启动了。

2、运行chkconfig --list,发现没有linux服务列表中httpd,通过chkconfig --add httpd来添加,但是提示:httpd服务不支持 chkconfig。需要编辑/etc/rc.d/init.d/httpd,添加以下注释信息:
  # chkconfig: 345 85 15
  # descrīption: Apache
    第一行3个数字参数意义分别为:哪些Linux级别需要启动httpd(3,4,5);启动序号(85);关闭序号(15)。

保存后执行:chkconfig --add httpd,成功添加。

在rc3.d、rc4.d、rc5.d路径中会出现S85httpd的链接文件,其他运行级别路径中会出现K61httpd的链接文件。

3、运行chkconfig --list | grep httpd,http在其中。


重启后,查看已启动的服务:

chkconfig --list | grep httpd,可以发现httpd

在RedHat或CentOS中,可以运行ntsysv来设置自启动服务


原创粉丝点击