关闭防火墙,让本地可以通过浏览器访问Nginx
服务。
[root@localhost ~]# systemctl stop firewalld
信号量
查看信号量:
[root@localhost ~]# kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAX
有64
种信号量,以下是几种常用的信号量:
SIGINT
、SIGTERM
:快速关闭。SIGQUIT
:从容关闭(优雅的关闭进程,即等请求结束后再关闭)。SIGHUP
:平滑重启,重新加载配置文件 (平滑重启,修改配置文件之后不用重启服务器)。SIGUSR1
:重新读取日志文件,在切割日志文件时用途较大。SIGUSR2
:平滑升级可执行程序 ,nginx
升级时候用。SIGWINCH
:从容关闭工作进程。
Nginx热部署
Nginx
是一个多进程的高性能反向代理服务器,包含一个master
进程和多个worker
进程(worker
进程的数量可以通过nginx.conf
配置文件中的worker_processes
参数进行设置,默认1
个),这样可以充分利用多核处理器。
默认1
个worker
进程。
并且master
进程和worker
进程是父子进程关系。
Nginx
工作模式为多进程,Nginx
在启动之后会有一个master
进程和多个worker
进程(默认1
个),多个worker
子进程将监听master
父进程监听的端口(参考父子进程的关系),并行处理请求。master
父进程主要用来管理worker
子进程(管理真正提供服务的worker
进程,向worker
进程发送信号,监控worker
进程的运行状态,当worker
进程异常退出后,会重新启动新的worker
进程),读取并验证配置信息,master
进程不会对用户请求提供服务,而用户请求是由worker
进程进行处理。
Nginx
是通过信号量来控制,比如停止和重启Nginx
。信号量是进程间通信的一种机制,master
主进程控制多个worker
子进程,也是通过信号量。
现在来演示Nginx
是怎么实现热部署的,博主通过修改Nginx
的配置文件来模拟Nginx
的升级(先copy
一份副本)。
[root@localhost ~]# cd /usr/local/nginx/conf/ [root@localhost conf]# ll 总用量 68 -rw-r--r--. 1 root root 1077 12月 20 20:24 fastcgi.conf -rw-r--r--. 1 root root 1077 12月 20 20:24 fastcgi.conf.default -rw-r--r--. 1 root root 1007 12月 20 20:24 fastcgi_params -rw-r--r--. 1 root root 1007 12月 20 20:24 fastcgi_params.default -rw-r--r--. 1 root root 2837 12月 20 20:24 koi-utf -rw-r--r--. 1 root root 2223 12月 20 20:24 koi-win -rw-r--r--. 1 root root 5231 12月 20 20:24 mime.types -rw-r--r--. 1 root root 5231 12月 20 20:24 mime.types.default -rw-r--r--. 1 root root 2656 12月 20 21:26 nginx.conf -rw-r--r--. 1 root root 2656 12月 20 20:24 nginx.conf.default -rw-r--r--. 1 root root 636 12月 20 20:24 scgi_params -rw-r--r--. 1 root root 636 12月 20 20:24 scgi_params.default -rw-r--r--. 1 root root 664 12月 20 20:24 uwsgi_params -rw-r--r--. 1 root root 664 12月 20 20:24 uwsgi_params.default -rw-r--r--. 1 root root 3610 12月 20 20:24 win-utf [root@localhost conf]# cp nginx.conf nginx_old.conf [root@localhost conf]# vim nginx.conf
由于还没有给Nginx
进行热部署,现在访问http://192.168.1.199/
还是原来的Nginx
页面。
查看Nginx
的进程:
[root@localhost conf]# ps -ef | grep nginx root 14964 1 0 22:25 ? 00:00:00 nginx: master process ./nginx nobody 14965 14964 0 22:25 ? 00:00:00 nginx: worker process root 15016 1521 0 23:07 pts/0 00:00:00 grep --color=auto nginx
给master
进程发送SIGUSR2
信号,让Nginx
平滑升级可执行程序。可以看到Nginx
重新启动了一组master
进程和worker
进程,而新master
进程是旧master
进程的子进程(通过父子进程的继承关系,新master
进程可以很方便地继承旧master
进程的相关资源)。
[root@localhost conf]# kill -s SIGUSR2 14964 [root@localhost conf]# ps -ef | grep nginx root 14964 1 0 22:25 ? 00:00:00 nginx: master process ./nginx nobody 14965 14964 0 22:25 ? 00:00:00 nginx: worker process root 15019 14964 0 23:18 ? 00:00:00 nginx: master process ./nginx nobody 15020 15019 0 23:18 ? 00:00:00 nginx: worker process root 15022 1521 0 23:19 pts/0 00:00:00 grep --color=auto nginx
并且Nginx
在日志目录中存储了新旧pid
文件(保存了新旧master
进程的ID
)。
[root@localhost conf]# ll ../logs 总用量 16 -rw-r--r--. 1 root root 2729 12月 20 23:20 access.log -rw-r--r--. 1 root root 708 12月 20 23:18 error.log -rw-r--r--. 1 root root 6 12月 20 23:18 nginx.pid -rw-r--r--. 1 root root 6 12月 20 22:25 nginx.pid.oldbin [root@localhost conf]# cat ../logs/nginx.pid 15019 [root@localhost conf]# cat ../logs/nginx.pid.oldbin 14964
给旧master
进程发送SIGWINCH
信号,让旧master
进程关闭旧worker
进程。
[root@localhost conf]# kill -s SIGWINCH 14964 [root@localhost conf]# ps -ef | grep nginx root 14964 1 0 22:25 ? 00:00:00 nginx: master process ./nginx root 15019 14964 0 23:18 ? 00:00:00 nginx: master process ./nginx nobody 15020 15019 0 23:18 ? 00:00:00 nginx: worker process root 15030 1521 0 23:27 pts/0 00:00:00 grep --color=auto nginx
现在访问http://192.168.1.199/
,会响应404
。
而访问http://192.168.1.199/nacos
,会访问到Nacos
服务。
如果升级版本没有问题,就可以给旧master
进程发送SIGQUIT
信号,让旧master
进程关闭,这样就只剩下新master
进程和新worker
进程,实现了Nginx
的热部署。
[root@localhost conf]# kill -s SIGQUIT 14964 [root@localhost conf]# ps -ef | grep nginx root 15019 1 0 23:18 ? 00:00:00 nginx: master process ./nginx nobody 15020 15019 0 23:18 ? 00:00:00 nginx: worker process root 15034 1521 0 23:31 pts/0 00:00:00 grep --color=auto nginx
如果升级版本有问题,需要回滚到之前的版本,就可以给旧master
进程发送SIGHUP
信号,因为博主重新进行了测试,所以进程号都变了,但很显然旧master
进程重新创建了旧worker
进程,并且进行版本升级的master
和worker
进程没有被关闭。
[root@localhost conf]# kill -s SIGHUP 15084 [root@localhost conf]# ps -ef | grep nginx root 15084 1 0 12月20 ? 00:00:00 nginx: master process ./nginx root 15106 15084 0 12月20 ? 00:00:00 nginx: master process ./nginx nobody 15107 15106 0 12月20 ? 00:00:00 nginx: worker process nobody 15131 15084 0 00:02 ? 00:00:00 nginx: worker process root 15141 1521 0 00:09 pts/0 00:00:00 grep --color=auto nginx
给新master
进程发送SIGQUIT
信号,让新master
进程关闭,这样就只剩下旧master
进程和新创建的旧worker
进程,实现了回滚。
[root@localhost conf]# kill -s SIGQUIT 15106 [root@localhost conf]# ps -ef | grep nginx root 15084 1 0 12月20 ? 00:00:00 nginx: master process ./nginx nobody 15131 15084 0 00:02 ? 00:00:00 nginx: worker process root 15159 1521 0 00:25 pts/0 00:00:00 grep --color=auto nginx
回滚成功。
还需要对版本回滚(即博主这里的配置文件回滚,不然下次重启就会出问题)。
[root@localhost conf]# cp -f nginx_old.conf nginx.conf cp:是否覆盖"nginx.conf"? y
为什么给旧master
进程发送SIGHUP
信号,旧master
进程重新创建的worker
进程没有重新读取配置文件?下面是官方的说明:
Send the HUP signal to the old master process. The old master process will start new worker processes without re-reading the configuration. After that, all new processes can be shut down gracefully, by sending the QUIT signal to the new master process.
向旧
master
进程发送SIGHUP
信号。旧master
进程将启动新worker
进程,而无需重新读取配置。之后,通过向新master
进程发送SIGQUIT
信号,所有新进程都可以正常关闭。
如果不存在新进程的情况下(只有一组master
、worker
进程),修改配置文件,再向master
进程发送SIGHUP
信号,看是否会重新加载配置文件。
[root@localhost conf]# kill -s SIGHUP 15084
很显然配置文件被重新加载了,由于博主还没有看源码,只能猜测Nginx
的实现(如果说错了,请大家评论补充),Nginx
应该是根据当前是否在进行热部署(存在新master
进程),来决定SIGHUP
信号是否需要重新加载配置文件。
以上是Nginx热部署如何实现的详细内容。更多信息请关注PHP中文网其他相关文章!

本篇文章给大家带来了关于nginx的相关知识,其中主要介绍了nginx拦截爬虫相关的,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

高并发系统有三把利器:缓存、降级和限流;限流的目的是通过对并发访问/请求进行限速来保护系统,一旦达到限制速率则可以拒绝服务(定向到错误页)、排队等待(秒杀)、降级(返回兜底数据或默认数据);高并发系统常见的限流有:限制总并发数(数据库连接池)、限制瞬时并发数(如nginx的limit_conn模块,用来限制瞬时并发连接数)、限制时间窗口内的平均速率(nginx的limit_req模块,用来限制每秒的平均速率);另外还可以根据网络连接数、网络流量、cpu或内存负载等来限流。1.限流算法最简单粗暴的

nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

实验环境前端nginx:ip192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡后端nginx:ip192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据下面配置192.168.6.205这台服务器vim/etc/rsyncd.confuid=nginxgid=nginxport=873ho

跨域是开发中经常会遇到的一个场景,也是面试中经常会讨论的一个问题。掌握常见的跨域解决方案及其背后的原理,不仅可以提高我们的开发效率,还能在面试中表现的更加

linux版本:64位centos6.4nginx版本:nginx1.8.0php版本:php5.5.28&php5.4.44注意假如php5.5是主版本已经安装在/usr/local/php目录下,那么再安装其他版本的php再指定不同安装目录即可。安装php#wgethttp://cn2.php.net/get/php-5.4.44.tar.gz/from/this/mirror#tarzxvfphp-5.4.44.tar.gz#cdphp-5.4.44#./configure--pr

nginx部署react刷新404的解决办法:1、修改Nginx配置为“server {listen 80;server_name https://www.xxx.com;location / {root xxx;index index.html index.htm;...}”;2、刷新路由,按当前路径去nginx加载页面即可。

nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。