Skip to content

Instantly share code, notes, and snippets.

@singleseeker
Created July 3, 2015 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save singleseeker/f5617fc744a0595edcfb to your computer and use it in GitHub Desktop.
Save singleseeker/f5617fc744a0595edcfb to your computer and use it in GitHub Desktop.
LNMP 升级 nginx 加lua脚本
#!/bin/bash
Install_Lua_NDK()
{
wget -c https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
if [ $? -eq 0 ]; then
echo "Download ngx_devel_kit successfully!"
fi
tar xzf v0.2.19.tar.gz
rm -rf v0.2.19.tar.gz
mv ngx_devel_kit-0.2.19 /usr/local/bin
Echo_Green "======== install lua NDK completed ======"
}
Install_Luajit()
{
wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
if [ $? -eq 0 ]; then
echo "Download LuaJIT successfully!"
fi
tar xzf LuaJIT-2.0.4.tar.gz
rm -rf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make PREFIX=/usr/local/luajit
make install PREFIX=/usr/local/luajit
cd ..
rm -rf LuaJIT-2.0.4
ln -sf /usr/local/luajit/bin/luajit /usr/bin/luajit
Echo_Green "======== install luajit completed ======"
}
Install_Lua_MOD()
{
wget -c https://github.com/openresty/lua-nginx-module/archive/v0.9.16.tar.gz
if [ $? -eq 0 ]; then
echo "Download Lua_MOD successfully!"
fi
tar xzf v0.9.16.tar.gz
rm -rf v0.9.16.tar.gz
mv lua-nginx-module-0.9.16 /usr/local/bin
Echo_Green "======== install lua MOD completed ======"
}
Upgrade_Nginx()
{
# You can add other modules arguments to nginx_modules_arguments variable#
Nginx_Modules_Arguments="--add-module=/usr/local/bin/ngx_devel_kit-0.2.19 --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/usr/local/bin/lua-nginx-module-0.9.16"
Cur_Nginx_Version=`/usr/local/nginx/sbin/nginx -v 2>&1 | cut -c22-`
if [ -s /usr/local/include/jemalloc/jemalloc.h ] && /usr/local/nginx/sbin/nginx -V 2>&1|grep -Eqi 'ljemalloc'; then
NginxMAOpt="--with-ld-opt='-ljemalloc'"
elif [ -s /usr/local/include/gperftools/tcmalloc.h ] && grep -Eqi "google_perftools_profiles" /usr/local/nginx/conf/nginx.conf; then
NginxMAOpt='--with-google_perftools_module'
else
NginxMAOpt=""
fi
Install_Luajit
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
Install_Lua_NDK
Install_Lua_MOD
Nginx_Version=""
echo "Current Nginx Version:${Cur_Nginx_Version}"
echo "You can get version number from http://nginx.org/en/download.html"
read -p "Please enter nginx version you want, (example: 1.7.8 ): " Nginx_Version
if [ "${Nginx_Version}" = "" ]; then
echo "Error: You must enter a nginx version!!"
exit 1
fi
echo "+---------------------------------------------------------+"
echo "| You will upgrade nginx version to ${Nginx_Version}"
echo "+---------------------------------------------------------+"
Press_Start
echo "============================check files=================================="
cd ${cur_dir}/src
if [ -s nginx-${Nginx_Version}.tar.gz ]; then
echo "nginx-${Nginx_Version}.tar.gz [found]"
else
echo "Error: nginx-${Nginx_Version}.tar.gz not found!!!download now......"
wget -c http://nginx.org/download/nginx-${Nginx_Version}.tar.gz
if [ $? -eq 0 ]; then
echo "Download nginx-${Nginx_Version}.tar.gz successfully!"
else
echo "You enter Nginx Version was:"${Nginx_Version}
Echo_Red "Error! You entered a wrong version number, please check!"
sleep 5
exit 1
fi
fi
echo "============================check files=================================="
Tar_Cd nginx-${Nginx_Version}.tar.gz nginx-${Nginx_Version}
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module ${NginxMAOpt} ${Nginx_Modules_Arguments}
make -j2
make install
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.${Upgrade_Date}
\cp objs/nginx /usr/local/nginx/sbin/nginx
echo "Test nginx configure file..."
/usr/local/nginx/sbin/nginx -t
echo "upgrade..."
make upgrade
Echo_Green "======== upgrade nginx completed ======"
echo "Program will display Nginx Version......"
/usr/local/nginx/sbin/nginx -v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment