nginx-v1.10.3热更新升级版本
2023-03-14 22:50:54 时间
nginx热更新实践
- 有的时候我们需要升级一下编译安装的nginx的版本
- 有的时候我们需要给编译安装的nginx上面添加一些扩展模块
- 有的时候,我们只是想玩玩。。。。
是的 ,这里都可以帮助你。。。
相关依赖包的下载链接
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.2.tar.gz
wget http://nginx.org/download/nginx-1.10.3.tar.gz
wget https://www.zlib.net/fossils/zlib-1.2.8.tar.gz
wget https://openssl.org/source/openssl-1.0.2d.tar.gz
wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.0.tar.gz -O ngx_devel_kit.tar.gz
wget https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz -O nginx_upstream_check_module.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.10.tar.gz -O lua-nginx-module.tar.gz
tar xf jemalloc-4.5.0.tar.bz2cd jemalloc-4.5.0 && ./configure && make && make install
apt-get install -y lua5.1-0-dev# apt-get install -y libjemalloc-dev 如果上面没有编译安装jemalloc,可以使用apt进行安装groupadd www
useradd www
编译安装Nginx
编译安装1.10.3
tar xf nginx-1.10.3.tar.gz && cd nginx-1.10.3./configure --prefix=/webserver/nginx --user=www --group=www --with-pcre --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2d --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --add-module=/usr/local/src/ngx_devel_kit --add-module=/usr/local/src/lua-nginx-module --with-ld-opt=-ljemalloc --with-stream --with-http_ssl_module --add-module=/usr/local/src/nginx_upstream_check_module && make && make install
编译安装1.14.2
tar xf nginx-1.14.2.tar.gz && cd nginx-1.14.2./configure --prefix=/webserver/nginx14 --user=www --group=www --with-pcre --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2d --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --add-module=/usr/local/src/ngx_devel_kit --add-module=/usr/local/src/lua-nginx-module --with-ld-opt=-ljemalloc --with-stream --with-http_ssl_module --add-module=/usr/local/src/nginx_upstream_check_module && make && make install
nginx热升级
- 首先启动nginx1.10.3
> root@cluster-node1:/webserver/nginx/sbin# lsnginx
> root@cluster-node1:/webserver/nginx/sbin# pwd/webserver/nginx/sbin
> root@cluster-node1:/webserver/nginx/sbin# ./nginx> root@cluster-node1:/webserver/nginx/sbin# ps -ef |grep nginxroot 44682 1 0 11:27 ? 00:00:00 nginx: master process ./nginx
www 44683 44682 0 11:27 ? 00:00:00 nginx: worker process
root 44685 6939 0 11:27 pts/1 00:00:00 grep --color=auto nginx
> root@cluster-node1:/webserver/nginx/sbin# netstat -tunlp |grep nginxtcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 44682/nginx
> root@cluster-node1:/webserver/nginx/sbin# ./nginx -vnginx version: nginx/1.10.3> root@cluster-node1:/webserver/nginx/sbin# ./nginx -Vnginx version: nginx/1.10.3built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)
built with OpenSSL 1.0.2d 9 Jul 2015TLS SNI support enabled
configure arguments: --prefix=/webserver/nginx --user=www --group=www --with-pcre --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2d --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --add-module=/usr/local/src/ngx_devel_kit --add-module=/usr/local/src/lua-nginx-module --with-ld-opt=-ljemalloc --with-stream --with-http_ssl_module --add-module=/usr/local/src/nginx_upstream_check_module
> root@cluster-node1:/webserver/nginx/sbin# curl -I http://localhostHTTP/1.1 200 OK
Server: nginx/1.10.3Date: Thu, 01 Aug 2019 15:29:08 GMT
Content-Type: text/html
Content-Length: 612Last-Modified: Thu, 01 Aug 2019 15:12:52 GMT
Connection: keep-alive
ETag: "5d430174-264"Accept-Ranges: bytes
- 备份nginx1.10.3的二进制文件
root@cluster-node1:/webserver/nginx/sbin# cp ./nginx ./nginx_1.10.3root@cluster-node1:/webserver/nginx/sbin# ls -ltotal 24840-rwxr-xr-x 1 root root 12715840 Aug 1 11:12 nginx
-rwxr-xr-x 1 root root 12715840 Aug 1 11:30 nginx_1.10.3
- 复制nginx 1.14.2版本的nginx二进制文件到当前的目录下覆盖nginx1.10.3的二进制文件
root@cluster-node1:/webserver/nginx/sbin# cp -f /webserver/nginx14/sbin/nginx ./root@cluster-node1:/webserver/nginx/sbin# ls -ltotal 25680-rwxr-xr-x 1 root root 13574704 Aug 1 11:31 nginx
-rwxr-xr-x 1 root root 12715840 Aug 1 11:30 nginx_1.10.3
- 发送热更新信号
root@cluster-node1:/webserver/nginx/sbin# ps -ef | grep nginxroot 44682 1 0 11:27 ? 00:00:00 nginx: master process ./nginx
www 44683 44682 0 11:27 ? 00:00:00 nginx: worker process
root 44709 6939 0 11:33 pts/1 00:00:00 grep --color=auto nginx
root@cluster-node1:/webserver/nginx/sbin# kill -USR2 44682root@cluster-node1:/webserver/nginx/sbin# ps -ef | grep nginxroot 44682 1 0 11:27 ? 00:00:00 nginx: master process ./nginx
www 44683 44682 0 11:27 ? 00:00:00 nginx: worker process
root 44710 44682 0 11:34 ? 00:00:00 nginx: master process ./nginx
www 44711 44710 0 11:34 ? 00:00:00 nginx: worker process
root 44713 6939 0 11:34 pts/1 00:00:00 grep --color=auto nginx
root@cluster-node1:/webserver/nginx/sbin# curl -I http://localhostHTTP/1.1 200 OK
Server: nginx/1.14.2Date: Thu, 01 Aug 2019 15:34:41 GMT
Content-Type: text/html
Content-Length: 612Last-Modified: Thu, 01 Aug 2019 15:25:32 GMT
Connection: keep-alive
ETag: "5d43046c-264"Accept-Ranges: bytes
- 下线旧版本的nginx的work进程
root@cluster-node1:/webserver/nginx/sbin# kill -WINCH 44682root@cluster-node1:/webserver/nginx/sbin# ps -ef | grep nginxroot 44682 1 0 11:27 ? 00:00:00 nginx: master process ./nginx
root 44710 44682 0 11:34 ? 00:00:00 nginx: master process ./nginx
www 44711 44710 0 11:34 ? 00:00:00 nginx: worker process
root 44757 6939 0 11:36 pts/1 00:00:00 grep --color=auto nginx
root@cluster-node1:/webserver/nginx/sbin# ./nginx -vnginx version: nginx/1.14.2root@cluster-node1:/webserver/nginx/sbin# ./nginx -Vnginx version: nginx/1.14.2built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)
built with OpenSSL 1.0.2d 9 Jul 2015TLS SNI support enabled
configure arguments: --prefix=/webserver/nginx14 --user=www --group=www --with-pcre --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2d --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --add-module=/usr/local/src/ngx_devel_kit --add-module=/usr/local/src/lua-nginx-module --with-ld-opt=-ljemalloc --with-stream --with-http_ssl_module --add-module=/usr/local/src/nginx_upstream_check_module
- 在退出nginx的时候,nginx旧版本的进程依旧存在,但是会在占用80端口,造成从新启动nginx失败,因此需要先杀掉80端口的旧版本的进程
root@cluster-node1:/webserver/nginx/sbin# ./nginx -s quitroot@cluster-node1:/webserver/nginx/sbin# ps -ef |grep nginxroot 44682 1 0 11:27 ? 00:00:00 nginx: master process ./nginx
www 44783 44682 0 11:38 ? 00:00:00 nginx: worker process
root 44785 6939 0 11:38 pts/1 00:00:00 grep --color=auto nginx
root@cluster-node1:/webserver/nginx/sbin# ./nginx -vnginx version: nginx/1.14.2root@cluster-node1:/webserver/nginx/sbin# ps -ef |grep nginxroot 44682 1 0 11:27 ? 00:00:00 nginx: master process ./nginx
www 44783 44682 0 11:38 ? 00:00:00 nginx: worker process
root 44788 6939 0 11:38 pts/1 00:00:00 grep --color=auto nginx
root@cluster-node1:/webserver/nginx/sbin# ./nginx -s reloadnginx: [error] open() "/webserver/nginx14/logs/nginx.pid" failed (2: No such file or directory)
root@cluster-node1:/webserver/nginx/sbin# ./nginxnginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
root@cluster-node1:/webserver/nginx/sbin# ./nginx -s stopnginx: [error] open() "/webserver/nginx14/logs/nginx.pid" failed (2: No such file or directory)
root@cluster-node1:/webserver/nginx/sbin# ls -l /webserver/nginx14/logs/nginx.pidls: cannot access '/webserver/nginx14/logs/nginx.pid': No such file or directory
root@cluster-node1:/webserver/nginx/sbin# pkill nginxroot@cluster-node1:/webserver/nginx/sbin# ./nginxroot@cluster-node1:/webserver/nginx/sbin# ps -ef |grep nginxroot 44800 1 0 11:39 ? 00:00:00 nginx: master process ./nginx
www 44801 44800 0 11:39 ? 00:00:00 nginx: worker process
root 44803 6939 0 11:40 pts/1 00:00:00 grep --color=auto nginx
root@cluster-node1:/webserver/nginx/sbin# ./nginx -vnginx version: nginx/1.14.2
相关文章
- 在 Go 里用 CGO?这 7 个问题你要关注!
- 9款优秀的去中心化通讯软件 Matrix 的客户端
- 求职数据分析,项目经验该怎么写
- 在OKR中,我看到了数据驱动业务的未来
- 火山引擎云原生大数据在金融行业的实践
- OpenHarmony富设备移植指南(二)—从postmarketOS获取移植资源
- 《数据成熟度指数》报告:64%的企业领袖认为大多数员工“不懂数据”
- OpenHarmony 小型系统兼容性测试指南
- 肯睿中国(Cloudera):2023年企业数字战略三大趋势预测
- 适用于 Linux 的十大命令行游戏
- GNOME 截图工具的新旧截图方式
- System76 即将推出的 COSMIC 桌面正在酝酿大变化
- 2GB 内存 8GB 存储即可流畅运行,Windows 11 极致精简版系统 Tiny11 发布
- 迎接 ecode:一个即将推出的具有全新图形用户界面框架的现代、轻量级代码编辑器
- loongarch架构介绍(三)—地址翻译
- Go 语言怎么解决编译器错误“err is shadowed during return”?
- 敏捷:可能被开发人员遗忘的部分
- Denodo预测2023年数据管理和分析的未来
- 利用数据推动可持续发展
- 在 Vue3 中实现 React 原生 Hooks(useState、useEffect),深入理解 React Hooks 的