CentOS6.3添加nginx系统服务的实例详解

作者:神神的蜗牛 时间:2023-10-07 01:10:03 

CentOS6.3添加nginx系统服务的实例详解

前言:

今天虚拟机上配了下服务器整理了个这个 nginx 服务

要注意 - 短横杠这个符号看看复制进去后有没有乱码,我之前就遇到这个问题,郁闷了好久才发现

提示:顶部的注释不要去除否则无法注册为系统服务,

关于:chkconfig: 2345 65 37

网上搜索总结了下意思是:

  • 2345 为启动该服务的系统环境

  • 65   为加载的优先级别

  • 37   为关闭的优先级别

65,37 这两个位置的数值不能相同,也不能和其它服务的数值冲突,这个我也没遇到过此类问题,如果有发现问题请对应自己的配置修改下好了

新建文件:


# vi /etc/init.d/nginx

输入内容:


#!/bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 65 37
# description: A nginx daemon.

set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME

# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0

d_test() {
 $DAEMON -t
}
d_start() {
 $DAEMON || echo -n " already running"
}
d_stop() {
 $DAEMON -s quit || echo -n " not running"
}
d_reload() {
 $DAEMON -s reload || echo -n " could not reload"
}

case "$1" in
 test)
  d_test
  echo "."
  ;;
 start)
  echo -n "Starting $DESC: $NAME"
  d_start
  echo "."
  ;;
 stop)
  echo -n "Stopping $DESC: $NAME"
  d_stop
  echo "."
  ;;
 reload)
  echo -n "Reloading $DESC configuration..."
  d_reload
  echo "reloaded."
  ;;
 restart)
  echo -n "Restarting $DESC: $NAME"
  d_stop
  # Sleep for two seconds before starting again, this should give the
  # Nginx daemon some time to perform a graceful stop.
  sleep 2
  d_start
  echo "."
  ;;
 *)
  echo "Usage: $SCRIPTNAME {test|start|stop|restart|reload}" >&2
  exit 3
  ;;
esac

exit $?

注册 nginx 服务:


chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on
chkconfig --list nginx

相关 nginx 命令:

检测 nginx 配置


# service nginx test

启动


# service nginx start

关闭


# service nginx stop

重启


# service nginx restart

重载配置


# service nginx reload

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

来源:http://blog.csdn.net/zhouzme/article/details/19576855

标签:CentOS,nginx,系统服务
0
投稿

猜你喜欢

  • vmware虚拟机安装centos7.3的教程图解

    2023-11-03 19:26:47
  • Linux创建进程达到65535的方法

    2023-10-10 09:34:11
  • 做站要做具有“生命力”的网站

    2008-06-06 11:26:00
  • 关于网站收录的一些思考

    2008-04-07 13:18:00
  • 买美国空间必读 WHM+cPanel空间付费管理系统介绍

    2010-04-20 10:51:00
  • centos 7 安装卸载apache(httpd)服务的详细步骤

    2023-08-26 00:51:50
  • DEDECMS:TAG作为文章发布后关键字meta keywords的修改办法

    2009-02-13 17:22:00
  • 服务器目录配置来有效防范ASP木马

    2007-08-06 14:10:00
  • ftp操作常识问题集锦

    2007-09-10 10:55:00
  • WordPress调用PageCookery的方法

    2010-06-21 09:40:00
  • 2009年各大主流CMS大PK

    2009-02-24 13:51:00
  • 暴雪CEO行使期权出售股份套现2000万美元

    2009-11-14 10:21:00
  • 互联网创业必备的知识

    2008-01-26 19:26:00
  • 解决linux系统中运行node进程却无法杀死进程的问题

    2023-03-09 14:32:34
  • 网站盈利只要做好三件事

    2008-01-23 14:30:00
  • 如何设置GoDaddy独立服务器 Godaddy

    2010-05-03 12:47:00
  • 使用rsync在两台VPS间传输文件

    2011-08-24 20:13:41
  • 简单的服务器信息监控软件

    2010-08-12 18:51:00
  • DeDeCms V5.6数据批量索引到淘特搜索引擎

    2010-06-20 15:32:00
  • GoDaddy主机如何查看网站的运行情况

    2010-04-12 13:17:00
  • asp之家 网站运营 m.aspxhome.com