安装luajit及时编译器
不建议从官网Download下载安装,使用过程会有警告;
[alert] 12687#0: detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
如果有需要重新安装,建议先卸载原版本make uninstall
直接 wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20210510.tar.gz
tar -xzvf v2.1-20210510.tar.gz
cd luajit2-2.1-20210510
make && make install PREFIX=/opt/lua/luajit2-2.1-20210510
如果有gcc报错,先安装gcc等依赖环境: yum install -y gcc gcc-c++ kernel-devel
设置环境变量
编译Luajit后设置环境变量
export LUAJIT_LIB=/opt/lua/luajit2-2.1-20210510/lib export LUAJIT_INC=/opt/lua/luajit2-2.1-20210510/include/luajit-2.1 source /etc/profile
编译安装带有lua模块的nginx
下载ngx_devel_kit lua-nginx-module模块及分别解压tar -zxvf
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.15.tar.gz
wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.1rc1.tar.gz
下载ng:
wget http://nginx.org/download/nginx-1.15.8.tar.gz 或官网下载 http://nginx.org/en/download.html
编译:
cd nginx-1.15.8
./configure --prefix=/opt/nginx --with-ld-opt="-Wl,-rpath,/opt/lua/luajit2-2.1-20210510/lib" --add-module=/opt/lua/ngx_devel_kit-0.3.1rc1 --add-module=/opt/lua/lua-nginx-module-0.10.15
make
make install
安装lua cjson模块
启动lua相应依赖包时有报错:
5014#0: init_worker_by_lua error: ...lua/skywalking-nginx-lua-0.6.0/lib/skywalking/tracer.lua:23: module 'cjson.safe' not found:
意思是缺少cjson模块;
下载cjson包;
wget https://github.com/mpx/lua-cjson/archive/refs/tags/2.1.0.tar.gz
解压进入目录,make时候出错,找不到lua.h文件;
进入到Makefile中,设置LUA_INCLUDE_DIR 为LUA_INCLUDE_DIR = /opt/lua/luajit2-2.1-20210510/src/
再次make,能找到lua.h文件,还是报错,luaL_setfuncs函数报错,luaL_setfuncs 这个方法 接口定义时不是静态的方法,实现时,却定义成了静态方法 解决方法:编辑 lua_cjson.c,将luaL_setfuncs函数的static关键字去掉;重新make && make install
可以看到cjson.so编译成功
其他报错
resty.core 模块找不到
[error] 12687#0: lua_load_resty_core failed to load the resty.core module from https://github.com/openresty/lua-resty-core; ensure you are using an OpenResty release from https://openresty.org/en/download.html (rc: 2, reason: module 'resty.core' not found:
no field package.preload['resty.core']
no file '/data/soft/soft_package/nginx/sockproc/lua-resty-shell/lib/resty/core.lua'
no file './resty/core.lua'
no file '/usr/local/LuaJIT/share/luajit-2.1.0-beta3/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core/init.lua'
no file '/usr/local/LuaJIT/share/lua/5.1/resty/core.lua'
no file '/usr/local/LuaJIT/share/lua/5.1/resty/core/init.lua'
no file './resty/core.so'
no file '/usr/local/lib/lua/5.1/resty/core.so'
no file '/usr/local/LuaJIT/lib/lua/5.1/resty/core.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
http块中,设置lua_load_resty_core off;即可解决
关闭LuaJIT FFI 模式;(resty_core是openresty的一个核心模块)