最近研究kong,这里记录一下
Nginx、OpenRestry、Kong这三个项目紧密相连:
https://github.com/Kong/kong
https://docs.konghq.com/install/source/
https://www.openssl.org/source/
https://github.com/Kong/lua-kong-nginx-module
https://openresty.org/en/download.html
./configure \
--prefix=/home1/zcy/kong/openresty \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-openssl=/home1/zcy/kong/openssl-1.1.1c \
--add-module=/home1/zcy/kong/lua-kong-nginx-module
报错:you need to have ldconfig in your PATH env when enabling luajit
解决方法:编辑Makefile文件,将can_run("ldconfig")改成can_run("/sbin/ldconfig")
./configure \
--lua-suffix=jit \
--with-lua=/home1/zcy/kong/openresty/luajit \
--with-lua-include=/home1/zcy/kong/openresty/luajit/include/luajit-2.1 \
--prefix=/home1/zcy/kong/luarocks
配置环境:
export PATH=$PATH:/home1/zcy/kong/openresty/bin:/home1/zcy/kong/luarocks/bin:
export LUA_PATH="/home1/zcy/kong/luarocks/share/lua/5.1/?.lua;;/home1/zcy/kong/luarocks/share/lua/5.1/?/init.lua;"
luarocks 安装:
$luarocks make kong-*.rockspec
or
$luarocks install kong 2.0.2-0
或者
$ git clone [email protected]:Kong/kong.git
$ cd kong
$ [sudo] make install # this simply runs the `luarocks make kong-*.rockspec` command
lua-resty-lrucache 0.09-2 is now installed in /home1/zcy/kong/luarocks (license: 2bsd)
lua-resty-acme 0.4.3-1 depends on lua-resty-openssl >= 0.2.1-1 (0.4.4-1 installed)
lua-resty-acme 0.4.3-1 is now installed in /home1/zcy/kong/luarocks (license: BSD)
kong-plugin-acme 0.2.2-1 is now installed in /home1/zcy/kong/luarocks (license: Apache 2.0)
kong 2.0.2-0 is now installed in /home1/zcy/kong/luarocks (license: Apache 2.0)
创建kong的数据库:
./bin/kong migrations up -c ./kong.conf
启动kong:
./bin/kong start -c ./kong.conf
kong默认的代理地址是:
proxy_listen = 0.0.0.0:8000, 0.0.0.0:8443
默认的管理地址是:
admin_listen = 127.0.0.1:8001, 127.0.0.1:8444 ssl
如果一切顺利,你应该看到一条消息通知你Kong正在运行。
默认情况下,Kong监听以下端口:
Error: Failed installing dependency: https://luarocks.org/lyaml-6.2.4-1.src.rock - Could not find library file for YAML
No file libyaml.a in /usr/local/lib
No file libyaml.a in /usr/local/lib64
No file libyaml.so in /usr/local/lib
No file libyaml.so in /usr/local/lib64
No file matching libyaml.so.* in /usr/local/lib
No file matching libyaml.so.* in /usr/local/lib64
No file libyaml.a in /usr/lib
No file libyaml.a in /usr/lib64
No file libyaml.so in /usr/lib
No file libyaml.so in /usr/lib64
No file matching libyaml.so.* in /usr/lib
No file matching libyaml.so.* in /usr/lib64
No file libyaml.a in /lib
No file libyaml.a in /lib64
No file libyaml.so in /lib
No file libyaml.so in /lib64
No file matching libyaml.so.* in /lib
No file matching libyaml.so.* in /lib64
You may have to install YAML in your system and/or pass YAML_DIR or YAML_LIBDIR to the luarocks command.
Example: luarocks install lyaml YAML_DIR=/usr/local
make: *** [install] Error 1
安装libyaml
# yum downgrade libyaml
# yum install libyaml-devel
$ kong start -c ./kong.conf 报错
Error: module 'resty.kong.tls' not found:No LuaRocks module found for resty.kong.tls
no field package.preload['resty.kong.tls']
no file './resty/kong/tls.lua'
no file './resty/kong/tls/init.lua'
no file '/home1/zcy/kong/openresty/site/lualib/resty/kong/tls.ljbc'
no file '/home1/zcy/kong/openresty/site/lualib/resty/kong/tls/init.ljbc'
no file '/home1/zcy/kong/openresty/lualib/resty/kong/tls.ljbc'
no file '/home1/zcy/kong/openresty/lualib/resty/kong/tls/init.ljbc'
no file '/home1/zcy/kong/openresty/site/lualib/resty/kong/tls.lua'
no file '/home1/zcy/kong/openresty/site/lualib/resty/kong/tls/init.lua'
no file '/home1/zcy/kong/openresty/lualib/resty/kong/tls.lua'
no file '/home1/zcy/kong/openresty/lualib/resty/kong/tls/init.lua'
no file '/home1/zcy/kong/luarocks/share/lua/5.1/resty/kong/tls.lua'
no file './resty/kong/tls.lua'
no file '/home1/zcy/kong/openresty/luajit/share/luajit-2.1.0-beta3/resty/kong/tls.lua'
no file '/usr/local/share/lua/5.1/resty/kong/tls.lua'
no file '/usr/local/share/lua/5.1/resty/kong/tls/init.lua'
no file '/home1/zcy/kong/openresty/luajit/share/lua/5.1/resty/kong/tls.lua'
no file '/home1/zcy/kong/openresty/luajit/share/lua/5.1/resty/kong/tls/init.lua'
no file '/home1/zcy/kong/luarocks/share/lua/5.1/resty/kong/tls/init.lua'
no file '/home1/zcy/.luarocks/share/lua/5.1/resty/kong/tls.lua'
no file '/home1/zcy/.luarocks/share/lua/5.1/resty/kong/tls/init.lua'
no file '/home1/zcy/kong/openresty/site/lualib/resty/kong/tls.so'
no file '/home1/zcy/kong/openresty/lualib/resty/kong/tls.so'
no file './resty/kong/tls.so'
no file '/usr/local/lib/lua/5.1/resty/kong/tls.so'
no file '/home1/zcy/kong/openresty/luajit/lib/lua/5.1/resty/kong/tls.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/home1/zcy/.luarocks/lib/lua/5.1/resty/kong/tls.so'
no file '/home1/zcy/kong/luarocks/lib/lua/5.1/resty/kong/tls.so'
no file '/home1/zcy/kong/openresty/site/lualib/resty.so'
no file '/home1/zcy/kong/openresty/lualib/resty.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/home1/zcy/kong/openresty/luajit/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/home1/zcy/.luarocks/lib/lua/5.1/resty.so'
no file '/home1/zcy/kong/luarocks/lib/lua/5.1/resty.so'
Run with --v (verbose) or --vv (debug) for more details
原因:是kong启动时会在预先设置的路径中加载tls.lua和init.lua模块,而搜索完所有路径都没有发现需要的模块就会报错,可能是在安装过程中依赖的lua模块没有放到对应的路径下。
解决方法:使用find命令在根目录下找kong缺失的模块文件(如:find / -name tls.lua),将找到后的模块文件放到kong启动加载时检索的目录下,或使用建立软连接的方式即可。
拷贝https://github.com/Kong/lua-kong-nginx-module里的lualib/resty/kong/tls.lua到 luarocks/share/lua/5.1/resty/kong/tls.lua
使用kong migrations bootstrap进行初始化的过程中,出现如下所示”failed to wait for schmeaconsensus:timeout”的错误。
原因:kong使用的数据库采用的是多台服务器集群部署的方式。在初始化过程中会进行一系列的创建数据库、表、字段等一系列操作,并要在集群之间完成数据的同步一致化。可能网络、磁盘IO等原因,未在设定的时间内完成数据一致化,就会报错。
解决方法:kong migrations bootstrap初始化命令后边可以跟一些选项参数,其中--db-timeout选项是用来指定超时时间的,如果不手动指定该选项,默认参数值为60(单位为秒)。因此可以手动指定该选项,并设置一个更长时间的参数。
kong start -c ./kong.conf
kong stop -p ./
https://www.lijiaocn.com/%E9%97%AE%E9%A2%98/2018/09/29/kong-usage-problem-and-solution.html
参考:
https://blog.csdn.net/lijiaocn/article/details/83004672
https://promagic.cn/apiwangguankongshiyongjiaochengyinginxopenrestyhekongdejibengainianyushiyongfangfa.shtml
https://bbs.huaweicloud.com/forum/thread-39375-1-1.html
如果觉得文章写得不错,能对你有帮助,可以扫描我的微信二维码请我喝咖啡哦~~哈哈~~