为了方便部署 nginx with lua 方案, 写了个自动部署脚本, 这个脚本从16年维护至今.
你可以在 gist: https://gist.github.com/karminski/135e58d2f52b91625dfc 找到这个脚本的最新版本.
需要注意的是:
脚本中的默认配置是:
这个配置在 171026-180426 期间在 juejin.im 的微服务服务器上运行了6个月未发现异常.
再之前的配置在 160816-171026 期间在 juejin.im 的微服务服务器上运行了14个月也未发现异常.
具体可以看脚本的 @changes 记录, 上面记载了模块搭配信息.
需要注意不同版本的 luajit 和 lua-nginx-module 带来的的差异.
该脚本默认 luajit 安装源使用的是 openresty 定制过的 luajit, 不是官方 luajit, 详情见: https://github.com/openresty/luajit2
scripts:
#!/bin/bash # deploy_nginx_with_lua_nginx_module.sh # @version 171026:7 # @author karminski <> # # @changes # 171026:7 CHANGE to nginx-1.10.3, lua-nginx-module-v0.10.10, luajit2-v2.1-20170925 # 170825:6 REMOVE --with-debug compile option to solve peformance issue. # 170627:5 CHANGE to nginx-1.10.3, lua-nginx-module-v0.10.8 # 161226:4 CHANGE to nginx-1.10.2, lua-nginx-module-v0.10.8, luajit2-v2.1-20161104 # 160816:3 CHANGE to nginx-1.10.1, lua-nginx-module-v0.10.8, luajit2-v2.1-20160517 # ... # @source # https://gist.github.com/karminski/135e58d2f52b91625dfc # [manual config area] SOURCE_LUAJIT=https://github.com/openresty/luajit2/archive/v2.1-20170925.tar.gz SOURCE_NGINX=http://nginx.org/download/nginx-1.10.3.tar.gz SOURCE_NGX_DEVEL_KIT=https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz SOURCE_LUA_NGINX_MODULE=https://github.com/openresty/lua-nginx-module/archive/v0.10.10.tar.gz LUAJIT_INSTALLER_PATH=/data/apps/luajit LUAJIT_INSTALL_PATH=/data/apps/luajit NGINX_INSTALLER_PATH=/data/apps/src/nginx_installer NGINX_INSTALL_PATH=/data/apps/nginx UNTAR_FOLDER_LUAJIT=luajit2-2.1-20170925 UNTAR_FOLDER_NGINX=nginx-1.10.3 UNTAR_FOLDER_NGX_DEVEL_KIT=ngx_devel_kit-0.3.0 UNTAR_FOLDER_LUA_NGINX_MODULE=lua-nginx-module-0.10.10 # [dump config for check] echo -e "\033[34m- nginx_deploy_with_lua_nginx_module.sh start \033[0m" echo -e "\033[34m--------------------------------------------- \033[0m" echo -e "\033[34m- SOURCE_LUAJIT: ${SOURCE_LUAJIT} \033[0m" echo -e "\033[34m- SOURCE_NGINX: ${SOURCE_NGINX} \033[0m" echo -e "\033[34m- SOURCE_NGX_DEVEL_KIT: ${SOURCE_NGX_DEVEL_KIT} \033[0m" echo -e "\033[34m- SOURCE_LUA_NGINX_MODULE: ${SOURCE_LUA_NGINX_MODULE} \033[0m" echo -e "\033[34m- LUAJIT_INSTALLER_PATH: ${LUAJIT_INSTALLER_PATH} \033[0m" echo -e "\033[34m- LUAJIT_INSTALL_PATH: ${LUAJIT_INSTALL_PATH} \033[0m" echo -e "\033[34m- NGINX_INSTALLER_PATH: ${NGINX_INSTALLER_PATH} \033[0m" echo -e "\033[34m- NGINX_INSTALL_PATH: ${NGINX_INSTALL_PATH} \033[0m" echo -e "\033[34m- UNTAR_FOLDER_LUAJIT: ${UNTAR_FOLDER_LUAJIT} \033[0m" echo -e "\033[34m- UNTAR_FOLDER_NGINX: ${UNTAR_FOLDER_NGINX} \033[0m" echo -e "\033[34m- UNTAR_FOLDER_NGX_DEVEL_KIT: ${UNTAR_FOLDER_NGX_DEVEL_KIT} \033[0m" echo -e "\033[34m- UNTAR_FOLDER_LUA_NGINX_MODULE: ${UNTAR_FOLDER_LUA_NGINX_MODULE} \033[0m" # [install dependency] yum install -y pcre-devel.x86_64 openssl-devel.x86_64 wget gcc g++ # [fetch and install luajit] ## [fetch luajit source] mkdir -p ${LUAJIT_INSTALLER_PATH} cd ${LUAJIT_INSTALLER_PATH} wget ${SOURCE_LUAJIT} for i in `ls *.tar.gz` do tar -zxvf $i done cd ${UNTAR_FOLDER_LUAJIT} REPLACED_PATH=`echo ${LUAJIT_INSTALL_PATH} | awk '{gsub("/", "\\\/", $0); printf("%s\n", $0);}'` sed -i "s/export PREFIX= \/usr\/local/export PREFIX= ${REPLACED_PATH}/g" Makefile echo -e "\033[34m- [FETCH FINISH]\033[0m" ## [make and install luajit] # if you want debug with luajit, use: make CCDEBUG=-g make -j make install echo -e "\033[34m- luajit info: \033[0m" ${LUAJIT_INSTALL_PATH}/bin/luajit -v echo -e "\033[34m- [luajit INSTALL FINISH]\033[0m" # [fetch and install nginx] ## [fetch installer source] mkdir -p ${NGINX_INSTALLER_PATH} cd ${NGINX_INSTALLER_PATH} wget ${SOURCE_NGINX} wget ${SOURCE_NGX_DEVEL_KIT} wget ${SOURCE_LUA_NGINX_MODULE} for i in `ls *.tar.gz` do tar -zxvf $i done echo -e "\033[34m- [FETCH FINISH]\033[0m" ## [configure, build and install] cd ${NGINX_INSTALLER_PATH} export LUAJIT_LIB=${LUAJIT_INSTALL_PATH}/lib export LUAJIT_INC=${LUAJIT_INSTALL_PATH}/include/luajit-2.1 echo -e "\033[34m- config LUAJIT_LIB to ${LUAJIT_LIB} \033[0m" echo -e "\033[34m- config LUAJIT_INC to ${LUAJIT_INC} \033[0m" cd "${NGINX_INSTALLER_PATH}/${UNTAR_FOLDER_NGINX}" chmod +x ./configure ./configure --prefix=${NGINX_INSTALL_PATH} \ --with-ld-opt="-Wl,-rpath,${LUAJIT_LIB}" \ --with-stream \ --with-stream_ssl_module \ --with-http_ssl_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --add-module=${NGINX_INSTALLER_PATH}/${UNTAR_FOLDER_NGX_DEVEL_KIT} \ --add-module=${NGINX_INSTALLER_PATH}/${UNTAR_FOLDER_LUA_NGINX_MODULE} \ make -j && make install export PATH=$PATH:${NGINX_INSTALL_PATH}/sbin ## [run nginx -v] echo -e "\033[34m- nginx info: \033[0m" ${NGINX_INSTALL_PATH}/sbin/nginx -V echo -e "\033[34m- [nginx INSTALL FINISH]\033[0m" echo -e "\033[34m- [ALL DONE]\033[0m"
以上