KONG GATEWAY 基本介绍及安装

1 Kong基本介绍
Kong 基于Nginx和lua实现的API GateWay,用于管控Restful接口:

  1. 使用修改过的Nginx作为代理服务器,即Openrestry,该服务器负责处理Api请求。
  2. Cassandra或者postgresql用作数据存储(Datastore)服务器,存储来自kong操作的数据。数据持久化建议采用Cassandra,原因如下:1)易于构建分布式 2)易于扩展。
  3. 基于Apache license认证。Kong 随着openrestry分发,已经包含lua-nginx-module.Openrestry不是nginx分支版本,而是扩展了nginx的一组module.核心包还是用nginx官方的。(Kong is distributed along with OpenResty, which already includes lua-nginx-module. OpenResty is not a fork of Nginx, but a bundle of modules extending its capabilities.)
    1.1 产品结构
    KONG GATEWAY 基本介绍及安装
    1.2 总体架构

KONG GATEWAY 基本介绍及安装

注:生产环境下,将DNS解析到kong即可,或者kong通过LVS负载分发,将DNS解析到LVS所在节点即可。
1.3 特征
1.3.1 Restful接口
Restful Interface
1.3.2 平台无关
Platform Agnostic
1.3.3 面向插件
Plugin oriented
1.3.4 扩展简单
Simple Scaling
1.3.5 高性能
Kong本事性能与nginx在一个级别上,另外可以实现灵活快速扩展,满足分布式环境下高并发大流量访问接入。
KONG GATEWAY 基本介绍及安装

上图是在基本认证开启情况下,kong与tyk性能对比,横座标表示服务运行数量,纵座标表示QPS,即每秒请求数量。

1.4 产品功能
KONG GATEWAY 基本介绍及安装

1.5 适用场景
作为API-GATEWAY,kong在通用互联网架构适用场景:
KONG GATEWAY 基本介绍及安装

2 Kong 安装
2.1 软件环境
CentOS Linux release 7.3.1611 64位
KongServer version =>1.0.3
PostgreSQL => 10.1 Schema:kong || User:kong
Nodejs: node-v8.11.3-linux-x64.tar
2.2 安装数据库
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
yum install postgresql10
yum install postgresql10-server
/usr/pgsql-10/bin/postgresql-10-setup initdb
vi /var/lib/pgsql/10/data/postgresql.conf
listen_addresses = '*'
vi pg_hba.conf
host all all 0.0.0.0/0 md5
systemctl enable postgresql-10
systemctl start postgresql-10

2.3 安装node and npm
xz -d node-v8.11.3-linux-x64.tar.xz
tar -xvf ./node-v8.11.3-linux-x64.tar
vi /etc/profile
export NODE_HOME=/opt/node
export PATH=${NODE_HOME}/bin/:$PATH
source /etc/profile
2.4 创建数据库
su - postgres
psql
1>create user kong with password 'icfw1602';
2>CREATE DATABASE kong OWNER kong;
3> grant all privileges on database kong to kong;
2.5 安装并启动kongserver
yum install -y perl-Time-HiRes.x86_64
rpm -ivh kong-community-edition-1.0.3.el7.noarch.rpm
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
vi /etc/kong/kong.conf => configure postgresql port and password
/usr/local/bin/kong migrations bootstrap [-c /etc/kong/kong.conf] =>初始化数据库

/usr/local/bin/kong start
2.6 安装可视化管理工具
1)下载源码(AngularJS )并编译
npm install -g bower
npm install -g gulp
npm install -g sails
git clone https://github.com/pantsel/konga.git
cd konga
npm install --unsafe-perm
2)配置数据库
su - postgres
psql
1>CREATE DATABASE konga OWNER kong;
2>grant all privileges on database konga to kong;
#cp konga/.env_example konga/.env
#vi .env
PORT=8080
NODE_ENV=production
KONGA_HOOK_TIMEOUT=120000
DB_ADAPTER=postgres
DB_HOST=192.168.20.22
DB_DATABASE=konga
DB_USER=kong
DB_PASSWORD=icfw1602
3) 初始化数据库
su - postgres
cd konga
node ./bin/konga.js prepare --adapter postgres --uri postgresql://192.168.20.22:5432/konga
(创建数据库,如出现数据库连接异常,设置vi pg_hba.conf,将host all all 0.0.0.0/0
md5中md5调整为trust并重启数据库,创建数据库后,还原为md5.并确认konga数据库、创建表owner为用户kong,如不是则调整)
alter table xx owner to kong;
4)启动konga
nohup npm run production >run.log & (已daemon方式启动)
Konga GUI will be available at http://localhost:8080
3 引用资源
Kong 在线资源:https://docs.konghq.com/
Konga 在线资源:https://github.com/pantsel/konga
Kong 中文资源:https://www.pocketdigi.com/book/kong/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章