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,高压脉冲引出...

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)
题目:3442. 奇偶频次间的最大差值 I 思路 :哈希,时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况,哈希表这里用数组即可实现。 C版本: class Solution { public:int maxDifference(string s) {int a[26]…...
FFmpeg 低延迟同屏方案
引言 在实时互动需求激增的当下,无论是在线教育中的师生同屏演示、远程办公的屏幕共享协作,还是游戏直播的画面实时传输,低延迟同屏已成为保障用户体验的核心指标。FFmpeg 作为一款功能强大的多媒体框架,凭借其灵活的编解码、数据…...
linux 错误码总结
1,错误码的概念与作用 在Linux系统中,错误码是系统调用或库函数在执行失败时返回的特定数值,用于指示具体的错误类型。这些错误码通过全局变量errno来存储和传递,errno由操作系统维护,保存最近一次发生的错误信息。值得注意的是,errno的值在每次系统调用或函数调用失败时…...

Mac软件卸载指南,简单易懂!
刚和Adobe分手,它却总在Library里给你写"回忆录"?卸载的Final Cut Pro像电子幽灵般阴魂不散?总是会有残留文件,别慌!这份Mac软件卸载指南,将用最硬核的方式教你"数字分手术"࿰…...

新能源汽车智慧充电桩管理方案:新能源充电桩散热问题及消防安全监管方案
随着新能源汽车的快速普及,充电桩作为核心配套设施,其安全性与可靠性备受关注。然而,在高温、高负荷运行环境下,充电桩的散热问题与消防安全隐患日益凸显,成为制约行业发展的关键瓶颈。 如何通过智慧化管理手段优化散…...
HTML前端开发:JavaScript 常用事件详解
作为前端开发的核心,JavaScript 事件是用户与网页交互的基础。以下是常见事件的详细说明和用法示例: 1. onclick - 点击事件 当元素被单击时触发(左键点击) button.onclick function() {alert("按钮被点击了!&…...

SiFli 52把Imagie图片,Font字体资源放在指定位置,编译成指定img.bin和font.bin的问题
分区配置 (ptab.json) img 属性介绍: img 属性指定分区存放的 image 名称,指定的 image 名称必须是当前工程生成的 binary 。 如果 binary 有多个文件,则以 proj_name:binary_name 格式指定文件名, proj_name 为工程 名&…...

网站指纹识别
网站指纹识别 网站的最基本组成:服务器(操作系统)、中间件(web容器)、脚本语言、数据厍 为什么要了解这些?举个例子:发现了一个文件读取漏洞,我们需要读/etc/passwd,如…...
Go 语言并发编程基础:无缓冲与有缓冲通道
在上一章节中,我们了解了 Channel 的基本用法。本章将重点分析 Go 中通道的两种类型 —— 无缓冲通道与有缓冲通道,它们在并发编程中各具特点和应用场景。 一、通道的基本分类 类型定义形式特点无缓冲通道make(chan T)发送和接收都必须准备好࿰…...
音视频——I2S 协议详解
I2S 协议详解 I2S (Inter-IC Sound) 协议是一种串行总线协议,专门用于在数字音频设备之间传输数字音频数据。它由飞利浦(Philips)公司开发,以其简单、高效和广泛的兼容性而闻名。 1. 信号线 I2S 协议通常使用三根或四根信号线&a…...