前置基础知识:
1、使用ZeroBrane Studio调试Openresty lua脚本请参考:https://blog.csdn.net/zhuankeshumo/article/details/79828080
2、OpenResty api网关设计 https://blog.csdn.net/zhuankeshumo/article/details/79393215
本文主要讲解使用ZeroBrane Studio调试kong源码步骤:
1、切换到kong next分支,并且安装luarocks,运行luarocks make
2、etc/kong/kong.conf配置lua_package_path和lua_package_cpath
lua_package_path = /home/caozhiyuan/ZeroBraneStudio-1.70/lualibs/?/?.lua;/home/caozhiyuan/ZeroBraneStudio-1.70/lualibs/?.lua;./?.lua;./?/init.lua; # Sets the Lua module search path
# (LUA_PATH). Useful when developing
# or using custom plugins not stored
# in the default search path.
lua_package_cpath = /home/caozhiyuan/ZeroBraneStudio-1.70/bin/linux/x64/clibs/?.so; # Sets the Lua C module search path
# (LUA_CPATH).
3、Kong.rewrite() 方法开始添加require('mobdebug').start('127.0.0.1')
4、docker方式安装kong数据库POSTGRES(https://docs.konghq.com/install/docker/),运行sudo bin/kong migrations up -c /etc/kong/kong.conf
5、sudo bin/kong start -c /etc/kong/kong.conf --vv
6、参考https://docs.konghq.com/0.14.x/getting-started/configuring-a-service/进行配置,访问http://localhost:8000/下配置的服务
7、kong源码理解
(1)、如何保证集群节点数据一致性?
db数据变更->workerevents.post_local 删除本地缓存->cluster_events:broadcast删除本地缓存