1. 程式人生 > >把編譯安裝的httpd 實現服務腳本,通過service和chkconfig 進行管理

把編譯安裝的httpd 實現服務腳本,通過service和chkconfig 進行管理

成功 服務腳本 文件內容 roc grep sharp list roo httpd

把編譯安裝的httpd 實現服務腳本,通過service和chkconfig 進行管理

1 編譯安裝httpd

把httpd編譯安裝在/app/httpd/目錄下。

2 在/etc/rc.d/init.d/目錄下新建一個文件httpd

這個文件的目的在於讓service 命令可以管理編譯安裝的httpd服務。

文件內容如下:

[[email protected] ~]# cat /etc/rc.d/init.d/httpd

#!/bin/bash
#
# httpd        Start up the httpd server daemon
#
# chkconfig: 2345 99 01
# description: httpd is a protocol for web server.
# This service starts up the httpd server daemon.
#
# processname: httpd
case $1 in
start)
    /app/httpd/bin/apachectl start ;;
stop)
    /app/httpd/bin/apachectl stop ;;
status)
    /app/httpd/bin/apachectl status ;;
*)
    echo err
esac

3 添加為開機啟動

[[email protected] /app/httpd/bin]# chkconfig --add httpd
[[email protected] /app/httpd/bin]# chkconfig --list |grep httpd
httpd     0:off    1:off    2:on    3:on    4:on    5:on    6:off

可以看到已經添加成功

4 通過service 命令啟動服務

[[email protected] ~]# service httpd start
httpd: Could not reliably determine the server‘s fully qualified domain name, using CentOS68.localhost for ServerName

可以看到會報錯,但是服務已經啟動成功了,修改/app/httpd/conf/httpd.conf這個文件,把98行前面的#去掉即可

98 #ServerName www.example.com:80

現在可以通過service命令管理手動安裝的httpd 服務了

把編譯安裝的httpd 實現服務腳本,通過service和chkconfig 進行管理