VPS侦探论坛

 找回密码
 注册
查看: 8208|回复: 5

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

[复制链接]
发表于 2013-3-8 20:53:20 | 显示全部楼层 |阅读模式

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

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

  11. clear
  12. echo "========================================================================="
  13. echo "upgrade Nginx or Tengine for LNMP"
  14. echo "Modified by saiwaike from Licess's upgrade_nginx.sh (http://lnmp.org)"
  15. echo "WebSite: http://saiwaike.com "
  16. echo "========================================================================="
  17. nv=$(/usr/local/nginx/sbin/nginx -v 2>&1)
  18. if [[ $(echo $nv | grep -i tengine) == $DEFAULT ]]
  19. then
  20.         old_webSvr_type="nginx"
  21.         old_webSvr_version=$(echo $nv|cut -d ":" -f2|cut -d "/" -f2)
  22. else
  23.         old_webSvr_type="tengine"
  24.         old_webSvr_version=$(echo $nv|cut -d ":" -f2|cut -d "/" -f2|cut -d " " -f1)
  25. fi  
  26. #echo $old_webSvr_version

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

  28. #set tengine version
  29.         new_webSvr_version=""
  30.         echo "Current [$old_webSvr_type] Web Server Versionold_webSvr_version"
  31.         echo "  [Tengine] [1]"
  32.         echo "  [Nginx]   [2]"
  33.         echo "lease input the webserver type you want:"
  34.         read -p "Just input 1 or 2 : " webSvr_choice
  35.         if [[ $webSvr_choice == 1 ]] ;then
  36.            new_webSvr_type="tengine"
  37.         else
  38.            new_webSvr_type="nginx"
  39.         fi
  40.       
  41.         echo "lease input [$new_webSvr_type] version you want:"
  42.         if [[ $new_webSvr_type == "tengine" ]]; then
  43.           echo "You can get version number from http://tengine.taobao.org/download_cn.html"
  44.         else
  45.           echo "You can get version number from http://nginx.org/en/download.html"
  46.         fi
  47.         read -p "(example: 1.2.4 ):" new_webSvr_version
  48.         if [ "$new_webSvr_version" = "" ]; then
  49.                 echo "Error: You must input $new_webSvr_type version!!"
  50.                 exit 1
  51.         fi
  52.         echo "==========================="
  53.         echo "You want to upgrade $old_webSvr_type version to $new_webSvr_type: $new_webSvr_version"
  54.         echo "Do you want to add uploadprogress_module for display uploadprogress ?"
  55.         read -p "Input yes(Y) or no(N):" if_with_upload_module
  56.                 if [[ $if_with_upload_module = "y" || $if_with_upload_module = "Yes"|| $if_with_upload_module = "yes" ]];then
  57.           if_with_upload_module="Y"
  58.         fi
  59.         echo "==========================="
  60.         get_char()        {
  61.         SAVEDSTTY=`stty -g`
  62.         stty -echo
  63.         stty cbreak
  64.         dd if=/dev/tty bs=1 count=1 2> /dev/null
  65.         stty -raw
  66.         stty echo
  67.         stty $SAVEDSTTY
  68.         }
  69.         echo ""
  70.         echo "ress any key to start...or Press Ctrl+c to cancel"
  71.         char=`get_char`

  72. echo "============================check files=================================="
  73. if [ -s $new_webSvr_type-$new_webSvr_version.tar.gz ]; then
  74.     echo "$new_webSvr_type-$new_webSvr_version.tar.gz [found]"
  75.   else
  76.     echo "Error: $new_webSvr_type-$new_webSvr_version.tar.gz not found!!!download now......"
  77.     if [[ $new_webSvr_type == "nginx" ]] ;then
  78.        wget -c http://nginx.org/download/nginx-$new_webSvr_version.tar.gz
  79.     else
  80.        wget -c http://tengine.taobao.org/download/tengine-$new_webSvr_version.tar.gz
  81.     fi
  82.     if [ $? -eq 0 ]; then
  83.         echo "Download $new_webSvr_type-$new_webSvr_version.tar.gz successfully!"
  84.     else
  85.         echo "WARNING!May be the [$new_webSvr_type] version you input was wrong,please check!"
  86.         echo "[$new_webSvr_type] Version input was:"$new_webSvr_version
  87.         sleep 5
  88.         exit 1
  89.     fi
  90. fi
  91. echo "============================check files=================================="
  92. echo "Stoping MySQL..."
  93. /etc/init.d/mysql stop
  94. echo "Stoping PHP-FPM..."
  95. /etc/init.d/php-fpm stop
  96. if [ -s /etc/init.d/memceached ]; then
  97.   echo "Stoping Memcached..."
  98.   /etc/init.d/memcacehd stop
  99. fi

  100. rm -rf $new_webSvr_type-$new_webSvr_version/

  101. #nginx_uploadprogress_module/
  102. if [[ $if_with_upload_module == "Y" ]];then
  103.   if [ -s nginx-upload-progress-module.zip ] ; then
  104.     echo "nginx-upload-porgress module exists"
  105.   else
  106.     wget -c -O nginx-upload-progress-module.zip https://github.com/masterzen/nginx-upload-progress-module/archive/master.zip
  107.     if [ $? -eq 0 ]; then
  108.         echo "Download  nginx-upload-progress-module.zip successfully!"
  109.     else
  110.         echo "WARNING!May be the cannot download nginx_uploadprogress_module from github,please check!"
  111.         sleep 5
  112.         exit 1
  113.     fi
  114.   fi
  115.   currentcd=$(pwd)
  116.   rm -rf /usr/local/nginx_module/nginx_uploadprogress_module
  117.   mkdir  /usr/local/nginx_module/;cd /usr/local/nginx_module/
  118.   unzip $currentcd/nginx-upload-progress-module.zip -d /usr/local/nginx_module/
  119.   # rename the module path name
  120.   ls|grep nginx|grep upload|grep progress|grep -v grep|xargs -i mv {} nginx_uploadprogress_module
  121.   sleep 5
  122.   #Back to lnmp path
  123.   cd $currentcd
  124.   tar zxvf $new_webSvr_type-$new_webSvr_version.tar.gz
  125.   cd $new_webSvr_type-$new_webSvr_version/
  126.   ./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/
  127.         make
  128. else
  129.   tar zxvf $new_webSvr_type-$new_webSvr_version.tar.gz
  130.   cd $new_webSvr_type-$new_webSvr_version/
  131.   ./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
  132.         make
  133. fi

  134. mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
  135. cp objs/nginx /usr/local/nginx/sbin/nginx
  136. /usr/local/nginx/sbin/nginx -t
  137. make upgrade
  138. echo "Upgrade completed!"
  139. echo "rogram will display [$new_webSvr_type] Version......"
  140. /usr/local/nginx/sbin/nginx -v
  141. cd ../

  142. echo "Starting MySQL..."
  143. /etc/init.d/mysql start
  144. echo "Starting PHP-FPM..."
  145. /etc/init.d/php-fpm start
  146. if [ -s /etc/init.d/memceached ]; then
  147.   echo "Starting Memcached..."
  148.   /etc/init.d/memcacehd start
  149. fi

  150. echo "========================================================================="
  151. echo "You have successfully upgrade from $old_webSvr_typeold_webSvr_version to $old_webSvr_typenew_webSvr_version"
  152. echo "========================================================================="
  153. echo ""
  154. echo "For more information about $filename please visit http://saiwaike.com"
  155. echo ""
  156. echo "========================================================================="
  157. fi
复制代码


[ 本帖最后由 ywq111 于 2013-3-11 11:02 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2013-3-11 11:01:16 | 显示全部楼层


没人感兴趣吗?  
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2013-3-11 13:54:10 | 显示全部楼层

回复 1# 的帖子


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

你好好参考下LTANMP一键安装包的
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2013-3-11 15:53:00 | 显示全部楼层

回复 3# 的帖子




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

[ 本帖最后由 ywq111 于 2013-3-11 15:54 编辑 ]
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2013-3-21 14:48:57 | 显示全部楼层

回复 4# 的帖子


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

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2013-3-22 11:36:43 | 显示全部楼层

回复 5# 的帖子


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

[ 本帖最后由 ywq111 于 2013-3-22 11:38 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-24 11:31 , Processed in 0.028266 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表