经过网络搜索、整理、实践笔记
前置条件:已安装nginx
一 、安装LuaJit
1.下载LuaJit http://luajit.org/download.html
[duanwc@CentOS_6 source]$ wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
2.安装
2.1解压:
[duanwc@CentOS_6 source]$ tar -zxvf LuaJIT-2.0.5.tar.gz
2.2进入解压目录
[duanwc@CentOS_6 source]$ cd LuaJIT-2.0.5
2.3编译
[duanwc@CentOS_6 LuaJIT-2.0.5]$ make PREFIX=/data/servers/luajit
2.4完成安装
[duanwc@CentOS_6 LuaJIT-2.0.5]$ make install PREFIX=/data/servers/luajit
二、下载ngx_devel_kit (NDK)
1.下载 ngx_devel_kit (NDK) https://github.com/simpl/ngx_devel_kit/tags
[duanwc@CentOS_6 source]$ wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.0.tar.gz
2.解压
[duanwc@CentOS_6 source]$ tar -zxvf v0.3.0.tar.gz
解压后文件夹:ngx_devel_kit-0.3.0
三、下载 ngx_lua
1.下载 ngx_lua https://github.com/openresty/lua-nginx-module/tags
[duanwc@CentOS_6 source]$ wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz
2.解压
[duanwc@CentOS_6 source]$ tar -zxvf v0.10.13.tar.gz
解压后文件夹:lua-nginx-module-0.10.13
四、查看之前编译参数
[duanwc@CentOS_6 source]$ nginx -V
configure arguments: --prefix=/data/servers/nginx --with-http_ssl_module --with-http_stub_status_module --with-openssl=/data/source/openssl-1.1.0c --with-threads
五、集成
1. 进入nginx安装源目录
[duanwc@CentOS_6 source]$ cd /data/servers/nginx-1.14.1/
2. 先执行环境变量
[duanwc@CentOS_6 nginx-1.14.1]$ export LUAJIT_LIB=/data/servers/luajit/lib
[duanwc@CentOS_6 nginx-1.14.1]$ export LUAJIT_INC=/data/servers/luajit/include/luajit-2.0
3. 备份之前的nginx
[duanwc@CentOS_6 nginx-1.14.1]$ cp /data/servers/nginx/sbin/nginx /data/servers/nginx/sbin/nginx.bak
4. 编译nginx 增加之前ngxin -V检查的参数
[duanwc@CentOS_6 nginx-1.14.1]$ ./configure --prefix=/data/servers/nginx --with-http_ssl_module --with-http_stub_status_module --with-openssl=/data/source/openssl-1.1.0c --with-threads --add-module=/data/source/ngx_devel_kit-0.3.0/ --add-module=/data/source/lua-nginx-module-0.10.13/
[duanwc@CentOS_6 nginx-1.14.1]$ make -j2 //使用2个线程执行
[duanwc@CentOS_6 nginx-1.14.1]$ make install
5. 如启动nginx产生错误
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
将libluajit-5.1.so.2软链至/lib64下
[duanwc@CentOS_6 ~]$ sudo ln -s /data/servers/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
六、检查lua是否集成成功
1. 打开../conf/nginx.conf配置文件,增加以下配置
location /hello_lua {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
2.重启nginx
[duanwc@CentOS_6 conf]$ sudo nginx -s reload
3.访问测试页
访问localhost/hello_lua会出现”hello, lua”表示安装成功
七、集成redis - 测试通过后补录