CentOS6.3添加nginx系统服务的实例详解
程序员文章站
2023-11-15 16:18:52
centos6.3添加nginx系统服务的实例详解
前言:
今天虚拟机上配了下服务器整理了个这个 nginx 服务
要注意 - 短横杠这个符号看看复制进去后有没有...
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
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!