mac系统/aarch架构源码编译安装kong文档

由于在项目中需要使用网关模块

经过技术调研和选型,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架构

  1. openresty安装
    1. 下载
      1. wget https://openresty.org/download/openresty-1.17.8.2.tar.gz
    2. configure文件修改
      1. https://blog.csdn.net/leehbing/article/details/77750803?skintest=skin3-template-test
    3. 安装pcre和openssl zlib,也是源码编译安装
    4. ##./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
    5. ./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
  2. luarocks安装
    1. wget https://codeload.github.com/luarocks/luarocks/zip/master -O luarocks-master.zip
    2. ./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
  3. cassandra安装(数据库可选pg和cassandra,同时本人会继续测试mysql)
    1. wget https://mirrors.tuna.tsinghua.edu.cn/apache/cassandra/3.0.20/apache-cassandra-3.0.20-bin.tar.gz
    2. vim conf/cassandra.yaml,更改配置后
    3. ./bin/cassandra启动
    4. ./bin/cqlsh 10.196.98.5 -u 'cassandra' -p 'cassandra'
      1. 增加kong用户
  4. kong安装
    1. git clone https://github.com/Kong/kong.git
    2. 修改Makefile中的luarocks路径
    3. export OPENSSL_DIR=/home/hadoop/xuxuerui_test/kong/openresty-1.17.8.2/openssl
    4. export PATH="$PATH:/Users/fnozoszzt/kong/openresty/bin"
    5. export LUA_PATH="/home/hadoop/xuxuerui_test/kong/luarocks/share/lua/5.1/?.lua;"
    6. 设置LUA_CPATH
    7. make install
    8. 安装过程缺少的库,通过yum安装都可以
    9. https://blog.csdn.net/scdxmoe/article/details/74755830
      1. cp ./openresty-1.17.8.2/zlib/lib/libz.so openresty/lualib/
      2. cp ../kong-master/kong/pdk/client/tls.lua resty/kong
      3. 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
      4.  

 

 

 

安装过程参考了以下文章

https://blog.csdn.net/lyking2001/article/details/82799068

 

遇到过的问题

1.如果报找不到resty  找不到nginx,需要先设置PATH环境变量

 

过程较为复杂

有其他问题也欢迎讨论

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值