在centos上安装服务

目标

简单记录一下如何在centos上安装服务。

  • 为了实现在centos/linux上实现开机启动,一般有两种做法 *

  • 在/etc/rc.local上写启动脚本

  • 安装成服务,然后定义其run level

下面简单说说安装成服务的过程

  • 在/etc/init.d/目录下编写启动脚本

  • 使用chkconfig命令添加服务。

1
2
chkconfig --add nginx
chkconfig [--level 2345] nginx on

启动脚本有一定的要求,主要是要求在脚本开头的注释有一定的格式。形如这样

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

–EOF–