现在建网站/品牌营销案例

Kong is a cloud-native, fast, scalable, and distributed Microservice API Gateway
背景
虽然Kong已经出到了2.0,但是因为之前是基于Kong 1.2.1做的扩展开发,所以这里讲解Kong的源码、开发环境搭建都是基于1.2.1版本,后续的版本也可以按照这个流程走,只是各个组件的版本不一样而已。
依赖版本
0. kong 基于1.2.1的扩展
1. openresty 1.13.6.2
2. luarocks 2.4.3
安装依赖
ibyaml-devel.x86_64
安装yaml包`yum install libyaml-devel.x86_64`
如果没有yaml包,在执行`/data/app/luarocks/bin/luarocks make`编译kong的时候会报错:
Error: Failed installing dependency: https://luarocks.org/lyaml-6.2.3-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/lib64You 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
安装openssl
下载openssl源码解压缩备用
使用openssl1.1.0l版本,需要将kong依赖中的luaossl版本改为:20190612(luaossl依赖openssl,所以一定需要先安装对应的openssl)
cd /data/server/kongwget https://www.openssl.org/source/openssl-1.1.0l.tar.gztar -xf openssl-1.1.0l.tar.gzroot用户下安装opensslcd openssl-1.1.0l./config shared zlibmake & make installmv /usr/bin/openssl /usr/bin/openssl.bakfind / -name opensslln -s /usr/local/bin/openssl /usr/bin/opensslecho "/usr/local/lib64/" >> /etc/ld.so.confldconfigopenssl version -a
测试openssl安装结果
openssl version -a输出如下内容OpenSSL 1.1.0l 10 Sep 2019built on: reproducible build, date unspecifiedplatform: linux-x86_64......
安装openresty
下载编译安装Openresty
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
./configure --with-pcre-jit --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module --prefix=/data/app/openresty --with-openssl=/data/server/kong/openssl-1.1.0l
修改环境变量
vi ~/.bash_profileexport PATH="$PATH:/data/app/openresty/bin"export PATH="$PATH:/data/app/openresty/luajit/lib"export PATH="$PATH:/data/app/openresty/luajit/include/luajit-2.1"source ~/.bash_profile
安装luarocks
下载编译安装luarocks
wget https://github.com/luarocks/luarocks/archive/2.4.3.zip./configure --lua-suffix=jit --prefix=/data/app/luarocks --with-lua=/data/app/openresty/luajit --with-lua-include=/data/app/openresty/luajit/include/luajit-2.1make buildmake install
修改环境变量
vi ~/.bash_profileexport PATH="$PATH:/data/app/luarocks/bin"export LUA_PATH="/data/app/luarocks/share/lua/5.1/?.lua"source ~/.bash_profile
编译安装kong
上传kong的源码,或者下载官方源码
解压缩,进入源码根目录,执行`/data/app/luarocks/bin/luarocks make`
最后输出表示安装成功
kong 1.2.1-0 is now installed in /data/app/luarocks (license: Apache 2.0)
再再修改一环境变量
export PATH="$PATH:/data/server/kong/kong/bin"
修改配置
根据需要修改配置文件,启动服务
初始化环境
第一次使用Kong需要对环境初始化,初始化主要是将核心的表在数据库中进行创建、数据插入。
启动服务
通过bin/kong start -c kong.conf 启动服务。