日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

【学习笔记】启动Nginx、查看nginx进程、查看nginx服务主进程的方式、Nginx服务可接受的信号、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级

發布時間:2024/9/27 Nginx 233 豆豆


1.啟動nginx的方式:

cd /usr/local/nginx

ls

./nginx -c nginx.conf

2.查看nginx的進程方式:

[root@localhost nginx]# ps –ef | grep nginx

[root@localhost nginx]# ps -ef | grep nginx

root???? 21094???? 1? 0 07:52 ???????? 00:00:00 nginx: master process ./nginx -c nginx.conf

nginx??? 21095 21094? 0 07:52 ???????? 00:00:00 nginx: worker process

root???? 21270? 3019? 1 08:05 pts/1??? 00:00:00 grep nginx

3.查看Nginx服務主進程的方式:

[root@localhost nginx]# cat nginx.pid

21094

這個進程號和上面的進程號是一樣的

4.Nginx服務可接受的信號

信號

作用

TERMINT

快速停止Nginx服務

QUIT

平緩停止Nginx服務

HUP

使用新的配置文件啟動進程,之后平緩停止原有進程,也就是所謂的平滑重啟

USR1

重新打開日志文件,常用于日志切割,在相關章節中會對此進一步說明

USR2

使用新版本的Nginx文件啟動服務,之后平緩停止原有Nginx進程,也就是所謂的平滑升級

WINCH

平緩停止worker process,用于Nginx服務器平滑升級

nginx服務主進程發送信號也有兩種方法。一種是使用nginx二進制文件

?

另一種方法是使用kill命令發送信號,其使用方法是:

Kill -9 PID

?

也可以通過發信號的方式:

使用TERM信號

[root@localhost nginx]# kill TERM 21094??? (其中21094master進程的pid,其中TERM可以換成INT QUIT)

-bash: kill: TERM: arguments must be process or job IDs

[root@localhost nginx]# ps -ef | grep nginx

root???? 21417? 3019? 0 08:16 pts/1??? 00:00:00 grep nginx

?

重啟命令

[root@localhost nginx]# ./nginx -c nginx.conf

[root@localhost nginx]# ps -ef | grep nginx

root???? 21440???? 1? 0 08:18 ???????? 00:00:00 nginx: master process ./nginx -c nginx.conf

nginx??? 21441 21440? 0 08:18 ???????? 00:00:00 nginx: worker process

root???? 21445? 3019? 2 08:18 pts/1??? 00:00:00 grep nginx

?

?

5、使用nginx的幫助的方式

nginx -h

[root@localhost nginx]# ./nginx -h

nginx version: nginx/1.10.1

Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

?

Options:

? -?,-h???????? : this help

? -v??????????? : show version and exit

? -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: /usr/local/nginx/nginx.conf)

? -g directives : set global directives out of configuration file

?

[root@localhost nginx]#

?

通過-v 用來顯示Nginx服務器的版本號;

通過-V顯示版本號,同事顯示相關的配置信息

通過-t檢查Nginx服務器配置文件是否有語法錯誤,可以與-c聯用,使輸出內容更詳細,這對查找配置文件中的語法錯誤很有幫助,如果檢查通過,將顯示類似下面的信息

[root@localhost nginx]# pwd

/usr/local/nginx

[root@localhost nginx]# ls

client_body_temp????? fastcgi_params.default? koi-win???????????? nginx?????????????? proxy_temp?????????? uwsgi_params

fastcgi.conf????????? fastcgi_temp??????????? logs??????????????? nginx.conf????????? scgi_params????????? uwsgi_params.default

fastcgi.conf.default? html??????????????????? mime.types????????? nginx.conf.default? scgi_params.default? uwsgi_temp

fastcgi_params??????? koi-utf???????????????? mime.types.default? nginx.pid?????????? scgi_temp??????????? win-utf

[root@localhost nginx]# ./nginx -t -c nginx.conf

nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/nginx.conf test is successful

[root@localhost nginx]#

?

可以執行

[root@localhost nginx]# ./nginx -V

nginx version: nginx/1.10.1

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)

built with OpenSSL 1.0.1c 10 May 2012

TLS SNI support enabled

configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/home/toto/software/nginxdepents/pcre-8.37 --with-zlib=/home/toto/software/nginxdepents/zlib-1.2.8 --with-openssl=/home/toto/software/nginxdepents/openssl-1.0.1c --with-http_stub_status_module --user=nginx --group=nginx

[root@localhost nginx]#

殺死主進程的方式同樣可以是:

./nginx SIGNAL nginx.pid

主要最后面一個參數是nginx.pid的路徑

?

6Nginx服務的重啟

關于Nginx平滑重啟,平滑重啟是這樣一個過程,Nginx服務進程接收到信號后,首先讀取新的Nginx配置文件,如果配置語法正確,則啟動新的Nginx服務,然后平緩關閉舊的服務進程;如果新的Nginx配置有問題,將顯示錯誤,仍然使用舊的Nginx提供服務。

?

使用以下命令實現Nginx服務的平滑重啟

./nginx –g HUP [-c newConfFile]

HUP信號用于發送平滑重啟信號。

newConfFile,可選項,用于指定新配置文件的路徑

或者,使用新的配置文件代替了舊的配置文件后,使用:

Kill HUP `nginx.pid`??? (注意最后一個參數連邊的引號;引號里面是nginx.pid的路徑)

也可以實現平滑重啟。

?

7Nginx服務器的升級

如果要對當前的Nginx服務器進行版本升級,應用新模塊,最簡單的辦法是停止當前Nginx服務,然后開啟新的Nginx服務,但這樣就會導致在一段時間內,用戶無法訪問服務器。為了解決這個問題,Nginx服務器提供平滑升級的功能。

平滑升級的過程是這樣的,Nginx服務接收到USR2信號后首先將舊的nginx.pid文件(如果在配置文件中更改過這個文件的名字,也是相同的過程)添加.oldbin,變為nginx.pid.oldbin文件;然后執行新版本Nginx服務器的二進制文件啟動服務。如果新的服務啟動成功,系統中將由新舊兩個Nginx服務公用提供Web服務。如果新的服務啟動成功,系統中將有新舊兩個Nginx服務共同提供Web服務。之后,需要向舊的Nginx服務進程發送WINCH信號,使舊的Nginx服務平滑停止,并刪除nginx.pid.oldbin文件。在發送WINCH信號之前,可以隨時停止新的Nginx服務。

注意:

為了實現Nginx服務器的平滑升級,新的服務器安裝路徑應該和舊的保持一致。因此建議用戶在安裝新服務器之前先備份舊服務器。如果由于某種原因無法保持新舊服務器安裝路徑一致,則可以先使用以下命令將舊服務器的安裝路徑更改為新服務器的安裝路徑:

./nginx –p newInstallPath

其中,newInstallPath為新服務器的安裝路徑。之后,備份舊服務器,安裝新服務器即可。

做好準備工作以后,使用以下命令實現Nginx服務的平滑升級。

./nginx –g USR2

其中USR2信號用于發送平滑升級信號。或者,使用:

Kill USR2 `nginx.pid`?? 注意,最后一個參數里面是nginx.pid的路徑

通過ps –ef | grep nginx查看新的Nginx服務器啟動正常,再使用:

./nginx –g WINCH

其中,WINCH信號用于發送平滑停止舊服務信號。或者,使用:

Kill WIN `nginx.pid`

這樣就不停止提供Web服務的前提下完成了Nginx服務器的平滑升級。

?

?

?

?

總結

以上是生活随笔為你收集整理的【学习笔记】启动Nginx、查看nginx进程、查看nginx服务主进程的方式、Nginx服务可接受的信号、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。