nginx版本的平滑升级

 


   nginx版本的平滑升级

    前几天我同事晚上值班没事的时候,把公司客户的一些nginx服务器进行了升级,这种操作我还从来没有做过,也挺好奇的,今天闲来没事就在网上找了类似的文档,进行了操作,并把其过程记录了下来……

1.查看自己服务器nginx的版本和最早自己编译安装是的参数

  
  
  
  
  1. [root@localhost ~]# /usr/local/nginx/sbin/nginx -V 
  2.  nginx version: nginx/1.2.1 
  3.  built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46) 
  4.  TLS SNI support disabled 
  5.  configure arguments: --prefix=/usr/local --sbin-path=/usr/sbin/nginx \
  6. --conf-path=/usr/local/nginx/conf/nginx.conf \
  7. --error-log-path=/var/log/nginx/error.log \
  8. --http-log-path=/var/log/nginx/access.log \
  9. --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock \
  10. --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module \
  11. --with-http_stub_status_module --with-http_gzip_static_module \
  12. --http-client-body-temp-path=/var/tmp/nginx/client/ \
  13. --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  14. --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  15. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  16. --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre 

2.在这里http://nginx.org/en/download.html找到最新的nginx版本,并下载到服务器上

3.对新版本进行解压并编译,其中安装目录必须和原来的一样,但是可以添加一些新的参数

  
  
  
  
  1. [root@localhost ~]# tar xvf nginx-1.2.4.tar.gz   
  2. [root@localhost ~]# cd nginx-1.2.4 
  3. [root@localhost nginx-1.2.4]# ./configure --prefix=/usr/local \ 
  4.   --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf \ 
  5.   --error-log-path=/var/log/nginx/error.log \ 
  6.   --http-log-path=/var/log/nginx/access.log \ 
  7.   --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock \ 
  8.   --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module \ 
  9.   --with-http_stub_status_module --with-http_gzip_static_module \ 
  10.   --http-client-body-temp-path=/var/tmp/nginx/client/ \ 
  11.   --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 
  12.   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 
  13.   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 
  14.   --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre 

4.只执行make命令,不需要make install

  
  
  
  
  1. [root@localhost nginx-1.2.4]# make 

5.替换nginx的一个二进制文件

  
  
  
  
  1. [root@localhost nginx-1.2.4]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak  
  2. [root@localhost nginx-1.2.4]# cp objs/nginx /usr/local/nginx/sbin/ 

6.进行测试是否成功

  
  
  
  
  1. [root@localhost nginx-1.2.4]# /usr/local/nginx/sbin/nginx -t 
  2.  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
  3.  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 

7.执行命令进行平滑升级

  
  
  
  
  1. [root@localhost nginx-1.2.4]# make upgrade
  2.  /usr/sbin/nginx -t 
  3.  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
  4.  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 
  5.  kill -USR2 `cat /var/run/nginx/nginx.pid` 
  6.  sleep 1 
  7.  test -f /var/run/nginx/nginx.pid.oldbin 
  8.  kill -QUIT `cat /var/run/nginx/nginx.pid.oldbin` 

make upgrade执行命令后显示的信息,其实显示的就是都执行了哪几个命令,也可以自己手动执行那个kill命令

8.在次查看版本信息

  
  
  
  
  1. [root@localhost nginx-1.2.4]# /usr/local/nginx/sbin/nginx -V  
  2.  nginx version: nginx/1.2.4 
  3.  built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46) 
  4.  TLS SNI support disabled 
  5.  configure arguments: --prefix=/usr/local --sbin-path=/usr/sbin/nginx 
  6. --conf-path=/usr/local/nginx/conf/nginx.conf \
  7. --error-log-path=/var/log/nginx/error.log \
  8. --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid \
  9. --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx \
  10. --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module \
  11. --with-http_gzip_static_module \
  12. --http-client-body-temp-path=/var/tmp/nginx/client/ 
  13. --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  14. --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  15. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  16. --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre 

nginx升级完成!

 

你可能感兴趣的:(nginx,linux,版本,升级,平滑)