來自網(wǎng)絡(luò)
01
信號(hào)量
=========================
nginx服務(wù)運(yùn)行時(shí)座柱,會(huì)保持一個(gè)主進(jìn)程和一個(gè)或者多個(gè)工作進(jìn)程崩瓤。
我們可以通過給Nginx服務(wù)主進(jìn)程發(fā)送信號(hào)就可以控制服務(wù)的啟停俊戳。
nginx服務(wù)可以接受的信號(hào)
信號(hào) | 作用 |
---|---|
TERM或INT | 快速停止 Nginx服務(wù) |
QUIT | 平緩?fù)V筃ginx服務(wù) |
HUP | 使用新的配置文件啟動(dòng)進(jìn)程陆蟆,之后平緩?fù)V乖羞M(jìn)程寇窑,平滑重啟 |
USR1 | 重新打開日志文件,常用于日志切割 |
USR2 | 使用新版本的Nginx文件啟動(dòng)服務(wù)慕的,平滑升級(jí) |
WINCH | 平緩?fù)V构ぷ鬟M(jìn)程阎肝,升級(jí)時(shí)使用 |
向nginx服務(wù)主進(jìn)程發(fā)送信號(hào)方式
- 使用nginx二進(jìn)制文件
- 使用kill命令發(fā)送
kill SIGNAL PID
02
二進(jìn)制信號(hào)量管理
=========================
在Linux平臺(tái)下,啟動(dòng)Nginx服務(wù)器直接運(yùn)行安裝目錄下的sbin目錄中的二進(jìn)制文件即可肮街。管理Linux也常用二進(jìn)制文件發(fā)送信號(hào)量风题。
- 查看二進(jìn)制信號(hào)量
# ./sbin/nginx -h
nginx version: nginx/1.11.6
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help //顯示幫助信息
-v : show version and exit//打印版本號(hào)并推出
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
- -V
打印版本號(hào)和配置并退出 - -t
測試配置正確性并退出 - -q
測試配置時(shí)只顯示錯(cuò)誤 - -s single
向主進(jìn)程發(fā)送信號(hào)
stop, quit, reopen, reload - -p
指定Nginx服務(wù)器路徑前綴 - -c filename
指定Nginx配置文件路徑 - -g directives
指定Nginx附加配置文件路徑
03
常用案例
=========================
- 查看Nginx服務(wù)進(jìn)程
[root@localhost nginx]# ps -ef |grep nginx
root 1767 1 0 05:31 ? 00:00:00 nginx: master process ./nginx
nobody 1768 1767 0 05:31 ? 00:00:00 nginx: worker process
root 2053 1741 0 05:44 pts/0 00:00:00 grep nginx
- 查看Nginx版本信息
[root@localhost nginx]# ./sbin/nginx -v
nginx version: nginx/1.11.6
- 檢測配置文件并平滑啟動(dòng)
[root@localhost nginx]# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx]# ./sbin/nginx -s reload