編譯安裝apache實現自動啓動

編譯安裝apache實現自動啓動

編譯安裝apache之後要想啓動我們可以用命令:路徑/apachectl start 如果要開機啓動我們可以把這條命令放在/etc/rc.d/rc.local下,但如果我們要像啓動其它服務一樣用service 服務名 start|stop|status一樣啓動,停止,查看狀態;讓chkconfig來安排系統在某個級別來啓動或者是關閉某個服務,我們就要做一些簡單的操作了,
 
首先我們
[root@apple ~]# ls /lamp/apache/bin/apachectl
/lamp/apache/bin/apachectl
查到到編譯安裝過的apache啓動腳本文件的位置,然後我們嘗試着去啓動他
[root@apple ~]# /lamp/apache/bin/apachectl start         -------這是正確的啓動方法
[root@apple ~]# service apachectl start
apachectl: 未被識別的服務
[root@apple ~]# chkconfig --list apachectl
在 apachectl 服務中讀取信息時出錯:沒有那個文件或目錄
[root@apple ~]#
如果我們要想實現用chkconfig實現在某個級別自動啓動我們要做如下操作。
1:複製編譯安裝的啓動腳本到/etc/init.d目錄下
[root@apple ~]# cp /lamp/apache/bin/apachectl /etc/init.d/
[root@apple ~]# ll /etc/init.d/apachectl -i
518664 -rwxr-xr-x 1 root root 3414 11-26 19:18 /etc/init.d/apachectl
[root@apple ~]# ll /etc/rc.d/init.d/apachectl -i
518664 -rwxr-xr-x 1 root root 3414 11-26 19:18 /etc/rc.d/init.d/apachectl
我們把文件複製到/etc/init.d之後我們會發現系統自動會在/etc/rc.d/init.d目錄下創建該文件的硬鏈接文件。
注意:節點號相同
2:修改apache啓動腳本文件的內容
要在配置文件中加入讓chkconfig在哪個級別啓動這個服務以及啓動服務和關閉服務的順序和描述信息。格式如下
[root@apple ~]# vi /etc/init.d/apachectl
#!/bin/sh
#
#chkconfig:35 81 91                     ------ 新添加行
#description:this is a apache server          ------ 新添加行
# Licensed to the Apache Software Foundation (ASF) under one or more
注:其中:35爲系統進入的級別,81爲系統第幾個啓動的服務,91爲系統第幾個關閉的服務。81和91 這些數字我們要注意不要跟系統已經存在的啓動項衝突!
3:讓chkconfig包含apachectl服務
[root@apple ~]# chkconfig --add apachectl
 
然後我們就可以查看了,
[root@apple ~]# chkconfig --list apachectl
apachectl       0:關閉 1:關閉 2:關閉 3:啓用 4:關閉 5:啓用 6:關閉
我們在/etc/rc.d/rc3.d和/etc/rc.d/rc5.d這兩個目錄下我們可以查看到
[root@apple ~]# ll /etc/rc.d/rc3.d/S81apachectl
lrwxrwxrwx 1 root root 19 11-26 19:28 /etc/rc.d/rc3.d/S81apachectl -> ../init.d/apachectl
[root@apple ~]# ll /etc/rc.d/rc5.d/S81apachectl
lrwxrwxrwx 1 root root 19 11-26 19:28 /etc/rc.d/rc5.d/S81apachectl -> ../init.d/apachectl
[root@apple ~]#
然後我們就可以用chkconfig 的來安排系統啓動哪個級別來啓動apache服務了
[root@apple ~]# chkconfig --level 345 apachectl on
[root@apple ~]# chkconfig --list apachectl
apachectl       0:關閉 1:關閉 2:關閉 3:啓用 4:啓用 5:啓用 6:關閉
[root@apple ~]# chkconfig --level 345 apachectl off
[root@apple ~]# chkconfig --list apachectl
apachectl       0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉
[root@apple ~]#

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章