Blog / 阅读

LNMP平滑升级nginx并安装ngx_lua模块教程

by admin on 2015-07-10 18:04:14 in ,



#ngx_lua module项目地址
https://github.com/chaoslawful/lua-nginx-module
在LNMP安装包后,重编译nginx,并添加ngx_lua模块

1」Download

wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.16.tar.gz
wget http://nginx.org/download/nginx-1.9.2.tar.gz

2」安装LuaJIT

tar -zxvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make
make install
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0

3」copy模块

cp v0.2.19.tar.gz /usr/local/src
cp v0.9.16.tar.gz /usr/local/src
tar -zxvf v0.2.19.tar.gz
tar -zxvf v0.9.16.tar.gz
 解压下载下来的ngx_devel_kit以及lua-nginx-module到/usr/local/src目录下,即
/usr/local/src/lua-nginx-module-0.9.16/
 /usr/local/src/ngx_devel_kit-0.2.19/

 3」重新编译Nginx

tar -zxvf nginx-1.9.2.tar.gz
解压nginx包,configure一下(参考LNMP安装包,未加其他修改)
./configure --user=www --group=www --prefix=/usr/local/nginx --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB" --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 \
--add-module=/usr/local/src/lua-nginx-module-0.9.16/ \
--add-module=/usr/local/src/ngx_devel_kit-0.2.19/
OK后make,别make install,否则就覆盖安装

4」备份替换

make完后在objs目录下多了个nginx,即新版本的程序
 备份旧的nginx程序
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

新nginx程序覆盖旧的
cp objs/nginx /usr/local/nginx/sbin/nginx

如果提示“cp:cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy”
建议使用如下语句cp
cp -rfp objs/nginx /usr/local/nginx/sbin/nginx

测试新的nginx程序是否正确
/usr/local/nginx/sbin/nginx -t
nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful

平滑重启nginx
/usr/local/nginx/sbin/nginx -s reload

查看ngixn版本及其编译参数
/usr/local/nginx/sbin/nginx -V

「问题解决」
1.如遇到找不到库文件
echo “/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig
即可
2./usr/local/nginx/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory  
在 Nginx 编译时,需要指定 RPATH,记得加入下面选项:
./configure --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"  

或者export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH



需要luafilesystem 的可以参考:为nginx的luajit安装luarocks并安装luafilesystem


写评论

相关文章

上一篇:win2008 r2 死机 事件查看器 id 10错误 WMI错误

下一篇:为nginx的luajit安装luarocks并安装luafilesystem

评论

写评论

* 必填.

分享

栏目

赞助商


热门文章

Tag 云