linux服务器升级nginx

时间:2023-03-09 22:22:10
linux服务器升级nginx

1、简介

  有时候nginx发布了新BUG或者添加了新的功能时,想要更新的时候服务又不能中断,这时候就要用到nginx的平滑升级了。

  该脚本同样适用于添加新扩展,添加新扩展的时候只需要把更新的版本修改为当前版本,更新的时候把需要添加的扩展加上去即可。

  我这里nginx安装目录为/usr/local/nginx

  当前系统,阿里云ECS CentOS 7.4 64位

2、查看nginx版本与编译信息

  # /usr/local/nginx/sbin/nginx -V

  linux服务器升级nginx

  这里的扩展要记录下来(重要),等下升级的时候用到,如果有需要添加新信息可以一起编译。

2、使用shell升级

  cnl_function.sh cnl_install_lnmp_init.sh 下载地址

  更新的时候请修改自己的安装目录

 #!/bin/bash
source ./cnl_function.sh
source ./cnl_install_lnmp_init.sh
#function of install nginx
update_nginx(){
cd /usr/local/src
[ -f nginx-1.15..tar.gz ] || wget http://nginx.org/download/nginx-1.15.6.tar.gz
tar -zxf nginx-1.15..tar.gz
cd nginx-1.15.
myum pcre-devel
[ -d /usr/local/nginx ] && cp -R /usr/local/nginx /usr/local/nginx_`date +%s`
check_ok
./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-ipv6 \
--with-http_v2_module \
--with-poll_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_dav_module \
--with-http_flv_module
#只编译不安装
make
check_ok
if [ -f /usr/local/nginx/sbin/nginx ]
then
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
check_ok
fi cp /usr/local/src/nginx-1.15./objs/nginx /usr/local/nginx/sbin/
check_ok kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
check_ok } read -p "Initialization completion, Enter (Y) to start update nginx1.15.6 :" n
if [ $n == 'Y' ]
then
echo "Start update==============================================================================================================================>"
update_nginx
echo "The update_nginx make done"
else
echo "Cancel the update."
fi

  进到shell脚本目录执行该脚本,按提示执行即可。

  linux服务器升级nginx

  执行完可以看到nginx版本已经升级为1.15.6