kong安装报错 /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:33: in function ‘check_state‘

文章描述了在启动Kong服务时遇到的警告和错误,提示数据库未初始化或者版本过旧。解决方案是运行Kong的迁移命令进行数据库初始化或升级到Kong1.5.0并转换apis实体。提供的Docker命令示例用于初始化数据库。

错误信息如下:

2023/06/01 22:32:35 [warn] 1#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/kong/nginx.conf:6
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/kong/nginx.conf:6
2023/06/01 22:32:35 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:33: Database needs bootstrapping or is older than Kong 1.0.

To start a new installation from scratch, run 'kong migrations bootstrap'.

To migrate from a version older than 1.0, migrated to Kong 1.5.0 first. 
If you still have 'apis' entities, you can convert them to Routes and Services
using the 'kong migrations migrate-apis' command in Kong 1.5.0.


stack traceback:
    [C]: in function 'error'
    /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:33: in function 'check_state'
    /usr/local/share/lua/5.1/kong/init.lua:628: in function 'init'
    init_by_lua:3: in main chunk
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:33: Database needs bootstrapping or is older than Kong 1.0.

To start a new installation from scratch, run 'kong migrations bootstrap'.

To migrate from a version older than 1.0, migrated to Kong 1.5.0 first. 
If you still have 'apis' entities, you can convert them to Routes and Services
using the 'kong migrations migrate-apis' command in Kong 1.5.0.


stack traceback:
    [C]: in function 'error'
    /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:33: in function 'check_state'
    /usr/local/share/lua/5.1/kong/init.lua:628: in function 'init'
    init_by_lua:3: in main chunk

报错原因,没有对kong使用的数据库进行初始化,执行以下命令即可:

docker run --rm --network=kong-net \ -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -e "KONG_PG_PASSWORD=kongpass" \ -e "KONG_PASSWORD=test" \ kong/kong-gateway:3.3.0.0 kong migrations bootstrap


 

Lua 中,`package.path` 是一个字符串,它定义了 `require` 函数在加载 Lua 模块时的搜索路径。该字符串由多个**路径模板**组成,用分号 `;` 分隔。每个模板中的 `?` 会被替换为要加载的模块名。例如: ``` ./?.lua;./?/init.lua;/usr/local/share/lua/5.1/?.lua;... ``` ### **1. 路径模板解析** | 路径模板 | 说明 | |----------|------| | `./?.lua` | 在当前目录查找 `<模块名>.lua` 文件 | | `./?/init.lua` | 在当前目录的子目录 `<模块名>` 中查找 `init.lua` | | `/usr/local/share/lua/5.1/?.lua` | 在系统 Lua 模块目录查找 `<模块名>.lua` | | `...` | 表示可能还有其他路径(如 LuaRocks 安装的库) | **示例:** ```lua -- 假设 package.path 包含 "./?.lua" local mymodule = require("hello") -- 会尝试加载 ./hello.lua ``` --- ### **2. 路径搜索规则** - **`?` 的作用**: `require("client")` 会把 `?` 替换为 `"client"`,依次尝试以下路径: 1. `./client.lua` 2. `./client/init.lua` 3. `/usr/local/share/lua/5.1/client.lua` - **顺序优先级**: 按 `package.path` 中定义的顺序依次查找,**第一个匹配的文件会被加载**。 --- ### **3. 跨平台路径问题** - **Windows 与 Linux 差异**: - Linux/macOS 使用 `/` 作为路径分隔符(如 `/usr/local/?.lua`) - Windows 通常使用 `\`(如 `C:\lua\?.lua`) - **解决方案**: 使用 `package.config` 中的分隔符(通常是 `/`),Lua 会自动处理: ```lua -- 跨平台兼容写法 package.path = package.path .. ";./lib/?.lua" ``` --- ### **4. 修改 `package.path`** - **添加自定义路径**: ```lua -- 添加 /custom/modules/ 到搜索路径 package.path = package.path .. ";/custom/modules/?.lua" local client = require("client") -- 查找 /custom/modules/client.lua ``` - **临时覆盖路径**: ```lua package.path = "/my/modules/?.lua" ``` --- ### **5. 调试路径问题** - **打印当前 `package.path`**: ```lua print(package.path) ``` - **检查文件是否存在**: ```lua local path = "./client.lua" print(io.open(path, "r") ~= nil) -- true 表示文件可读 ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值