启动Nginx、查看nginx进程、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级
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服务可接受的信号
|
信号 |
作用 |
|
TERM或INT |
快速停止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 (其中21094是master进程的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的路径
6、Nginx服务的重启
关于Nginx平滑重启,平滑重启是这样一个过程,Nginx服务进程接收到信号后,首先读取新的Nginx配置文件,如果配置语法正确,则启动新的Nginx服务,然后平缓关闭旧的服务进程;如果新的Nginx配置有问题,将显示错误,仍然使用旧的Nginx提供服务。
使用以下命令实现Nginx服务的平滑重启
./nginx –g HUP [-c newConfFile]
HUP信号用于发送平滑重启信号。
newConfFile,可选项,用于指定新配置文件的路径
或者,使用新的配置文件代替了旧的配置文件后,使用:
Kill HUP `nginx.pid` (注意最后一个参数连边的引号;引号里面是nginx.pid的路径)
也可以实现平滑重启。
7、Nginx服务器的升级
如果要对当前的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服务器的升级的更多相关文章
- 一个命令解决linux重启nginx就丢失pid文件问题
sudo nginx -c /etc/nginx/nginx.conf
- java web项目在linux部署、启动,查看系统配置常用的linux命令总结
本文为博主原创,未经允许不得转载: 以下为在工作中常用的linux命令进行了总结,主要在项目安装及启动,及编辑部署文件时应用较多1.gz文件是一种压缩文件. 以·tar.gz为扩展名的是一种压缩文件, ...
- 【学习笔记】启动Nginx、查看nginx进程、查看nginx服务主进程的方式、Nginx服务可接受的信号、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级
1.启动nginx的方式: cd /usr/local/nginx ls ./nginx -c nginx.conf 2.查看nginx的进程方式: [root@localhost nginx] ...
- Nginx 的启动、停止、平滑重启、信号控制和平滑升级
Nginx 的启动 假设 nginx 安装在 /usr/local/nginx 目录中,那么启动 nginx 的命令就是: [root@localhost ~]# /usr/local ...
- Nginx启动、停止与平滑重启
如何启动Nginx:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 停止Nginx:可以发送向通信号给Nginx主进程的 ...
- Nginx的启动、停止、平滑重启
转载自:http://www.xj123.info/2572.html 启动Nginx /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/ngi ...
- Nginx的平滑重启和平滑升级
一,Nginx的平滑重启如果改变了Nginx的配置文件(nginx.conf),想重启Nginx,可以发送系统信号给Nginx主进程的方式来进行.在重启之前,要确认Nginx配置文件的语法是正确的. ...
- (转)不停止Nginx服务的情况下平滑变更Nginx配置
在不停止Nginx服务的情况下平滑变更Nginx配置 1.修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确: /u ...
- nginx定时备份access访问日志并重启nginx
用.sh脚本写了备份日志脚本 其实就是转移文件改名后重新建一个空文件 mv /alidata/log/nginx/access/wxtest.log /alidata/log/nginx/access ...
随机推荐
- sysbench - 数据库功能及性能测试工具
sysbench 的 GitHub 参考资料 1.0 之后的版本使用方法跟之前的有所区别,下面所有内容基于 1.0.9 版本. 另外,为了方便管理测试,最好不要通过命令直接运行测试,而是写成脚本自动化 ...
- poj3669 Meteor Shower (宽度优先搜索)
Description - 题目描述 Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平面坐标系的原点放牧,打算在群星 ...
- 15.队列Queue的特点以及使用,优先级等
#生产者与消费者模式,模式解释:比如MVC设计模式 ''' 1.队列 (1)特点:先进先出 (2)python2 VS python3 python2:from Queue import queue ...
- 记一次Laravel 定时任务schedul:run未执行的处理
关于Laravel的任务调度(定时任务)的配置在此不做赘述,跟着官方文档一步一步的操作是不会导致定时任务不能正常工作的. 为保证能及时捕获定时任务执行出现异常的原因,只需在配置系统crontab时指定 ...
- Survey Results for Rebecca Murpheys Learning JavaScript Survey
时间 2016-01-27 05:40:46 Raymond Camden's Blog 原文 http://www.raymondcamden.com/2016/01/25/survey-res ...
- PHP_CodeIgniter _remap重新定义方法
如果controller定义了_remap方法, 在_remap中重新定义方法 class Test extends CI_Controller{ public function index(){ e ...
- topic模式下的收发
生产者: import pika import sys connection = pika.BlockingConnection(pika.ConnectionParameters( host='lo ...
- C# WCF 服务引用与Web引用
参考:https://blog.csdn.net/yelin042/article/details/82770205
- Java实现二分法(折半)查找数组中的元素
二分查找 算法思想:又叫折半查找,要求待查找的序列有序.每次取中间位置的值与待查关键字比较,如果中间位置的值比待查关键字大,则在前半部分循环这个查找的过程,如果中间位置的值比待查关键字小,则在后半部分 ...
- turtle库使用
turtle库的使用 绘图窗体布局 turtle.setup(width,height,startx,straty) 用来控制窗体的大小与位置,其中后width与height用来控制窗体的大小,sta ...