Kong源码安装

Kong源码安装

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/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

安装openssl

下载openssl源码解压缩备用

使用openssl1.1.0l版本,需要将kong依赖中的luaossl版本改为:20190612(luaossl依赖openssl,所以一定需要先安装对应的openssl)

cd /data/server/kong

wget https://www.openssl.org/source/openssl-1.1.0l.tar.gz

tar -xf openssl-1.1.0l.tar.gz

root用户下安装openssl

cd openssl-1.1.0l

./config shared zlib

make & make install

mv /usr/bin/openssl /usr/bin/openssl.bak

find / -name openssl

ln -s /usr/local/bin/openssl /usr/bin/openssl

echo "/usr/local/lib64/" >> /etc/ld.so.conf

ldconfig

openssl version -a

测试openssl安装结果

openssl version -a

输出如下内容

OpenSSL 1.1.0l 10 Sep 2019

built on: reproducible build, date unspecified

platform: 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_profile

export 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.1

make build

make install

修改环境变量

vi ~/.bash_profile

export 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 启动服务。

评论

暂无评论