@yibo
2015-10-10T05:38:11.000000Z
字数 1159
阅读 941
nginx bash
#!/usr/bin/env bash# 升级nginx,加stream模块——tcp代理oldVersion=1.8newVersion=1.9.2newPath=/opt/nginx-$newVersionsrcPath=/opt/source/nginx-$newVersion# copy一份当前的nginx作为副本,并在该副本上进行升级操作cd /optcp -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 installmake# 重命名nginx旧版本二进制文件(期间nginx并不会停止服务)rm -rf $newPath/sbin/nginx.oldmv $newPath/sbin/nginx $newPath/sbin/nginx.old# 然后拷贝一份新编译的二进制文件cp $srcPath/objs/nginx $newPath/sbin/# 向nginx.conf中追加新的配置cat >>$newPath/conf/nginx.conf<<EOFstream {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.confecho -n "是否开始升级? (yes/no)"read confirmif [ "$confirm" == 'yes' ];thencd $srcPath# 在源码目录运行make upgrade# 查看一下版本是否正确$newPath/sbin/nginx -V# 重新设置一下软连接cd /optrm -rf nginxln -s nginx-1.9.2 nginxfi