将Apache添加为Linux的服务 实现自启动
將Apache添加為L(zhǎng)inux的服務(wù) 實(shí)現(xiàn)自啟動(dòng)
在Linux下用源代碼方式編譯安裝完Apache后,啟動(dòng)關(guān)閉Apache可以通過(guò)如下命令實(shí)現(xiàn):
/app/apache2.2.14/bin/apachectl start | stop | restart
如果想將httpd列入系統(tǒng)自動(dòng)啟動(dòng)的服務(wù),可以直接將上述的apachectl文件拷貝到 /etc/rc.d/init.d 中,然后在相應(yīng)的啟動(dòng)級(jí)別如3,5中加入鏈接即可。命令如下: /etc/rc.d/init.d/.httpd.swp cp /app/apache2.2.14/bin/apachectl /etc/rc.d/init.d/httpd ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd
鏈接文件的S61是啟動(dòng)時(shí)的序號(hào)。當(dāng)init.d目錄下有httpd腳本后,我們就可以通過(guò)service命令來(lái)啟動(dòng)關(guān)閉apache了。在任意路徑下執(zhí)行:
service httpd start | stop | restart
腳本中沒(méi)有輸入提示信息,但命令已經(jīng)執(zhí)行了。這時(shí)有個(gè)問(wèn)題就是:雖然apache已經(jīng)可以自動(dòng)啟動(dòng),但在linux的服務(wù)列表中卻看不到它, 比如運(yùn)行 ntsysv或紅帽子的chkconfig --list指令。要添加服務(wù),一般通過(guò)chkconfig --add xxx來(lái)實(shí)現(xiàn),但需要腳本中有相應(yīng)的信息才行, 否則chkconfig就會(huì)提示:xxx 服務(wù)不支持 chkconfig。所以我們首先編輯httpd腳本,在第2行添加如下注釋信息:
# chkconfig: 35 61 61 # description: Apache
第一行的3個(gè)參數(shù)意義分別為:在哪些運(yùn)行級(jí)別啟動(dòng)httpd(3,5);啟動(dòng)序號(hào)(S61);關(guān)閉序號(hào)(K61)。注意:第二行的描述必須要寫!
保存后執(zhí)行:chkconfig --add httpd
就將httpd添加入服務(wù)了。在rc3.d、rc5.d路徑中將來(lái)就會(huì)出現(xiàn)S61httpd的鏈接,其他運(yùn)行級(jí)別路徑中會(huì)出現(xiàn)K61httpd的鏈接。
運(yùn)行chkconfig --list就可以看到httpd的服務(wù)了。
用chkconfig將自編譯設(shè)置為系統(tǒng)服務(wù)的時(shí)候,httpd 服務(wù)不支持 chkconfig。
[root@localhost ~]# chkconfig --add httpd [root@localhost ~]# chkconfig --list|grep httpd httpd?????????? 0:關(guān)閉 1:關(guān)閉 2:關(guān)閉 3:關(guān)閉 4:關(guān)閉 5:關(guān)閉 6:關(guān)閉 [root@localhost ~]# chkconfig --level 345 httpd on [root@localhost ~]# chkconfig --list|grep httpd httpd?????????? 0:關(guān)閉 1:關(guān)閉 2:關(guān)閉 3:啟用 4:啟用 5:啟用 6:關(guān)閉
為了您的安全,請(qǐng)只打開(kāi)來(lái)源可靠的網(wǎng)址打開(kāi)網(wǎng)站??? 取消
來(lái)自: http://hi.baidu.com/kennyrbj/blog/item/1358ee8d0df876e4f11f3624.html轉(zhuǎn)載于:https://www.cnblogs.com/duxp/archive/2012/05/06/apache_server.html
總結(jié)
以上是生活随笔為你收集整理的将Apache添加为Linux的服务 实现自启动的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java web中验证码的实现
- 下一篇: asp:UpdatePanel中使用下拉