1.前言
Kong Gateway 是一个运行在 Nginx 上的 Lua 应用程序,它与 OpenResty 一起发布。Kong Gateway 底层数据库只支持 PostgreSQL 和 Cassandra,从 3.4.0 版本官方已不在支持 Cassandra。
由于大部分国产数据并没有提供 Lua 语言驱动,所有笔者将采用 ODBC 适配达梦数据库,文中涉及到的 lua 源码需要读者自行实现。
2.环境
cd "/usr/bin" && \
curl -fLO https://releases.bazel.build/6.1.0/release/bazel-6.1.0-linux-x86_64 && \
chmod +x bazel-6.1.0-linux-x86_64 && \
mv bazel-6.1.0-linux-x86_64 bazel
复制代码
yum install \
automake \
gcc \
gcc-c++ \
git \
libyaml-devel \
make \
patch \
perl \
perl-IPC-Cmd \
protobuf-devel \
unzip \
valgrind \
valgrind-devel \
zlib-devel
复制代码
yum install unixODBC unixODBC-devel
复制代码
配置 odbc 数据库源配置文件在: /etc/odbc.ini
[DM8]
Description = DM ODBC DSN
#DM8数据库区动
Driver = /usr/lib/dm/libdodbc.so
#数据库连接地址
SERVER = localhost
#此处为用户名
UID = SYSDBA
#此处为连接的密码
PWD = 12345678s
#数据库实例端口号
TCP_PORT = 5236
复制代码
命令验证是否生效
3.适配
dependencies = {
......
"luasql-odbc == 2.6.0",
}
build = {
type = "builtin",
modules = {
......
["kong.cluster_events.strategies.dm"] = "kong/cluster_events/strategies/dm.lua",
["kong.db.strategies.dm"] = "kong/db/strategies/dm/init.lua",
["kong.db.strategies.dm.connector"] = "kong/db/strategies/dm/connector.lua",
["kong.db.strategies.dm.tags"] = "kong/db/strategies/dm/tags.lua",
......
}
}
复制代码
kong/cluster_events/strategies/dm.lua
#建立数据库连接
kong/db/strategies/dm/connector.lua
#访问数据库SELECT、INSERT、DELETE、UPDATE等
kong/db/strategies/dm/init.lua
kong/db/strategies/dm/tags.lua
复制代码
#配置文件
kong.conf.default
kong/templates/kong_defaults.lua
kong/db/strategies/init.lua
kong/cluster_events/init.lua
kong/conf_loader/init.lua
kong/db/schema/others/migrations.lua
#依赖的表、触发器、函数
kong/db/migrations/core/000_base.lua
#辅助表结构及插件依赖表结构可忽略但必须有数据库名称配置
#当然也可以把表结构拆分到相关的lua文件中
kong/db/migrations/core/003_100_to_110.lua
kong/db/migrations/core/004_110_to_120.lua
kong/db/migrations/core/005_120_to_130.lua
kong/db/migrations/core/006_130_to_140.lua
kong/db/migrations/core/007_140_to_150.lua
kong/db/migrations/core/008_150_to_200.lua
kong/db/migrations/core/009_200_to_210.lua
kong/db/migrations/core/010_210_to_211.lua
kong/db/migrations/core/011_212_to_213.lua
kong/db/migrations/core/012_213_to_220.lua
kong/db/migrations/core/013_220_to_230.lua
kong/db/migrations/core/014_230_to_270.lua
kong/db/migrations/core/015_270_to_280.lua
kong/db/migrations/core/016_280_to_300.lua
kong/db/migrations/core/017_300_to_310.lua
kong/db/migrations/core/018_310_to_320.lua
kong/db/migrations/core/019_320_to_330.lua
kong/db/migrations/operations/200_to_210.lua。
复制代码
4.编译
bazel build //build:kong --verbose_failures --action_env=CFLAGS="-DUNIXODBC"
bazel build --config release //build:kong --verbose_failures --action_env=CFLAGS="-DUNIXODBC
#输出rpm文件到当前目录的bazel-bin/pkg/
bazel build --config release :kong_el7 --verbose_failures
复制代码
5.安装
默认安装路径: /usr/local/share/lua/5.1/,日志路径: /usr/local/kong
6.源码
感兴趣友情支持,主要支持达梦数据库、MYSQL、瀚高。
https://item.taobao.com/item.htm?ft=t&id=763874191645
评论