Nginx升级脚本

葛大爷 互联网 2019-05-13 265

Nginx升级脚本nginx_update.sh

#!/usr/bin/env bash
# nginx 从1.15.2升级到1.15.12
clear
# 只编译,不安装
echo -e "\e[1;33m正在下载中...\e[0m"
wget http://nginx.org/download/nginx-1.15.12.tar.gz --no-check-certificate > /tmp/nginx_update.log
tar -xf nginx-1.15.12.tar.gz
cd nginx-1.15.12
echo -e "\e[1;33m正在编译中...\e[0m"
./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-stream >> /tmp/nginx_update.log
make >> /tmp/nginx_update.log
##############################################################################################
echo ""
echo "===升级之前版本==="
/usr/local/nginx/sbin/nginx -v
echo -e "\e[1;33m开始升级...\e[0m"
# 备份之前的版本
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp ./objs/nginx /usr/local/nginx/sbin/
# 将旧的nginx.pid文件添加后缀.oldbin,系统中将有新旧两个Nginx服务共同提供web服务
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
# 通过发送WINCH信号(平缓停止worker process)和QUIT信号(平缓停止Nginx服务)停止旧的Nginx服务进程
kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
echo ""
echo "===升级之后版本==="
/usr/local/nginx/sbin/nginx -v
echo -e "\e[1;33m升级结束,请验证业务...\e[0m"