Linux 服务升级:Nginx 热升级 与 平滑回退
目录
一、实验
1.环境
2.Kali Linux 使用nmap扫描CentOS
3.Kali Linux 远程CentOS
4.Kali Linux 使用openvas 扫描 CentOS
5.Nginx 热升级
6.Nginx 平滑回退
二、问题
1.kill命令的信号有哪些
2.平滑升级与回退的信号
一、实验
1.环境
(1)主机
表1 主机
| 系统 | 版本 | IP | 备注 |
| CentOS | 7.9 | 192.168.204.200 | nginx升级主机 |
| Kali Linux | 2024.1 | 192.168.204.146(动态) 192.168.204.100(静态) | 已部署openvas |
(2)查看Kali Linux (2024.1)系统版本
cat /etc/os-release

(3)查看Kali Linux (2024.1)系统IP地址
ip addr

2.Kali Linux 使用nmap扫描CentOS
(1)扫描网段存活主机
nmap -sP 192.168.204.0/24
(2)扫描主机
nmap 192.168.204.200

(3)扫描主机系统
nmap -O 192.168.204.200

(4)扫描22端口开放情况
nmap -sS -p 22 192.168.204.200

(5)hydra 破解密码
hydra -l root -P test.txt 192.168.204.200 ssh

3.Kali Linux 远程CentOS
(1)远程
ssh root@192.168.204.200

(2)查看nginx版本
系统做了版本隐藏与修改
[root@www ~]# nginx -v
![]()
(3)查看进程
nginx未启动
[root@www ~]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3061 0.0 0.0 112676 984 pts/1 R+ 12:32 0:00 grep --color=auto nginx
[root@www ~]#
[root@www ~]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 3063 3006 0 12:32 pts/1 00:00:00 grep --color=auto -E CMD|nginx

测试
[root@www ~]# curl -I 127.0.0.1
curl: (7) Failed connect to 127.0.0.1:80; 拒绝连接[root@www ~]# curl -I 192.168.204.200
curl: (7) Failed connect to 192.168.204.200:80; 拒绝连接
![]()

(4)查看nginx安装位置
[root@www ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/local/sbin/nginx /usr/local/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz

(5)重启服务
[root@www ~]# systemctl restart nginx
![]()
测试
[root@www ~]# curl -I 192.168.204.200
HTTP/1.1 200 OK
Server: IIS777
Date: Tue, 19 Mar 2024 04:34:59 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 59
Last-Modified: Tue, 04 Jul 2023 13:39:01 GMT
Connection: keep-alive
ETag: "64a420f5-3b"
Accept-Ranges: bytes[root@www ~]# curl -I 192.168.204.200
HTTP/1.1 200 OK
Server: IIS777
Date: Tue, 19 Mar 2024 04:35:01 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 59
Last-Modified: Tue, 04 Jul 2023 13:39:01 GMT
Connection: keep-alive
ETag: "64a420f5-3b"
Accept-Ranges: bytes
(6)查看进程
nginx已启动
[root@www ~]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3142 0.0 0.0 20532 688 ? Ss 12:34 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 3143 0.2 0.1 24292 2724 ? S 12:34 0:00 nginx: worker process
nginx 3144 0.0 0.1 24292 2724 ? S 12:34 0:00 nginx: worker process
nginx 3145 0.0 0.1 24292 2724 ? S 12:34 0:00 nginx: worker process
nginx 3146 0.0 0.1 24292 2724 ? S 12:34 0:00 nginx: worker process
nginx 3147 0.0 0.1 24292 2724 ? S 12:34 0:00 nginx: worker process
nginx 3148 0.0 0.1 24292 2724 ? S 12:34 0:00 nginx: worker process
nginx 3149 0.0 0.1 24292 2724 ? S 12:34 0:00 nginx: worker process
nginx 3150 0.2 0.1 24292 2972 ? S 12:34 0:00 nginx: worker process
root 3158 0.0 0.0 112676 984 pts/1 S+ 12:35 0:00 grep --color=auto nginx
[root@www ~]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 3142 1 0 12:34 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 3143 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3144 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3145 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3146 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3147 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3148 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3149 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3150 3142 0 12:34 ? 00:00:00 nginx: worker process
root 3160 3006 0 12:35 pts/1 00:00:00 grep --color=auto -E CMD|nginx

(7)继续查看版本
[root@www ~]# nginx -v
nginx version: IIS777
[root@www ~]#
[root@www ~]# rpm -qa | grep nginx
nginx-filesystem-1.20.1-10.el7.noarch
nginx-1.20.1-10.el7.x86_64
[root@www ~]# /usr/local/sbin/nginx -V
nginx version: IIS777
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

(8)查看nginx文件
本机存在2个版本的安装包
[root@www nginx]# find / -name nginx*


(9)查看配置文件
确定本机安装版本为1.22.0
[root@www nginx]# vim /usr/local/nginx/conf/nginx.conf

[root@www nginx]# vim /opt/nginx-1.22.0/src/core/nginx.h
![]()

4.Kali Linux 使用openvas 扫描 CentOS
(1)端口列表(Port Lists)
Configuration - Port Lists

(2)创建端口
选择带星号图标


(3)弹出界面

(4)扫描80端口

(5)新增http

(5)目标主机(Targets)
Configuration - Targets

(6) 创建扫描目标
选择带星号图标


(7)弹出界面

(8)扫描目标

(9)扫描任务
Scans -Tasks

(10) 创建扫描任务
选择带星号图标


(11)弹出界面

(12)设置

查看扫描方式

(14)查看,点击底部播放按钮

(15)开始扫描
观察变化






(16)查看扫描结果
Scans -Reports
点击左下角时间查看信息

(17)下载报告
点击左上角下载图标

(18)弹出界面

查看下载类型

选择PDF

5.Nginx 热升级
(1)查看版本
最新版本为1.25.4
https://nginx.org/download/

(2)下载
[root@www opt]# wget no-check-certificate https://nginx.org/download/nginx-1.25.4.tar.gz

(3)备份
[root@www nginx-1.25.4]# cd ~
[root@www ~]# cd /usr/local/nginx
[root@www nginx]# ls
client_body_temp conf fastcgi_temp html logs passwd.db proxy_temp sbin scgi_temp uwsgi_temp
[root@www nginx]# cd ..
[root@www local]# ls
bin etc games include lib lib64 libexec mysql nginx php sbin share src stress
[root@www local]# cp -pr ./nginx ./nginx_20240319_1.22.0
[root@www local]# ls
bin etc games include lib lib64 libexec mysql nginx nginx_20240319_1.22.0 php sbin share src stress

(4)解压
[root@www opt]# tar xf nginx-1.25.4.tar.gz
![]()
(5)编译
[root@www local]# cd /opt/nginx-1.25.4/
[root@www nginx-1.25.4]# ls#这里指定的安装路径前缀和老的nginx保持一致
[root@www nginx-1.25.4]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module


[root@www nginx-1.25.4]# make
![]()

(6)验证
[root@www nginx-1.25.4]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@www nginx-1.25.4]# cd objs
[root@www objs]# ls
autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src

(7)备份旧的Nginx二进制
[root@www objs]# cd /usr/local/sbin
[root@www sbin]# ls
nginx php-fpm
[root@www sbin]# mv ./nginx ./nginx_1.22.0
[root@www sbin]# ls
nginx_1.22.0 php-fpm

(8)拷贝新的Nginx二进制
[root@www sbin]# cd ..
[root@www local]# ls
bin etc games include lib lib64 libexec mysql nginx nginx_20240319_1.22.0 php sbin share src stress
[root@www local]# cp -pr /opt/nginx-1.25.4/objs/nginx ./sbin

查看
[root@www local]# cd sbin
[root@www sbin]# ls
nginx nginx_1.22.0 php-fpm

(9)向旧的master发送USR2信号
查看旧的master进程PID为3142
[root@www sbin]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 3142 1 0 12:34 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 3143 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3144 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3145 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3146 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3147 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3148 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3149 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3150 3142 0 12:34 ? 00:00:01 nginx: worker process
root 10884 3006 0 14:09 pts/1 00:00:00 grep --color=auto -E CMD|nginx
[root@www sbin]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3142 0.0 0.0 20532 688 ? Ss 12:34 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 3143 0.0 0.1 24292 2964 ? S 12:34 0:00 nginx: worker process
nginx 3144 0.0 0.1 24292 2972 ? S 12:34 0:00 nginx: worker process
nginx 3145 0.0 0.1 24292 2968 ? S 12:34 0:00 nginx: worker process
nginx 3146 0.0 0.1 24292 2972 ? S 12:34 0:00 nginx: worker process
nginx 3147 0.0 0.1 24292 2968 ? S 12:34 0:00 nginx: worker process
nginx 3148 0.0 0.1 24292 2968 ? S 12:34 0:00 nginx: worker process
nginx 3149 0.0 0.1 24292 2972 ? S 12:34 0:00 nginx: worker process
nginx 3150 0.0 0.1 24292 2972 ? S 12:34 0:01 nginx: worker process
root 10922 0.0 0.0 112676 984 pts/1 S+ 14:10 0:00 grep --color=auto nginx

(10)确认nginx.pid位置
[root@www run]# cd /usr/local/nginx[root@www nginx]# find ./ -name nginx.pid
./logs/nginx.pid
[root@www nginx]# cat ./logs/nginx.pid
3142
![]()

(11) 热升级
[root@www nginx]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid `
![]()
查看进程
[root@www nginx]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 3142 1 0 12:34 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 3143 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3144 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3145 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3146 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3147 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3148 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3149 3142 0 12:34 ? 00:00:00 nginx: worker process
nginx 3150 3142 0 12:34 ? 00:00:01 nginx: worker process
root 12211 3142 0 14:32 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12213 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12214 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12215 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12216 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12217 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12218 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12219 12211 0 14:32 ? 00:00:00 nginx: worker process
root 12238 3006 0 14:32 pts/1 00:00:00 grep --color=auto -E CMD|nginx
[root@www nginx]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3142 0.0 0.0 20532 844 ? Ss 12:34 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 3143 0.0 0.1 24292 2964 ? S 12:34 0:00 nginx: worker process
nginx 3144 0.0 0.1 24292 2972 ? S 12:34 0:00 nginx: worker process
nginx 3145 0.0 0.1 24292 2968 ? S 12:34 0:00 nginx: worker process
nginx 3146 0.0 0.1 24292 2972 ? S 12:34 0:00 nginx: worker process
nginx 3147 0.0 0.1 24292 2968 ? S 12:34 0:00 nginx: worker process
nginx 3148 0.0 0.1 24292 2968 ? S 12:34 0:00 nginx: worker process
nginx 3149 0.0 0.1 24292 2972 ? S 12:34 0:00 nginx: worker process
nginx 3150 0.0 0.1 24292 2972 ? S 12:34 0:01 nginx: worker process
root 12211 0.0 0.0 20536 1692 ? S 14:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12213 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12214 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12215 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12216 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12217 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12218 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12219 0.0 0.1 24296 2452 ? S 14:32 0:00 nginx: worker process
root 12249 0.0 0.0 112676 980 pts/1 R+ 14:32 0:00 grep --color=auto nginx
发现有两个master进程,第二个master进程就是新的主进程,并且是作为老进程的子进程启动的。

并且nginx会将老的pid文件命名为nginx.pid.oldbin。
[root@www logs]# ll | head -1 ;ll |grep nginx.pid
总用量 5904
-rw-r--r--. 1 root root 6 3月 19 14:32 nginx.pid
-rw-r--r--. 1 root root 5 3月 19 12:34 nginx.pid.oldbin

[root@www logs]# ll /usr/local/nginx/logs/nginx.pid.oldbin
-rw-r--r--. 1 root root 5 3月 19 12:34 /usr/local/nginx/logs/nginx.pid.oldbin
![]()
查看PID
[root@www logs]# cat nginx.pid
12211
[root@www logs]# cat nginx.pid.oldbin
3142

(12)向旧master发送winch信号
[root@www logs]# kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
![]()
[root@www logs]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 3142 1 0 12:34 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root 12211 3142 0 14:32 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12213 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12214 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12215 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12216 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12217 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12218 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12219 12211 0 14:32 ? 00:00:00 nginx: worker process
root 12887 3006 0 14:43 pts/1 00:00:00 grep --color=auto -E CMD|nginx
[root@www logs]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3142 0.0 0.0 20532 844 ? Ss 12:34 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 12211 0.0 0.0 20536 1692 ? S 14:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 0.0 0.1 24296 2968 ? S 14:32 0:00 nginx: worker process
nginx 12213 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12214 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12215 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12216 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12217 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12218 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12219 0.0 0.1 24296 2452 ? S 14:32 0:00 nginx: worker process
root 12899 0.0 0.0 112676 984 pts/1 R+ 14:43 0:00 grep --color=auto nginx
平滑关闭旧master的worker进程

(13)向旧master发送QUIT信号
[root@www logs]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
![]()
[root@www logs]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 12211 1 0 14:32 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12213 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12214 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12215 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12216 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12217 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12218 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12219 12211 0 14:32 ? 00:00:00 nginx: worker process
root 13069 3006 0 14:46 pts/1 00:00:00 grep --color=auto -E CMD|nginx
[root@www logs]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 12211 0.0 0.0 20536 1692 ? S 14:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 0.0 0.1 24296 2968 ? S 14:32 0:00 nginx: worker process
nginx 12213 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12214 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12215 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12216 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12217 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12218 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12219 0.0 0.1 24296 2452 ? S 14:32 0:00 nginx: worker process
root 13084 0.0 0.0 112676 984 pts/1 R+ 14:46 0:00 grep --color=auto nginx

(14)创建软连接
[root@www logs]# ln -s /usr/local/nginx/sbin/nginx /bin/
![]()
(15)验证
[root@www logs]# nginx -V
nginx version: nginx/1.25.4
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

6.Nginx 平滑回退
(1)替换nginx二进制文件
查看
[root@www logs]# cd /usr/local/sbin
[root@www sbin]# ls
nginx nginx_1.22.0 php-fpm

替换
[root@www sbin]# mv nginx nginx_1.25.4
[root@www sbin]# ls
nginx_1.22.0 nginx_1.25.4 php-fpm
[root@www sbin]# mv nginx_1.22.0 nginx
[root@www sbin]# ls
nginx nginx_1.25.4 php-fpm

(2)向旧的master发送USR2信号
查看PID
[root@www logs]# cat /usr/local/nginx/logs/nginx.pid
12211

[root@www logs]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid `
![]()
查看进程
[root@www logs]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 12211 1 0 14:32 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12213 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12214 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12215 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12216 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12217 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12218 12211 0 14:32 ? 00:00:00 nginx: worker process
nginx 12219 12211 0 14:32 ? 00:00:00 nginx: worker process
root 14055 12211 0 15:02 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 14056 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14057 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14058 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14059 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14060 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14061 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14062 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14063 14055 0 15:02 ? 00:00:00 nginx: worker process
root 14077 3006 0 15:02 pts/1 00:00:00 grep --color=auto -E CMD|nginx
[root@www logs]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 12211 0.0 0.0 20536 1692 ? S 14:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12212 0.0 0.1 24296 2968 ? S 14:32 0:00 nginx: worker process
nginx 12213 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12214 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12215 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12216 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12217 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12218 0.0 0.1 24296 2712 ? S 14:32 0:00 nginx: worker process
nginx 12219 0.0 0.1 24296 2452 ? S 14:32 0:00 nginx: worker process
root 14055 0.0 0.0 20536 1696 ? S 15:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 14056 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14057 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14058 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14059 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14060 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14061 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14062 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14063 0.0 0.1 24296 2456 ? S 15:02 0:00 nginx: worker process
root 14087 0.0 0.0 112676 984 pts/1 R+ 15:03 0:00 grep --color=auto nginx

nginx会将老的pid文件命名为nginx.pid.oldbin。
[root@www logs]# ll | head -1 ;ll |grep nginx.pid
总用量 5908
-rw-r--r--. 1 root root 6 3月 19 15:02 nginx.pid
-rw-r--r--. 1 root root 6 3月 19 14:32 nginx.pid.oldbin

查看PID
[root@www logs]# cat nginx.pid
14055
[root@www logs]# cat nginx.pid.oldbin
12211

(3)向旧的master发送WINCH信号
[root@www logs]# kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
![]()
查看进程
[root@www logs]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 12211 1 0 14:32 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root 14055 12211 0 15:02 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 14056 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14057 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14058 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14059 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14060 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14061 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14062 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14063 14055 0 15:02 ? 00:00:00 nginx: worker process
root 14290 3006 0 15:06 pts/1 00:00:00 grep --color=auto -E CMD|nginx
[root@www logs]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 12211 0.0 0.0 20536 1692 ? S 14:32 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 14055 0.0 0.0 20536 1696 ? S 15:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 14056 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14057 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14058 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14059 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14060 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14061 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14062 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14063 0.0 0.1 24296 2456 ? S 15:02 0:00 nginx: worker process
root 14305 0.0 0.0 112676 984 pts/1 R+ 15:06 0:00 grep --color=auto nginx

(4)向旧的master发送QUIT信号
[root@www logs]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
![]()
查看进程
[root@www logs]# ps -ef | grep -E "CMD|nginx"
UID PID PPID C STIME TTY TIME CMD
root 14055 1 0 15:02 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 14056 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14057 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14058 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14059 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14060 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14061 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14062 14055 0 15:02 ? 00:00:00 nginx: worker process
nginx 14063 14055 0 15:02 ? 00:00:00 nginx: worker process
root 14371 3006 0 15:07 pts/1 00:00:00 grep --color=auto -E CMD|nginx
[root@www logs]# ps axuw | head -1;ps axuw | grep nginx
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 14055 0.0 0.0 20536 1696 ? S 15:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 14056 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14057 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14058 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14059 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14060 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14061 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14062 0.0 0.1 24296 2716 ? S 15:02 0:00 nginx: worker process
nginx 14063 0.0 0.1 24296 2456 ? S 15:02 0:00 nginx: worker process
root 14377 0.0 0.0 112676 984 pts/1 R+ 15:07 0:00 grep --color=auto nginx

(5)验证
已恢复之前版本
[root@www logs]# nginx -V
nginx version: IIS777
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

二、问题
1.kill命令的信号有哪些
(1)查看信号
[root@www ~]# kill -l1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP6) 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

2.平滑升级与回退的信号
(1)信号
| 信号 | 数字 | 含义 |
| QUIT | 3 | 关闭 |
| HUP | 1 | 重启 |
| USR1 | 10 | 重新打开日志文件,repon |
| USR2 | 12 | 平滑升级可执行的二进制程序 |
| WINCH | 28 | 平滑关闭worker进程 |

相关文章:
Linux 服务升级:Nginx 热升级 与 平滑回退
目录 一、实验 1.环境 2.Kali Linux 使用nmap扫描CentOS 3.Kali Linux 远程CentOS 4.Kali Linux 使用openvas 扫描 CentOS 5.Nginx 热升级 6.Nginx 平滑回退 二、问题 1.kill命令的信号有哪些 2.平滑升级与回退的信号 一、实验 1.环境 (1)主机…...
能降低嵌入式系统功耗的三个技术
为电池寿命设计嵌入式系统已经成为许多团队重要的设计考虑因素。优化电池寿命的能力有助于降低现场维护成本,并确保客户不需要不断更换或充电电池,从而获得良好的产品体验。 团队通常使用一些标准技术来提高电池寿命,例如将处理器置于低功耗…...
暴力快速入门强化学习
强化学习算法的基本思想(直觉) 众所周知,强化学习是能让智能体实现某个具体任务的强大算法。 强化学习的基本思想是让智能体跟环境交互,通过环境的反馈让智能体调整自己的策略,从反馈中学习,不断学习来得到…...
vue中v-if和v-show的区别
手段:v-if是动态的向DOM树内添加或者删除DOM元素;v-show是通过设置DOM元素的display样式属性控制显隐;编译过程:v-if切换有一个局部编译/卸载的过程,切换过程中合适地销毁和重建内部的事件监听和子组件;v-s…...
MATLAB绘图
现学现用,用时再学。 plot函数:有两个向量被指定为参数,plot(x,y) 会生成 y 对 x 的图形 添加轴标签和标题: 通过调用一次 plot,多个 x-y 对组参数会创建多幅图形: 在每十个数据点处放置标记: 一个窗口绘制多个图形; 可在弹窗的插入选项上添加…...
嵌入式学习-ARM-Day4
嵌入式学习-ARM-Day4 实现三个LED灯亮灭 .text .global _start _start: 使能GPIOE的外设时钟 RCC_MP_AHB4ENSETR的第[4]设置为1即可使能GPIOE时钟 LED1 LDR R0,0X50000A28 指定寄存器地址 LDR R1,[R0] 将寄存器原来的数值读取出来,保存到R1中 ORR R1,R1,#(0x…...
MySQL 中的事务和存储引擎
目录 事务的 ACID 特性 MySQL 的四种隔离机制和问题 MySQL 的四种隔离机制: MySQL 的存储引擎 InnoDB 存储引擎 MyISAM 存储引擎 Memory 存储引擎 通过 ALTER TABLE 语句更改存储引擎 在创建表时指定存储引擎 通过修改配置文件设置默认存储引擎 在数据库系…...
echarts多个折线图共用一个x轴和tooltip组件
实现效果 根据接口传来的数据,使用echarts绘制出,共用一个x轴的图表 功能:后端将所有数据传送过来,前端通过监听选中值来展示对应的图表数据 数据格式: 代码: <template><div><div clas…...
wireshark数据捕获实验简述
Wireshark是一款开源的网络协议分析工具,它可以用于捕获和分析网络数据包。是一款很受欢迎的“网络显微镜”。 实验拓扑图: 实验基础配置: 服务器: ip:172.16.1.88 mask:255.255.255.0 r1: sys sysname r1 undo info enable in…...
如何利用RunnerGo简化性能测试流程
在软件开发过程中,测试是一个重要的环节,需要投入大量时间和精力来确保应用程序或网站的质量和稳定性。但是,随着应用程序变得更加复杂和庞大,传统的测试工具在面对比较繁琐的项目时非常费时费力。这时,一些自动化测试…...
继承和深拷贝封装
继承和深拷贝封装 今日目标: 1.es5寄生组合式继承 2.es6类的继承 3.深拷贝函数封装 00-回顾 # 不同数据类型赋值时的区别: 基本数据类型,赋的就是值,相互之间不再有任何影响 引用数据类型,赋的是地址,…...
《定时执行专家》:Nircmd 的超级搭档,解锁自动化新境界
目录 Nircmd 简介 《定时执行专家》与 Nircmd 的结合 示例: 自动清理电脑垃圾: 定时发送邮件: 定时关闭电脑: 《定时执行专家》的优势: 总结: 以下是一些其他使用示例: 立即下载《定时执行专家》: Nircmd 官方网站: 更…...
Android 封装的工具类
文章目录 日志封装类-MyLog线程封装类-LocalThreadPools自定义进度条-LoadProgressbar解压缩类-ZipUtils本地数据库类-MySQLiteHelper访问webservice封装-HttpUtilsToolbar封装类-MaterialToolbar网络请求框架-OkGo网络请求框架-OkHttp 日志封装类-MyLog 是对android log的封装…...
linux下线程分离属性
linux下线程分离属性 一、线程的属性---分离属性二、线程属性设置2.1 线程创建前设置分离属性2.2 线程创建后设置分离属性 一、线程的属性—分离属性 什么是分离属性? 首先分离属性是线程的一个属性,有了分离属性的线程,不需要别的线程去接合…...
Leetcode 208. 实现 Trie (前缀树)
心路历程: 一道题干进去了一个下午,单纯从解题角度可以直接用python的集合就很简单地解决(不知道是不是因为python底层的set()类)。后来从网上看到这道题应该从前缀树的角度去做,于是花了半个多小时基于字典做了前缀树…...
蓝桥杯练习题——健身大调查
在浏览器中预览 index.html 页面效果如下: 目标 完成 js/index.js 中的 formSubmit 函数,用户填写表单信息后,点击蓝色提交按钮,表单项隐藏,页面显示用户提交的表单信息(在 id 为 result 的元素显示&#…...
React——组件通讯
组件通讯介绍 组件中的状态是私有的,组件的状态只能在组件内部使用,无法直接在组件外使用,但是我们在日常开发中,通常会把相似、功能完整的应用才分成组件(工厂模式)利于我们的开发,而不同组件直…...
php闭包应用
laravel 路由 bingTo 把路由URL映射到匿名回调函数上,框架会把匿名回调函数绑定到应用对象上,这样在匿名函数中就可以使用$this关键字引用重要的应用对象。Illuminate\Support\Traits\Macroable的__call方法。 自己写一个简单的demo: <?php <?…...
基于python+vue的OA公文发文管理系统flask-django-php-nodejs
系统根据现有的管理模块进行开发和扩展,采用面向对象的开发的思想和结构化的开发方法对OA公文发文管理的现状进行系统调查。采用结构化的分析设计,该方法要求结合一定的图表,在模块化的基础上进行系统的开发工作。在设计中采用“自下而上”的…...
脉冲变压器电感的工艺结构原理及选型参数总结
🏡《总目录》 目录 1,概述2,工作原理3,结构特点3.1,铁心结构3.2,铁心材料3.3,绕组4,工艺流程4.1,准备铁芯4.2,绕制线圈4.3,安装线圈4.4,固定线圈4.5,绝缘处理4.6,高压脉冲引出...
golang循环变量捕获问题
在 Go 语言中,当在循环中启动协程(goroutine)时,如果在协程闭包中直接引用循环变量,可能会遇到一个常见的陷阱 - 循环变量捕获问题。让我详细解释一下: 问题背景 看这个代码片段: fo…...
Cesium1.95中高性能加载1500个点
一、基本方式: 图标使用.png比.svg性能要好 <template><div id"cesiumContainer"></div><div class"toolbar"><button id"resetButton">重新生成点</button><span id"countDisplay&qu…...
(二)TensorRT-LLM | 模型导出(v0.20.0rc3)
0. 概述 上一节 对安装和使用有个基本介绍。根据这个 issue 的描述,后续 TensorRT-LLM 团队可能更专注于更新和维护 pytorch backend。但 tensorrt backend 作为先前一直开发的工作,其中包含了大量可以学习的地方。本文主要看看它导出模型的部分&#x…...
UE5 学习系列(三)创建和移动物体
这篇博客是该系列的第三篇,是在之前两篇博客的基础上展开,主要介绍如何在操作界面中创建和拖动物体,这篇博客跟随的视频链接如下: B 站视频:s03-创建和移动物体 如果你不打算开之前的博客并且对UE5 比较熟的话按照以…...
NLP学习路线图(二十三):长短期记忆网络(LSTM)
在自然语言处理(NLP)领域,我们时刻面临着处理序列数据的核心挑战。无论是理解句子的结构、分析文本的情感,还是实现语言的翻译,都需要模型能够捕捉词语之间依时序产生的复杂依赖关系。传统的神经网络结构在处理这种序列依赖时显得力不从心,而循环神经网络(RNN) 曾被视为…...
(转)什么是DockerCompose?它有什么作用?
一、什么是DockerCompose? DockerCompose可以基于Compose文件帮我们快速的部署分布式应用,而无需手动一个个创建和运行容器。 Compose文件是一个文本文件,通过指令定义集群中的每个容器如何运行。 DockerCompose就是把DockerFile转换成指令去运行。 …...
DingDing机器人群消息推送
文章目录 1 新建机器人2 API文档说明3 代码编写 1 新建机器人 点击群设置 下滑到群管理的机器人,点击进入 添加机器人 选择自定义Webhook服务 点击添加 设置安全设置,详见说明文档 成功后,记录Webhook 2 API文档说明 点击设置说明 查看自…...
Razor编程中@Html的方法使用大全
文章目录 1. 基础HTML辅助方法1.1 Html.ActionLink()1.2 Html.RouteLink()1.3 Html.Display() / Html.DisplayFor()1.4 Html.Editor() / Html.EditorFor()1.5 Html.Label() / Html.LabelFor()1.6 Html.TextBox() / Html.TextBoxFor() 2. 表单相关辅助方法2.1 Html.BeginForm() …...
k8s从入门到放弃之HPA控制器
k8s从入门到放弃之HPA控制器 Kubernetes中的Horizontal Pod Autoscaler (HPA)控制器是一种用于自动扩展部署、副本集或复制控制器中Pod数量的机制。它可以根据观察到的CPU利用率(或其他自定义指标)来调整这些对象的规模,从而帮助应用程序在负…...
使用SSE解决获取状态不一致问题
使用SSE解决获取状态不一致问题 1. 问题描述2. SSE介绍2.1 SSE 的工作原理2.2 SSE 的事件格式规范2.3 SSE与其他技术对比2.4 SSE 的优缺点 3. 实战代码 1. 问题描述 目前做的一个功能是上传多个文件,这个上传文件是整体功能的一部分,文件在上传的过程中…...

