美文网首页
糕dy带你玩kong🐒

糕dy带你玩kong🐒

作者: GoddyWu | 来源:发表于2018-11-01 16:28 被阅读0次

网上看了很多关于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

相关文章

网友评论

      本文标题:糕dy带你玩kong🐒

      本文链接:https://www.haomeiwen.com/subject/mlmtxqtx.html