网站首页 > 技术教程 正文
背景
生产环境 Nginx 需要增加支持 TCP 反向代理功能,需要再添加--with-stream参数重新编译后,在线升级 Nginx。
在线升级
# 查看当前版本(注意为大写 V)
$ cd /usr/local/nginx/sbin
$ nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
# 安装编译依赖
$ yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
# 下载、解压、并编译(仅编译不安装)
$ wget http://nginx.org/download/nginx-1.16.1.tar.gz
$ tar -zxvf nginx-1.16.1.tar.gz
$ cd nginx-1.16.1
# 增加 --with-stream 编译
# --pid-path 根据各自情况添加,由于 nginx 执行升级命令时,默认是从 nginx/logs 目录下找 nginx.pid
$ ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-stream --pid-path=/usr/local/nginx/nginx.pid
# -j 指定CPU内核数量,加快编译速度
$ make -j 4
# 备份旧版本,复制新版本
$ mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
$ cp nginx-1.16.1/objs/nginx /usr/local/nginx/sbin/
$ chown nginx:nginx /usr/local/nginx/sbin/nginx
# 升级前查看进程号,确认进程号与 nginx.pid 一致
$ ps -ef | grep nginx
root 11871 1 0 3月24 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 13772 11871 0 11月10 ? 00:00:02 nginx: worker process
nginx 13773 11871 0 11月10 ? 00:00:03 nginx: worker process
nginx 13774 11871 0 11月10 ? 00:00:04 nginx: worker process
nginx 13775 11871 0 11月10 ? 00:00:04 nginx: worker process
$ cat /usr/local/nginx/nginx.pid
11871
# 在 nginx1.16.1 目录下,执行 make upgrade 命令自动升级
$ cd nginx-1.16.1
$ make upgrade
# 使用新版本检测配置文件是否正确
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# 发送平滑迁移信号给旧的 nginx 进程
kill -USR2 `cat /usr/local/nginx/nginx.pid`
sleep 1
# 检测旧的 nginx.pid 进程是否变为 nginx.pid.oldbin
test -f /usr/local/nginx/nginx.pid.oldbin
# 结束旧版本的进程,完成升级
kill -QUIT `cat /usr/local/nginx/nginx.pid.oldbin`
# 验证是否升级成功,查看 nginx 进程号是否变化(11871-->31845)
$ ps -ef | grep nginx
root 31845 1 0 16:58 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 31847 31845 0 16:58 ? 00:00:00 nginx: worker process
nginx 31848 31845 0 16:58 ? 00:00:00 nginx: worker process
nginx 31849 31845 0 16:58 ? 00:00:00 nginx: worker process
nginx 31850 31845 0 16:58 ? 00:00:00 nginx: worker process
$ cat /usr/local/nginx/nginx.pid
31845
# 查看升级后的版本(注意为大写 V)
$ /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-stream --pid-path=/usr/local/nginx/nginx.pid
猜你喜欢
- 2024-10-15 作为一名前端,是怎么理解nginx的
- 2024-10-15 一分钟搭建Nginx环境(Docker版本)
- 2024-10-15 从官网入门系列-nginx web文件 反向代理 动静分离 负荷均衡(二)
- 2024-10-15 折腾记·关于Nginx的学习记录(nginx最全教程)
- 2024-10-05 Nginx 从入坑到弃坑 - 日常维护篇
- 2024-10-05 Centos7系统Nginx负载均衡如何安装和配置? - 蓝易云
- 2024-10-05 nginx学习笔记(nginx基础教程)
- 2024-10-05 Nginx 从入门到实践,万字详解(nginx入门教程)
你 发表评论:
欢迎- 最近发表
-
- 阿里P8大佬总结的Nacos入门笔记,从安装到进阶小白也能轻松学会
- Linux环境下,Jmeter压力测试的搭建及报错解决方法
- Java 在Word中合并单元格时删除重复值
- 解压缩软件哪个好用?4款大多数人常用的软件~
- Hadoop高可用集群搭建及API调用(hadoop3高可用)
- lombok注解@Data没有toString和getter、setter问题
- Apache Felix介绍(apache fineract)
- Spring Boot官方推荐的Docker镜像编译方式-分层jar包
- Gradle 使用手册(gradle详细教程)
- 字节二面:为什么SpringBoot的 jar可以直接运行?
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)