「四」命令行、热部署、日志切割
命令行
- 格式: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