最近,Aerchi在折騰 ECS服務器 (Centos 7),每次重啟后都要手動開啟apache服務,好繁瑣。
仔細研究了下:
Apache 的服務
第一、啟動、終止、重啟
systemctl start httpd.service #啟動
systemctl stop httpd.service #停止
systemctl restart httpd.service #重啟
第二、設置開機啟動/關閉
systemctl enable httpd.service #開機啟動
systemctl disable httpd.service #開機不啟動
第三、檢查httpd狀態
systemctl status httpd.service
需要將Apache注冊到Linux服務里面啊!
注冊Apache到Linux服務
在Centos 7 安裝完Apache后,啟動關閉Apache可以通過如下命令實現:
/usr/local/apache/bin/apachectl start | stop | restart
如果想將httpd列入系統自動啟動的服務,可以直接將上述的apachectl文件拷貝到 /etc/rc.d/init.d 中,然后在相應的啟動級別如3,5中加入鏈接即可。命令如下:
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd # 復制到init.d 並重命名為httpd
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd
鏈接文件的S61是啟動時的序號。當init.d目錄下有httpd腳本后,我們就可以通過service命令來啟動關閉apache了。在任意路徑下執行:
service httpd start | stop | restart
這時有個問題就是:雖然apache已經可以自動啟動,但在linux的服務列表中卻看不到它,要添加服務,一般通過chkconfig --add xxx來實現,但需要腳本中有相應的信息才行,否則chkconfig就會提示:xxx 服務不支持 chkconfig。所以我們首先編輯httpd腳本,在第2行(#!/bin/sh下面)添加如下注釋信息(包括#):
# chkconfig: 35 61 61
# description: Apache
第一行的3個參數意義分別為:在哪些運行級別啟動httpd(3,5);啟動序號(S61);關閉序號(K61)。注意:第二行的描述必須要寫!
保存后執行:
chkconfig --add httpd #所有開機模式下自啟動,另外chkconfig httpd on 表示345模式下自啟動
就將httpd添加入服務了。在rc3.d、rc5.d路徑中將來就會出現S61httpd的鏈接,其他運行級別路徑中會出現K61httpd的鏈接。
最后,修改 rc.local文件添加自啟動
vim /etc/rc.d/rc.local
添加如下:
13 touch /var/lock/subsys/local
14 /etc/init.d/mysqld start
15 #/usr/local/apache/bin/apachectl start
16 #apachectl restart
17 touch /usr/local/apache/bin/
18 /usr/local/apache/bin/apachectl start
運行下面的命令查看服務,就可以看到httpd的服務了。
chkconfig --list
systemctl list-unit-files
------------------------------------------
樂意黎
2018-06-29
---------------------
作者:aerchi
來源:CSDN
原文:https://blog.csdn.net/aerchi/article/details/80859894
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!