nginx 平滑升级原理


spacer.gif

nginx 平滑升级_第1张图片


  升级 nginx

  • 1、安装配置1.8版本的 nginx


    [root@localhost ~]# yum install -y gcc gcc-c++ pcre-devel openssl-devel zlib-devel

    [root@localhost ~]# useradd -M -s /sbin/nologin nginx

    [root@localhost ~]# tar xf nginx-1.8.1.tar.gz -C /usr/local

    [root@localhost ~]# cd /usr/local/nginx-1.8.1/

    [root@localhost nginx-1.8.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module


    --prefix=/usr/local/nginx                  \\指定安装路径

    --with-http_stub_status_module               \\声明启用service status服务状态页,默认 不启用

    --with-http_ssl_module                    \\启用ssl(Secure Sockets Layer安全套接 层)模块,以支持https请求

    --sbin-path=/usr/bin/                     \\声明nginx命令目录

  [root@localhost nginx-1.8.1]# make && make install 

  [root@localhost nginx-1.8.1]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

  [root@localhost nginx-1.8.1]# nginx 

  [root@localhost nginx-1.8.1]#  ss -anput | grep nginx

  tcp    LISTEN     0      128       *:80                    *:*                   users:    (("ngin",pid=12004,fd=6),("nginx",pid=12003,fd=6))

  [root@localhost nginx-1.8.1]# nginx -v

  nginx version: nginx/1.8.1


  • 2、升级配置nginx-1.10版本      blob.png


[root@localhost ~]# tar xf nginx-1.10.3.tar.gz -C /usr/local

[root@localhost ~]# cd /usr/local/nginx-1.10.3/

[root@localhost nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --user=nginx --group=ngiinx --with-http_stub_status_module --with-http_ssl_module --with-pcre

[root@localhost nginx-1.10.3]# make

[root@localhost ~]# cd

[root@localhost ~]# mv /usr/local/nginx/sbin/nginx  /usr/local/nginx/sbin/nginx_old

[root@localhost ~]# cp /usr/local/nginx-1.10.3/objs/nginx /usr/local/nginx/sbin/           

   复制新版本的nginx可执行程序

[root@localhost ~]# mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old

[root@localhost ~]# cp /usr/local/nginx-1.10.3/conf/nginx.conf  /usr/local/nginx/nginx.conf

[root@localhost ~]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`


主进程将重命名它的 .pid 文件为 .oldbin,然后执行新的可执行程序,依次启动新的主进程和新的工作进程


[root@localhost ~]# ls /usr/local/nginx/logs/

access.log  error.log  nginx.pid

[root@localhost ~]# nginx -v

nginx version: nginx/1.10.3