zl程序教程

您现在的位置是:首页 >  其他

当前栏目

nginx-v1.10.3热更新升级版本

2023-03-14 22:50:54 时间

nginx热更新实践

  1. 有的时候我们需要升级一下编译安装的nginx的版本
  2. 有的时候我们需要给编译安装的nginx上面添加一些扩展模块
  3. 有的时候,我们只是想玩玩。。。。

是的 ,这里都可以帮助你。。。

相关依赖包的下载链接

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热升级

  1. 首先启动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
  1. 备份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
  1. 复制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
  1. 发送热更新信号
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
  1. 下线旧版本的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
  1. 在退出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