Mac下源码构建Kong

背景

  • Nginx 应该最著名的反向代理服务器。
  • Openresty 基于Nginx 与 Lua 的高性能 Web 平台,是一个完整生态。
  • Kong 基于Nginx (Openresty)的ApiGateway

参考资料:
Nginx中文
Openresty中文
Kong的Github

构建说明

版本:
Openresty : 1.13.6.2rc0
Kong: 0.12.1

  • 安装依赖
brew update
brew install openssl  pcre        
# 如果存在则可以更新
brew upgrade openssl pcre
  • 下载源码
git clone https://github.com/openresty/openresty.git
cd openresty
make 
Mac下源码构建Kong_第1张图片
生成openresty代码

cd openresty-1.13.6.2rc0

Mac下源码构建Kong_第2张图片
源码包
./configure \
  --with-pcre-jit \
  --with-ipv6 \
  --with-http_realip_module \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --with-http_v2_module \
  --with-cc-opt="-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/" \
  --with-ld-opt="-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/" \
  -j4

这里的openssl和pcre的头文件和库文件都安装在/usr/local/opt下,如果使用brew安装的,默认是该路径,如果不在则需要修改,否则编译Nginx会出错

make
sudo make install

将openresty加入环境变量,默认安装在/usr/local/openresty

echo export PATH=$PATH:/usr/local/openresty >> ~/.zshrc
source ~/.zshrc

openresty安装参考:
http://openresty.org/cn/installation.html

  • 安装Kong
git clone https://github.com/Kong/kong.git
cd kong
sudo make install

官方安装向导切换到next分支git checkout next,本文直接在master分支

  • 安装postgres
    直接在docker里下载官方的postgres


    Mac下源码构建Kong_第3张图片
    官方镜像

进入容器,创建用户及库

su - postgres
psql
CREATE USER kong; CREATE DATABASE kong OWNER kong;
Mac下源码构建Kong_第4张图片
容器shell
  • 启动kong
sudo kong start
版本验证失败

修改Kong使用的Openresty版本

cd /usr/local/share/lua/5.1/kong
vi meta.lua

openresty最新版本是openresty/1.13.6.2rc0 (clone日:2018-02-15)
修改kong脚本中的版本(也可以在下载的源码中修改后安装)


Mac下源码构建Kong_第5张图片
修改必要版本信息.png
  • 重新运行
kong start
  • 加入测试api

请参考kong配置说明
https://getkong.org/docs/0.12.x/getting-started/adding-your-api/

后记

你可能感兴趣的:(Mac下源码构建Kong)