CentOS7.4源碼編譯安裝apache服務設置開機自啓動失敗

1、系統版本信息

[root@lamp /]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@lamp /]# uname -r
3.10.0-957.21.3.el7.x86_64

2、源碼編譯安裝apache服務後,設置開機自啓動報錯信息

################systemctl設置開機自啓動報錯################

[root@lamp scripts]# systemctl enable httpd 
httpd.service is not a native service, redirecting to /sbin/chkconfig.     #httpd。服務不是本機服務,重定向到/sbin/chkconfig。
Executing /sbin/chkconfig httpd on
service httpd does not support chkconfig

################chkconfig設置開機自啓動報錯################

[root@lamp scripts]# chkconfig --add httpd
service httpd does not support chkconfig     #服務httpd不支持chkconfig

3、解決方法或思路

    1)編寫apache啓動腳本

[root@lamp scripts]# pwd
/opt/httpd/scripts
[root@lamp scripts]# vim httpd 
#!/bin/bash
#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server

function httpd_start(){
/opt/httpd/bin/apachectl start
}

function httpd_stop(){
/opt/httpd/bin/apachectl stop
}

case $1 in
        start)
                httpd_start
        ;;
        stop)
                httpd_stop
        ;;
        restart)
                httpd_stop
                httpd_start
        ;;
        *)
                echo "Usage: httpd start|stop|restart!"
        ;;
esac

    注意:以下兩行內容必須寫,並且要寫在第二行,否則無法設置開機自啓動

#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server

    2)把編寫的啓動腳本複製到/etc/init.d/目錄下,並且賦予執行權限,(添加到系統服務中)

[root@lamp scripts]# chmod +x httpd 
[root@lamp scripts]# ll
total 4
-rwxr-xr-x 1 root root 284 Jul 17 09:55 httpd
[root@lamp scripts]# cp -a httpd /etc/init.d/

    3)重新加載守護進程,啓動服務

[root@lamp scripts]# systemctl daemon-reload   #必須先加載守護進程,否則無法啓動服務
[root@lamp scripts]# systemctl start httpd
[root@lamp scripts]# netstat -lnpt|grep http
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2996/httpd

    注意:將編寫的apache啓動腳本添加到系統服務中後,首先要加載守護進程,否則無法啓動服務。

    下面是沒有加載守護進程,啓動服務的報錯信息:

[root@lamp scripts]# systemctl start httpd
Warning: httpd.service changed on disk. Run 'systemctl daemon-reload' to reload units.

    4)設置開機自啓動

        設置開機自啓動命令:

[root@lamp scripts]# chkconfig --add httpd

        查看開機自啓動是否設置成功:

[root@lamp scripts]# chkconfig --list|grep httpd

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

    5)apache安裝路徑

[root@lamp httpd]# pwd 
/opt/httpd
[root@lamp httpd]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules  scripts


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