CentOS6.3添加nginx系統服務的實例詳解
前言:
今天虛擬機上配了下服務器整理了個這個 nginx 服務
要注意 - 短橫杠這個符號看看復制進去后有沒有亂碼,我之前就遇到這個問題,郁悶了好久才發現
提示:頂部的注釋不要去除否則無法注冊為系統服務,
關于:chkconfig: 2345 65 37
網上搜索總結了下意思是:
- 2345 為啟動該服務的系統環境
- 65 為加載的優先級別
- 37 為關閉的優先級別
65,37 這兩個位置的數值不能相同,也不能和其它服務的數值沖突,這個我也沒遇到過此類問題,如果有發現問題請對應自己的配置修改下好了
新建文件:
1
|
# vi /etc/init.d/nginx |
輸入內容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/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 服務:
1
2
3
4
|
chmod +x /etc/init .d /nginx chkconfig --add nginx chkconfig --level 2345 nginx on chkconfig --list nginx |
相關 nginx 命令:
檢測 nginx 配置
1
|
# service nginx test |
啟動
1
|
# service nginx start |
關閉
1
|
# service nginx stop |
重啟
1
|
# service nginx restart |
重載配置
1
|
# service nginx reload |
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
原文鏈接:http://blog.csdn.net/zhouzme/article/details/19576855