栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

nginx平滑升级时,需要在运行的nginx是以全路径启动的

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nginx平滑升级时,需要在运行的nginx是以全路径启动的

在平滑升级nginx的时候,如果不给出nginx程序的全路径的话,会出现USR2信号没起作用的情况

具体如下

验证 用nginx命令直接启动,不给全路径
[root@vm2 ~]# ll /usr/local/nginx/sbin/
total 30556
-rwxr-xr-x 1 nginx nginx 5175248 Feb  7 11:32 nginx
-rwxr-xr-x 1 nginx nginx 7934392 Feb  6 20:27 nginx.old
-rwxr-xr-x 1 nginx nginx 7934392 Feb  7 11:09 nginx.old2
-rwxr-xr-x 1 nginx nginx 5175248 Feb  7 11:32 nginx.old3
-rwxr-xr-x 1 nginx nginx 5055968 Feb  7 11:39 nginx.old4

[root@vm2 ~]# ll /usr/sbin/nginx
lrwxrwxrwx 1 root root 27 Feb  6 20:31 /usr/sbin/nginx -> /usr/local/nginx/sbin/nginx

[root@vm2 ~]# nginx -V
nginx version: nginx/1.20.2
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx

# 启动nginx,不给全路径

[root@vm2 ~]# nginx
[root@vm2 ~]# pstree -p | grep nginx
           |-nginx(12096)---nginx(12097)

[root@vm2 ~]# cat /usr/local/nginx/logs/nginx.pid
12096

# 升级二进制

[root@vm2 ~]# rm -f /usr/local/nginx/sbin/nginx
[root@vm2 ~]# cp -p /usr/local/nginx/sbin/nginx.old4 /usr/local/nginx/sbin/nginx

[root@vm2 ~]# nginx -V
nginx version: nginx/1.21.6
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx

# 发送USR2。没有新的,master

[root@vm2 ~]# kill -USR2 12096
[root@vm2 ~]# ps -ef | grep nginx
root       12096       1  0 12:10 ?        00:00:00 nginx: master process nginx
nginx      12097   12096  0 12:10 ?        00:00:00 nginx: worker process
root       12109    1124  0 12:12 pts/1    00:00:00 grep --color=auto nginx
[root@vm2 ~]#


非软连接的全路径
[root@vm2 ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.20.2
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx

# 用不是软连接的全路径
[root@vm2 ~]# /usr/local/nginx/sbin/nginx
[root@vm2 ~]# ps -ef | grep nginx
root       12119       1  0 12:15 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx      12120   12119  0 12:15 ?        00:00:00 nginx: worker process
root       12122    1124  0 12:16 pts/1    00:00:00 grep --color=auto nginx

[root@vm2 ~]# cat /usr/local/nginx/logs/nginx.pid
12119

# 换新程序

[root@vm2 ~]# rm -f /usr/local/nginx/sbin/nginx
[root@vm2 ~]# cp -p /usr/local/nginx/sbin/nginx.old4 /usr/local/nginx/sbin/nginx

[root@vm2 ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.21.6
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx

# 发送USR2,有新master进程

[root@vm2 ~]# kill -USR2 12119
[root@vm2 ~]# ps -ef | grep nginx
root       12119       1  0 12:15 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx      12120   12119  0 12:15 ?        00:00:00 nginx: worker process
root       12127   12119  0 12:17 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx      12128   12127  0 12:17 ?        00:00:00 nginx: worker process
root       12130    1124  0 12:17 pts/1    00:00:00 grep --color=auto nginx

全路径的软连接
[root@vm2 ~]# which nginx
/usr/sbin/nginx
[root@vm2 ~]# ll /usr/sbin/nginx
lrwxrwxrwx 1 root root 27 Feb  6 20:31 /usr/sbin/nginx -> /usr/local/nginx/sbin/nginx
[root@vm2 ~]# /usr/sbin/nginx -V
nginx version: nginx/1.20.2
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx

# 使用全路径软连接
[root@vm2 ~]# /usr/sbin/nginx
[root@vm2 ~]# pstree -p | grep nginx
           |-nginx(12147)---nginx(12148)

[root@vm2 ~]# ps -ef | grep nginx
root       12147       1  0 12:22 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx      12148   12147  0 12:22 ?        00:00:00 nginx: worker process
root       12152    1124  0 12:22 pts/1    00:00:00 grep --color=auto nginx

# 换新程序

[root@vm2 ~]# rm -f /usr/local/nginx/sbin/nginx
[root@vm2 ~]# cp -p /usr/local/nginx/sbin/nginx.old4 /usr/local/nginx/sbin/nginx

# 发送USR2,有新的master进程

[root@vm2 ~]# kill -USR2 12147
[root@vm2 ~]# ps -ef | grep nginx
root       12147       1  0 12:22 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx      12148   12147  0 12:22 ?        00:00:00 nginx: worker process
root       12155   12147  0 12:23 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx      12156   12155  0 12:23 ?        00:00:00 nginx: worker process
root       12158    1124  0 12:23 pts/1    00:00:00 grep --color=auto nginx

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/729215.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号