咨询一个问题, 升级到trengine3.0.0 版本 后 lua 报错,
nginx: [error] 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 OpenResty - Download (rc: 2, reason: module 'resty.core' not found:
no field package.preload['resty.core']
no file './resty/core.lua'
no file '/usr/local/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 './resty/core.so'
no file '/usr/local/lib/lua/5.1/resty/core.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so')
已经增加了ngx_devel_kit 、ua-nginx-module 、lua-resty-core、 lua-resty-lrucache
安装路径是: /usr/local
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
根据您描述的问题,升级到 Tengine 3.0.0 版本后,lua_load_resty_core
报错,提示无法加载 resty.core
模块。以下是针对该问题的详细分析和解决方案:
错误原因:
resty.core
模块未正确加载。lua-resty-core
模块未正确安装或路径配置不正确。lua_package_path
和 lua_package_cpath
)。lua-resty-core
不兼容。已知条件:
ngx_devel_kit
、lua-nginx-module
、lua-resty-core
和 lua-resty-lrucache
。/usr/local
。确保 lua-resty-core
和其他依赖模块已正确安装,并且路径符合预期。
检查 lua-resty-core
是否存在:
ls /usr/local/lib/lua/5.1/resty/core.lua
如果文件不存在,请重新安装 lua-resty-core
:
cd /usr/local/src
wget https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.24.tar.gz
tar -zxvf v0.1.24.tar.gz
cd lua-resty-core-0.1.24
make install PREFIX=/usr/local
确保 lua-resty-lrucache
也已正确安装:
ls /usr/local/lib/lua/5.1/resty/lrucache.lua
如果缺失,请参考类似步骤安装。
在 nginx.conf
文件中,添加或修改以下配置,确保 Lua 模块能够被正确加载:
http {
lua_package_path "/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/resty/?.lua;;";
lua_package_cpath "/usr/local/lib/lua/5.1/?.so;;";
}
lua_package_path
用于指定 Lua 脚本文件的搜索路径。lua_package_cpath
用于指定 Lua C 扩展模块的搜索路径。Tengine 3.0.0 对 OpenResty 和 LuaJIT 的版本有特定要求。请确认以下内容:
检查 OpenResty 版本:
nginx -V
确保使用的是官方推荐的 OpenResty 版本(如 1.19.x 或更高版本)。
检查 LuaJIT 版本:
luajit -v
推荐使用 LuaJIT 2.1 或更高版本。如果版本过低,请升级 LuaJIT:
cd /usr/local/src
wget https://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz
tar -zxvf LuaJIT-2.1.0-beta3.tar.gz
cd LuaJIT-2.1.0-beta3
make && make install PREFIX=/usr/local
如果上述步骤仍无法解决问题,可能需要重新编译 Tengine,确保所有模块正确链接。
下载并解压 Tengine 源码:
cd /usr/local/src
wget https://tengine.taobao.org/download/tengine-3.0.0.tar.gz
tar -zxvf tengine-3.0.0.tar.gz
cd tengine-3.0.0
配置编译选项:
./configure --prefix=/usr/local/nginx \
--with-http_lua_module \
--with-luajit-lib=/usr/local/lib \
--with-luajit-inc=/usr/local/include/luajit-2.1 \
--add-module=/usr/local/src/ngx_devel_kit \
--add-module=/usr/local/src/lua-nginx-module
编译并安装:
make && make install
完成上述步骤后,测试 Nginx/Tengine 配置是否正常:
检查配置文件语法:
nginx -t
启动或重启服务:
nginx -s reload
验证 Lua 模块加载: 在 Nginx 配置中添加一个简单的 Lua 测试脚本:
location /test {
content_by_lua_block {
local core = require "resty.core"
ngx.say("resty.core loaded successfully")
}
}
访问 /test
路径,确认输出结果为 resty.core loaded successfully
。
lua-resty-core
和 lua-resty-lrucache
的版本与 OpenResty 和 LuaJIT 兼容。lua_package_path
和 lua_package_cpath
配置一致。/usr/local
目录及其子目录的权限,确保 Nginx/Tengine 进程有读取权限。通过以上步骤,您可以解决 Tengine 3.0.0 升级后 lua_load_resty_core
报错的问题。如果仍有疑问,请提供更多错误日志以便进一步排查。您可以复制页面截图提供更多信息,我可以进一步帮您分析问题原因。