社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  NGINX

记录Nginx的升级实践以及实现的三种方法详解

knight-zhou • 4 年前 • 262 次点击  

方法一:

对于现在有的环境是通过源码包安装nginx的,由于库文件都存在,要升级nginx直接在虚拟机上编译安装好包 然后打包 ,更新到线上机器的/opt/nginx1.x上。

测试如下:

scp nginx1.6.3_az.tar.gz root@192.168.137.128:/opt/

对于现用机器:

tar xzf nginx1.6.3_az.tar.gz

测试正常。

方法二:

采用替换二进制文件nginx(objs下的)

现有环境是nginx1.5.7 ,要升级到nginx1.6.3.测试如下:

对于新版本:

先用

[root@QD1 nginx-1.6.3]# patch -p1 < /opt/soft/nginx_upstream_check_module-master/check_1.5.12+.patch  把补丁打进去

 [root@QD1 nginx-1.6.3]# ./configure --prefix=/opt/nginx --with-http_stub_status_module  --with-http_gzip_static_module  --with-http_ssl_module --add-module=/opt/soft/nginx_upstream_check_module-master

[root@QD1 nginx-1.6.3]# make                            //这样在objs下生成二进制nginx,不要make install

[root@QD1 nginx-1.6.3]# cp objs/nginx /opt/nginx/sbin/

[root@QD1 nginx-1.6.3]# /opt/nginx/sbin/nginx -v

[root@QD1 nginx-1.6.3]# /opt/nginx/sbin/nginx -t

[root@QD1 nginx-1.6.3]# ls /opt/nginx/logs/

access.log error.log nginx.pid

[root@QD1 nginx-1.6.3]# /opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf      //测试新版本nginx是否正常

[root@QD1 nginx-1.6.3]# ls /opt/nginx/logs/

access.log error.log nginx.pid

[root@QD1 nginx-1.6.3]# pkill nginx                  //停掉现有nginx

[root@QD1 nginx-1.6.3]# ls /opt/nginx/logs/ 

access.log error.log                                                              //pid消失

[root@QD1 nginx-1.6.3]# /opt/nginx/sbin/nginx

[root@QD1 conf]# /opt/nginx/sbin/nginx -s reload

方法三:

重新编译新版本nginx,安装到/opt/nginx1.x上。然后拷贝旧版本配置文件,

将新版本nginx1.x的端口改一下测试是否正常,正常的话就停掉旧版本nginx,新版本nginx改成80.

此方法是正常方法,一定可以实现不作测试。

[root@QD1 nginx-1.6.3]# patch -p1 < /opt/soft/nginx_upstream_check_module-master/check_1.5.12+.patch

[root@QD1 nginx-1.6.3]#   ./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module  --with-http_gzip_static_module  --add-module=/opt/soft/nginx_upstream_check_module-master

第三种方法是最安全的方法 推荐使用。

对于第三种方法:脚本实现如下:

#!/bin/bash
# function: upgrate nginx
# os_type: Centos/Redhat
# author: knight
# date: 2015-05-27
###################
mypath1="/opt/software"
mypath2="/opt/soft"
cd /opt/
if [ ! -d "$mypath1" ];then
	cd $mypath2
	#pwd
else
	cd $mypath1
	#pwd
fi

#download & install
wget http://nginx.org/download/nginx-1.6.3.tar.gz
wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master
tar -xzf nginx-1.6.3.tar.gz
unzip master
cd nginx-1.6.3
patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch
./configure --prefix=/opt/nginx1.6 --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module  --add-module=../nginx_upstream_check_module-master
make
make install

# copy nginx_configuration
rsync -av /opt/nginx/conf/nginx.conf /opt/nginx1.6/conf/
cp -a /opt/nginx/conf/webconf /opt/nginx1.6/conf/
sed -i 's/listen *80;/listen  83;/g' /opt/nginx1.6/conf/nginx.conf           #对原文件修改加 -i
echo "软件安装完成, 请在webconf/upstream.conf加入以下参数进行测试"
echo -e "参数是:\n  check interval=3000 rise=2 fall=5 timeout=1000 type=http;\n  "
echo "如果要加入状态页可以在nginx.conf的http段加入如下:"
echo -e "location /status {\n  check_status;\n  access_log   off;\n  }\n"
echo "以上完成之后启动新版nginx进行测试,测试无误后,修改新版nginx端口为80,停掉旧版nginx,再启动新版nginx,升级完成"

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52951
 
262 次点击