「四」命令列、熱部署、日誌切割
阿新 • • 發佈:2022-05-08
命令列
- 格式:nginx 引數 [動作]
- 幫助:-? -h
- 使用指定的配置檔案:-c
- 指定配置指令:-g
- 指定執行目錄:-p
- 傳送訊號:-s
指令:
stop:停止服務
quit:優雅停止服務
reload:過載配置檔案
reopen:重新開始記錄日誌檔案 - 測試配置檔案是否有語法錯誤:-t -T
- 列印nginx的版本資訊、編譯資訊等:-v -V
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -s reload root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -? nginx version: nginx/1.14.2 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: /home/ubuntu/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -v nginx version: nginx/1.14.2 root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -t nginx: the configuration file /home/ubuntu/nginx/conf/nginx.conf syntax is ok nginx: configuration file /home/ubuntu/nginx/conf/nginx.conf test is successful #讀取-c引數後指定的nginx.conf配置檔案來啟動Nginx root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -c /home/ubuntu/nginx/conf/nginx.conf #使用-p引數指定Nginx的安裝目錄 root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ./nginx -p /home/ubuntu/nginx
熱部署
root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ps -ef |grep nginx root 26122 1 0 16:57 ? 00:00:00 nginx: master process ./nginx nobody 26409 26122 0 16:58 ? 00:00:00 nginx: worker process root 27449 26146 0 17:03 pts/1 00:00:00 grep --color=auto nginx #替換nginx二進位制檔案 root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# cp nginx nginx.old #平滑部署 root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# kill -USR2 26122 root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ps -ef |grep nginx root 26122 1 0 16:57 ? 00:00:00 nginx: master process ./nginx nobody 26409 26122 0 16:58 ? 00:00:00 nginx: worker process root 28580 26122 0 17:08 ? 00:00:00 nginx: master process ./nginx nobody 28581 28580 0 17:08 ? 00:00:00 nginx: worker process root 28607 26146 0 17:08 pts/1 00:00:00 grep --color=auto nginx #kill老master程序 root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# kill -WINCH 26122 root@VM-4-4-ubuntu:/home/ubuntu/nginx/sbin# ps -ef |grep nginx root 26122 1 0 16:57 ? 00:00:00 nginx: master process ./nginx root 28580 26122 0 17:08 ? 00:00:00 nginx: master process ./nginx nobody 28581 28580 0 17:08 ? 00:00:00 nginx: worker process root 28750 26146 0 17:09 pts/1 00:00:00 grep --color=auto nginx
切割日誌檔案
root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# ls -l total 12 -rw-r--r-- 1 ubuntu ubuntu 0 May 8 16:57 access.log -rw-r--r-- 1 ubuntu ubuntu 1610 May 8 17:08 error.log #1610位元組內容 -rw-r--r-- 1 root root 6 May 8 17:08 nginx.pid -rw-r--r-- 1 root root 6 May 8 16:57 nginx.pid.oldbin root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# mv error.log /home/ubuntu/error.log.bak root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# ../sbin/nginx -s reopen #重新生成error日誌檔案 root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs# ll total 20 drwxrwxr-x 2 ubuntu ubuntu 4096 May 8 17:15 ./ drwxrwxr-x 11 ubuntu ubuntu 4096 May 8 16:57 ../ -rw-r--r-- 1 nobody ubuntu 0 May 8 16:57 access.log -rw-r--r-- 1 nobody root 61 May 8 17:15 error.log #空檔案 -rw-r--r-- 1 root root 6 May 8 17:08 nginx.pid -rw-r--r-- 1 root root 6 May 8 16:57 nginx.pid.oldbin root@VM-4-4-ubuntu:/home/ubuntu/nginx/logs#
具體資料:https://blog.csdn.net/weixin_46389787/article/details/116941097