糕dy带你玩kong🐒

网上看了很多关于kong的资料,但是和oauth2结合的不太清晰,所以写几篇博客帮其他人理解kong+oauth2的结合使用。

简介

https://konghq.com/about-kong/
kong基于nginx开发的API Gateway(可以认为是一个OpenResty应用程序),可以方便的横向扩展,可以方便的添加已定义的插件,甚至可以自己开发插件并使用,底层使用Apache Cassandra或PostgreSQL数据库。
它的核心功能:

  • 代理(proxy):
  • 集群(cluster):
  • 负载均衡(load balance):
  • 登录(authentication):
  • 健康检查(health check):
  • 日志(logging)
  • API: KONG的配置由REST API完成

kong的核心概念:

  • 服务(service)
  • 消费者(consumer)
  • 插件(plugin)
  • (target)
  • 路由(route)

安装

https://konghq.com/install/
楼主使用的mac,简单使用homebrew工具安装即可。
官方mac安装教程官方快速使用教程

# 安装数据库
$ brew install postgresql
# 初始化数据库
$ initdb /usr/local/var/postgres
# 启动
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# 停止
$ pg_ctl -D /usr/local/var/postgres stop -s -m fast
# 登录指定数据库
$ psql -d postgres
$ CREATE USER kong; CREATE DATABASE kong OWNER kong;

$ brew tap kong/kong
$ brew install kong
# 中括号里的不用,brew安装的没有kong.conf文件
$ kong migrations up [-c /path/to/kong.conf]
$ kong start [-c /path/to/kong.conf]
$ kong stop
$ kong reload

kong 占用的端口:

  • :8000 资源访问端口 http协议
  • :8443 资源访问端口 https协议
  • :8001 管理员访问端口 http协议
  • :8444 管理员访问端口 https协议

官网资料是非常详细的,这里就不翻译了。 https://docs.konghq.com/0.14.x/getting-started/introduction/

附:

docker-compose 启动

version: '2.1'
services:
  kong-database:
    image: postgres:9.5
    environment:
      - POSTGRES_USER=kong
      - POSTGRES_DB=kong
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 30s
      timeout: 30s
      retries: 3
    restart: on-failure
  kong:
    image: kong:latest
    command: kong start --run-migrations
    depends_on:
      kong-database:
        condition: service_healthy
    healthcheck:
      test: "kong health"
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
      - KONG_PG_DATABASE=kong
      - KONG_ADMIN_LISTEN=0.0.0.0:8001        
    ports:
      - "8000:8000"
      - "8001:8001"
      - "8443:8443"
      - "8444:8444"
    restart: on-failure
  kong-dashboard:
    image: pgbi/kong-dashboard
    depends_on:
      kong:
        condition: service_healthy
    entrypoint: ./docker/entrypoint_dev.sh
    ports:
      - "8080:8080"

参考:

reference

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 直接进入正题吧,这篇文章直接讲构建完整的kong+oauth2协议的例子。 官方地址oauth插件:https:/...
    GoddyWu阅读 4,734评论 0 3
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,009评论 19 139
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    aimaile阅读 26,597评论 6 427
  • Kong 是 Mashape 开源的高性能高可用 API 网关和 API 管理服务层。它基于 OpenResty ...
    meng_philip123阅读 9,146评论 0 6
  • 不知道是不是每个人都像我一样,对初恋依旧恋恋不舍。 当然恋恋不舍的不是初恋这个人,毕竟那个人说不定和我们相隔着整个...
    轻情阅读 179评论 0 0