由于在项目中需要使用网关模块
经过技术调研和选型,kong是基于nginx的网关,性能较高,有lua模块,可以扩展功能
因此适用于所在项目
kong软件本身使用openresty,是一个c++模块,网上教程比较少
我在调研测试过程中,也尝试直接从源码编译,这样可以更好的理解该软件
我结合了一些资料,完成编译过程
使用源码安装,中间有较多环境变量的设置
但不修改/usr /etc 下面的系统文件
可以同时安装多个软件
同时centos系统,yum安装的kong软件是基本x86_64的,在aarch下无法启动,需要自己编译才可用
mac安装
1.brew安装openssl
我安装的版本是1.0.2r
2.下载安装openresty
目录为/Users/fnozoszzt/kong/openresty/
安装命令
#####./configure --with-openssl=/usr/local/Cellar/openssl/1.0.2r/ --prefix=/Users/fnozoszzt/kong/openresty/
./configure --with-cc-opt="-I/usr/local/Cellar/openssl/1.0.2r/include/ -I/usr/local/Cellar/pcre/8.44/include/" --with-ld-opt="-L/usr/local/Cellar/openssl/1.0.2r/lib/ -L/usr/local/Cellar/pcre/8.44/lib/" -j8 --with-pcre-jit --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module --prefix=/Users/fnozoszzt/kong/openresty/
安装完成后有nginx,luajit
3.安装pg
网上教程比较多
4.下载安装luarocks
git clone git://github.com/luarocks/luarocks.git
源码下载
./configure --lua-suffix=jit --with-lua=/Users/fnozoszzt/kong/openresty/luajit --with-lua-include=/Users/fnozoszzt/kong/openresty/luajit/include/luajit-2.1/ --prefix=/Users/fnozoszzt/kong/luarocks
安装之后运行luarocks,指向之前安装的openresty/luajit
经测试,不能用brew安装luarocks
4.下载kong源码
make install
为luajit安装依赖
并设置环境变量
export LUA_PATH="/Users/fnozoszzt/kong/luarocks/share/lua/5.1/?.lua;"
export PATH="$PATH:/Users/fnozoszzt/kong/openresty/bin"
export PATH="$PATH:/Users/fnozoszzt/kong/openresty/nginx/sbin"
export PATH="$PATH:/Users/fnozoszzt/kong/kong/kong-0.12.2/bin"
LUA_PATH是为kong脚本设置lua的查找路径
5.在kong目录下,运行设置kong.conf,运行start
2.aarch架构
- openresty安装
- 下载
- wget https://openresty.org/download/openresty-1.17.8.2.tar.gz
- configure文件修改
- 安装pcre和openssl zlib,也是源码编译安装
- ##./configure -j2 --with-pcre=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/pcre-8.44 --with-openssl=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/openssl-1.1.0i --with-zlib=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/zlib-1.2.11 --prefix=/home/hadoop/xuxuerui_test/kong/openresty
- ./configure --with-cc-opt="-I/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/openssl-1.1.0i/include -I/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/pcre-8.44/include -I/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/zlib-1.2.11/include" --with-ld-opt="-L-I/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/openssl-1.1.0i/include/lib -L/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/pcre-8.44/lib -L/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/zlib-1.2.11/lib" -j8 --with-pcre-jit --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module --prefix=/home/hadoop/xuxuerui_test/kong/openresty --with-pcre=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/pcre-8.44 --with-openssl=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/openssl-1.1.0i --with-zlib=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/zlib-1.2.11
- 下载
- luarocks安装
- wget https://codeload.github.com/luarocks/luarocks/zip/master -O luarocks-master.zip
- ./configure --lua-suffix=jit --with-lua=/home/hadoop/xuxuerui_test/kong/openresty/luajit --with-lua-include=/home/hadoop/xuxuerui_test/kong/openresty/luajit/include/luajit-2.1/ --prefix=/home/hadoop/xuxuerui_test/kong/luarocks
- cassandra安装(数据库可选pg和cassandra,同时本人会继续测试mysql)
- wget https://mirrors.tuna.tsinghua.edu.cn/apache/cassandra/3.0.20/apache-cassandra-3.0.20-bin.tar.gz
- vim conf/cassandra.yaml,更改配置后
- ./bin/cassandra启动
- ./bin/cqlsh 10.196.98.5 -u 'cassandra' -p 'cassandra'
- 增加kong用户
- kong安装
- git clone https://github.com/Kong/kong.git
- 修改Makefile中的luarocks路径
- export OPENSSL_DIR=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/openssl
- export PATH="$PATH:/Users/fnozoszzt/kong/openresty/bin"
- export LUA_PATH="/home/hadoop/xuxuerui_test/kong/luarocks/share/lua/5.1/?.lua;"
- 设置LUA_CPATH
- make install
- 安装过程缺少的库,通过yum安装都可以
- https://blog.csdn.net/scdxmoe/article/details/74755830
- cp ./openresty-1.17.8.2/zlib/lib/libz.so openresty/lualib/
- cp ../kong-master/kong/pdk/client/tls.lua resty/kong
- https://mutoulazy.github.io/2020/04/13/linux/%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85kong%202.0.3%E7%89%88%E6%9C%AC/#%E5%90%AF%E5%8A%A8kong
安装过程参考了以下文章
https://blog.csdn.net/lyking2001/article/details/82799068
遇到过的问题
1.如果报找不到resty 找不到nginx,需要先设置PATH环境变量
过程较为复杂
有其他问题也欢迎讨论