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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值