ywq111 发表于 2013-3-8 20:53:20

【lnmp插件】升级nginx或者tengine的脚本

说明:
[*]仅在自己的vps上测试过[*]作用:将本地的nginx更换为nginx或tengine的其他版本[*]适应范围:仅配合lnmp.org的lnmp0.9的脚本使用[*]为了支持drupal7显示上传进度条,程序可选择是否安装上传进度条模块:
进度条不知何故,安装后配置几次没成功,总是502错误(如不是很需要,请在安装progress时输入N)
虽然现在安装成功了,但原因未知。似乎和nginx配置很有关系
建议需要安装的朋友多读readme文档,另外可能需要一些折腾才能成功。[*]FileField Nginx Progress
drupal对于nginx的进度条模块[*]转载时请保留代码中的网址。#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

filename = upgrade-nginx-or-tengine-with_upload_module.sh
echo "file name : $filename"
# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install lnmp"
    exit 1
fi

clear
echo "========================================================================="
echo "upgrade Nginx or Tengine for LNMP"
echo "Modified by saiwaike from Licess's upgrade_nginx.sh (http://lnmp.org)"
echo "WebSite: http://saiwaike.com "
echo "========================================================================="
nv=$(/usr/local/nginx/sbin/nginx -v 2>&1)
if [[ $(echo $nv | grep -i tengine) == $DEFAULT ]]
then
      old_webSvr_type="nginx"
      old_webSvr_version=$(echo $nv|cut -d ":" -f2|cut -d "/" -f2)
else
      old_webSvr_type="tengine"
      old_webSvr_version=$(echo $nv|cut -d ":" -f2|cut -d "/" -f2|cut -d " " -f1)
fi
#echo $old_webSvr_version

if [ "$1" != "--help" ]; then

#set tengine version
      new_webSvr_version=""
      echo "Current [$old_webSvr_type] Web Server Versionold_webSvr_version"
      echo " "
      echo "   "
      echo "lease input the webserver type you want:"
      read -p "Just input 1 or 2 : " webSvr_choice
      if [[ $webSvr_choice == 1 ]] ;then
         new_webSvr_type="tengine"
      else
         new_webSvr_type="nginx"
      fi
      
      echo "lease input [$new_webSvr_type] version you want:"
      if [[ $new_webSvr_type == "tengine" ]]; then
          echo "You can get version number from http://tengine.taobao.org/download_cn.html"
      else
          echo "You can get version number from http://nginx.org/en/download.html"
      fi
      read -p "(example: 1.2.4 ):" new_webSvr_version
      if [ "$new_webSvr_version" = "" ]; then
                echo "Error: You must input $new_webSvr_type version!!"
                exit 1
      fi
      echo "==========================="
      echo "You want to upgrade $old_webSvr_type version to $new_webSvr_type: $new_webSvr_version"
      echo "Do you want to add uploadprogress_module for display uploadprogress ?"
      read -p "Input yes(Y) or no(N):" if_with_upload_module
                if [[ $if_with_upload_module = "y" || $if_with_upload_module = "Yes"|| $if_with_upload_module = "yes" ]];then
          if_with_upload_module="Y"
      fi
      echo "==========================="
      get_char()      {
      SAVEDSTTY=`stty -g`
      stty -echo
      stty cbreak
      dd if=/dev/tty bs=1 count=1 2> /dev/null
      stty -raw
      stty echo
      stty $SAVEDSTTY
      }
      echo ""
      echo "ress any key to start...or Press Ctrl+c to cancel"
      char=`get_char`

echo "============================check files=================================="
if [ -s $new_webSvr_type-$new_webSvr_version.tar.gz ]; then
    echo "$new_webSvr_type-$new_webSvr_version.tar.gz "
else
    echo "Error: $new_webSvr_type-$new_webSvr_version.tar.gz not found!!!download now......"
    if [[ $new_webSvr_type == "nginx" ]] ;then
       wget -c http://nginx.org/download/nginx-$new_webSvr_version.tar.gz
    else
       wget -c http://tengine.taobao.org/download/tengine-$new_webSvr_version.tar.gz
    fi
    if [ $? -eq 0 ]; then
      echo "Download $new_webSvr_type-$new_webSvr_version.tar.gz successfully!"
    else
      echo "WARNING!May be the [$new_webSvr_type] version you input was wrong,please check!"
      echo "[$new_webSvr_type] Version input was:"$new_webSvr_version
      sleep 5
      exit 1
    fi
fi
echo "============================check files=================================="
echo "Stoping MySQL..."
/etc/init.d/mysql stop
echo "Stoping PHP-FPM..."
/etc/init.d/php-fpm stop
if [ -s /etc/init.d/memceached ]; then
echo "Stoping Memcached..."
/etc/init.d/memcacehd stop
fi

rm -rf $new_webSvr_type-$new_webSvr_version/

#nginx_uploadprogress_module/
if [[ $if_with_upload_module == "Y" ]];then
if [ -s nginx-upload-progress-module.zip ] ; then
    echo "nginx-upload-porgress module exists"
else
    wget -c -O nginx-upload-progress-module.zip https://github.com/masterzen/nginx-upload-progress-module/archive/master.zip
    if [ $? -eq 0 ]; then
      echo "Downloadnginx-upload-progress-module.zip successfully!"
    else
      echo "WARNING!May be the cannot download nginx_uploadprogress_module from github,please check!"
      sleep 5
      exit 1
    fi
fi
currentcd=$(pwd)
rm -rf /usr/local/nginx_module/nginx_uploadprogress_module
mkdir/usr/local/nginx_module/;cd /usr/local/nginx_module/
unzip $currentcd/nginx-upload-progress-module.zip -d /usr/local/nginx_module/
# rename the module path name
ls|grep nginx|grep upload|grep progress|grep -v grep|xargs -i mv {} nginx_uploadprogress_module
sleep 5
#Back to lnmp path
cd $currentcd
tar zxvf $new_webSvr_type-$new_webSvr_version.tar.gz
cd $new_webSvr_type-$new_webSvr_version/
./configure --user=www --group=www --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-ipv6 --with-http_realip_module --with-http_mp4_module --with-http_secure_link_module --add-module=/usr/local/nginx_module/nginx_uploadprogress_module/
      make
else
tar zxvf $new_webSvr_type-$new_webSvr_version.tar.gz
cd $new_webSvr_type-$new_webSvr_version/
./configure --user=www --group=www --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-ipv6 --with-http_realip_module --with-http_mp4_module --with-http_secure_link_module
      make
fi

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp objs/nginx /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -t
make upgrade
echo "Upgrade completed!"
echo "rogram will display [$new_webSvr_type] Version......"
/usr/local/nginx/sbin/nginx -v
cd ../

echo "Starting MySQL..."
/etc/init.d/mysql start
echo "Starting PHP-FPM..."
/etc/init.d/php-fpm start
if [ -s /etc/init.d/memceached ]; then
echo "Starting Memcached..."
/etc/init.d/memcacehd start
fi

echo "========================================================================="
echo "You have successfully upgrade from $old_webSvr_typeold_webSvr_version to $old_webSvr_typenew_webSvr_version"
echo "========================================================================="
echo ""
echo "For more information about $filename please visit http://saiwaike.com"
echo ""
echo "========================================================================="
fi

[ 本帖最后由 ywq111 于 2013-3-11 11:02 编辑 ]

ywq111 发表于 2013-3-11 11:01:16

没人感兴趣吗?:(

star826 发表于 2013-3-11 13:54:10

回复 1# 的帖子

我看到我笑了。。你既然用tengine你用到什么特性了吗。。

你好好参考下LTANMP一键安装包的

ywq111 发表于 2013-3-11 15:53:00

回复 3# 的帖子

让你见笑了。:lol很特别的特性倒是真没有包括在里面。不过tengine核心和nginx还是有些不一样的。
目前只是一个切换脚本。之所以没包含特性在里面,是因为特性是要看需要的。如果说js和css合并,个人感觉google的那个插件更好些——不需要手工修改源代码来合并。

[ 本帖最后由 ywq111 于 2013-3-11 15:54 编辑 ]

star826 发表于 2013-3-21 14:48:57

回复 4# 的帖子

你说的minify?
直接tengine合并。插件始终是浪费

ywq111 发表于 2013-3-22 11:36:43

回复 5# 的帖子

我说的插件是指的google的那个nginx模块 (PageSpeed)
词未达意让您误解,抱歉。 :loveliness:

[ 本帖最后由 ywq111 于 2013-3-22 11:38 编辑 ]
页: [1]
查看完整版本: 【lnmp插件】升级nginx或者tengine的脚本