安装自定义插件后无法启动Kong Gateway的问题求助
我正在使用Kong Gateway 0.11.2搭配Cassandra数据库2.2.7版本,已编写一个自定义插件并尝试手动安装。已根据Kong官方文档在kong.conf文件中完成必要配置,执行kong migrations up命令显示成功,但执行后无法启动Kong Gateway,日志报错如下:
[error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:149: [cassandra error] the current database schema does not match this version of Kong. Please run
kong migrations upto update/initialize the database schema. Be aware that Kong migrations should only run from a single node, and that nodes running migrations concurrently will conflict with each other and might corrupt your database schema!
stack traceback:
[C]: in function 'assert'
/usr/local/share/lua/5.1/kong/init.lua:149: in function 'init'
init_by_lua:3: in main chunk
nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:149: [cassandra error] the current database schema does not match this version of Kong. Please runkong migrations upto update/initialize the database schema. Be aware that Kong migrations should only run from a single node, and that nodes running migrations concurrently will conflict with each other and might corrupt your database schema!
stack traceback:
[C]: in function 'assert'
/usr/local/share/lua/5.1/kong/init.lua:149: in function 'init'
init_by_lua:3: in main chunk
1. 确认迁移执行状态
登录Cassandra数据库,查询schema_migrations表验证迁移记录:
SELECT * FROM kong.schema_migrations;
检查结果中是否包含Kong 0.11.2对应的所有迁移版本,且executed字段均为true。如果存在缺失或未执行的记录,说明迁移未真正完成。
2. 检查自定义插件的迁移脚本
如果自定义插件包含数据库迁移逻辑:
- 确认脚本放置路径为插件目录下的
migrations/cassandra - 脚本命名需遵循
[version]_[name].lua格式 - 确保脚本语法兼容Cassandra 2.2.7,避免使用高版本特性(如JSON类型、LWT语法扩展等)
- 执行迁移前,
kong.conf的plugins配置必须包含自定义插件名,否则Kong不会加载并执行其迁移脚本
3. 重置并重新执行迁移(谨慎操作)
若迁移记录异常,按以下步骤操作:
- 停止所有Kong节点,避免并发操作
- 备份Cassandra中
kongkeyspace的所有数据 - 执行重置命令:
kong migrations reset - 重新执行迁移:
kong migrations up - 启动Kong节点:
kong start -c /path/to/kong.conf
4. 验证数据库配置与权限
- 检查
kong.conf中的Cassandra配置:cassandra_contact_points是否指向正确的节点IP/域名cassandra_keyspace是否为kong且已正确创建
- 确认Kong使用的数据库用户拥有
CREATE、ALTER、SELECT等schema操作权限
5. 启用Debug日志排查
启动Kong时添加--vv参数获取详细日志,定位schema不匹配的具体原因:
kong start -c /path/to/kong.conf --vv
日志中会显示具体哪个表或字段的schema不符合预期,针对性修复。
内容的提问来源于stack exchange,提问作者Ankit Bhatia

