@yibo
2015-10-10T05:38:11.000000Z
字数 1159
阅读 825
nginx
bash
#!/usr/bin/env bash
# 升级nginx,加stream模块——tcp代理
oldVersion=1.8
newVersion=1.9.2
newPath=/opt/nginx-$newVersion
srcPath=/opt/source/nginx-$newVersion
# copy一份当前的nginx作为副本,并在该副本上进行升级操作
cd /opt
cp -r nginx-$oldVersion nginx-$newVersion
# 加参数编译
cd $srcPath
./configure --prefix=/opt/nginx-$newVersion \
--user=nginx --group=nginx \
--with-stream \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--add-module=../ngx_cache_purge-2.3 \
--with-http_image_filter_module \
--with-http_sub_module \
--with-http_spdy_module
# 执行make编译,但不要执行make install
make
# 重命名nginx旧版本二进制文件(期间nginx并不会停止服务)
rm -rf $newPath/sbin/nginx.old
mv $newPath/sbin/nginx $newPath/sbin/nginx.old
# 然后拷贝一份新编译的二进制文件
cp $srcPath/objs/nginx $newPath/sbin/
# 向nginx.conf中追加新的配置
cat >>$newPath/conf/nginx.conf<<EOF
stream {
upstream backend {
#hash $remote_addr consistent;
server 10.10.5.11:1024;
}
server {
listen 9999;
proxy_pass backend;
}
}
EOF
# 为了保险起见,还是用vim瞜一眼配置吧
vim $newPath/conf/nginx.conf
# 检验一下配置文件有没有错
$newPath/sbin/nginx -t -c $newPath/conf/nginx.conf
echo -n "是否开始升级? (yes/no)"
read confirm
if [ "$confirm" == 'yes' ];then
cd $srcPath
# 在源码目录运行
make upgrade
# 查看一下版本是否正确
$newPath/sbin/nginx -V
# 重新设置一下软连接
cd /opt
rm -rf nginx
ln -s nginx-1.9.2 nginx
fi