编译安装的httpd实现服务脚本,通过service和chkconfig进行管理

前端之家收集整理的这篇文章主要介绍了编译安装的httpd实现服务脚本,通过service和chkconfig进行管理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

把编译安装的httpd 实现服务脚本,通过service和chkconfig 进行管理

1 编译安装httpd

    把httpd编译安装在/app/httpd/目录下。

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

这个文件的目的在于让service 命令可以管理编译安装的httpd服务。

    文件内容如下:

  1. [root@CentOS68 ~]# cat /etc/rc.d/init.d/httpd
  2.  
  3. #!/bin/bash
  4. #
  5. # httpd Start up the httpd server daemon
  6. #
  7. # chkconfig: 2345 99 01
  8. # description: httpd is a protocol for web server.
  9. # This service starts up the httpd server daemon.
  10. #
  11. # processname: httpd
  12. case $1 in
  13. start)
  14. /app/httpd/bin/apachectl start ;;
  15. stop)
  16. /app/httpd/bin/apachectl stop ;;
  17. status)
  18. /app/httpd/bin/apachectl status ;;
  19. *)
  20. echo err
  21. esac

3 添加为开机启动

  1. [root@CentOS68 /app/httpd/bin]# chkconfig --add httpd
  2. [root@CentOS68 /app/httpd/bin]# chkconfig --list |grep httpd
  3. httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

可以看到已经添加成功

4 通过service 命令启动服务

  1. [root@CentOS68 ~]# service httpd start
  2. 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 服务了

猜你在找的Linux相关文章