what

problems





多个服务要写自己的log,auth,对于比较耗时的,有时还要高流量限制。

solution intro

单点部署的情况:



why not just haproxy log (kinbana)

haproxy rate limit http://blog.serverfault.com/2010/08/26/1016491873/

simple version:

  1. frontend fe_api_ssl
  2. acl too_many_uploads_by_user sc0_gpc0_rate() gt 100
  3. acl mark_seen sc0_inc_gpc0 gt 0
  4. stick-table type string size 100k store gpc0_rate(60s)
  5. tcp-request content track-sc0 hdr(Authorization) if METH_POST document_request is_upload
  6. use_backend be_429_slow_down if mark_seen too_many_uploads_by_user
  7. backend be_429_slow_down
  8. timeout tarpit 2s
  9. errorfile 500 /etc/haproxy/errorfiles/429.http
  10. http-request tarpit
  11. backend be_api

feature

install

try to use docker instead of pkg/deb/vagrant

  1. docker run -d --name kong-database -p 5432:5432 -e "POSTGRES_USER=kong" -e "POSTGRES_DB=kong" postgres:9.4
  2. docker run -d --name kong-database -p 9042:9042 cassandra:3
  3. dengwei@RMBAP:~/projects/github/kong$ docker ps -a
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. b1b969345f2c kong:latest "/docker-entrypoin..." 16 hours ago Up 16 hours 0.0.0.0:7946->7946/tcp, 0.0.0.0:8000-8001->8000-8001/tcp, 0.0.0.0:8443->8443/tcp, 0.0.0.0:7946->7946/udp kong
  6. 9d73317da8e3 cassandra:3 "/docker-entrypoin..." 16 hours ago Up 16 hours 7000-7001/tcp, 7199/tcp, 9160/tcp, 0.0.0.0:9042->9042/tcp kong-database
  7. kong-database

config

  1. http localhost:8001
  1. HTTP/1.1 200 OK
  2. ...
  3. Server: kong/0.10.2
  4. {
  5. "configuration": {
  6. "admin_ip": "0.0.0.0",
  7. "admin_listen": "0.0.0.0:8001",
  8. "admin_listen_ssl": "0.0.0.0:8444",
  9. "admin_port": 8001,
  10. "admin_ssl": true,
  11. ...
  12. "admin_ssl_ip": "0.0.0.0",
  13. "admin_ssl_port": 8444,
  14. "anonymous_reports": true,
  15. "cassandra_consistency": "ONE",
  16. "cassandra_contact_points": [
  17. "kong-database"
  18. ],
  19. "cassandra_data_centers": [
  20. "dc1:2",
  21. "dc2:3"
  22. ],
  23. "cassandra_keyspace": "kong",
  24. "cassandra_lb_policy": "RoundRobin",
  25. "cassandra_port": 9042,
  26. ...
  27. "pg_user": "kong",
  28. "plugins": {
  29. "acl": true,
  30. ...
  31. },
  32. "prefix": "/usr/local/kong",
  33. "proxy_ip": "0.0.0.0",
  34. "proxy_listen": "0.0.0.0:8000",
  35. ...
  36. },
  37. "hostname": "b1b969345f2c",
  38. "lua_version": "LuaJIT 2.1.0-beta2",
  39. "plugins": {
  40. "available_on_server": {
  41. "acl": true,
  42. ...
  43. },
  44. "enabled_in_cluster": {}
  45. },
  46. ...
  47. "tagline": "Welcome to kong",
  48. "timers": {
  49. "pending": 4,
  50. "running": 0
  51. },
  52. "version": "0.10.2"
  53. }

adding an api:

  1. http POST localhost:8001/apis name=demo upstream_url=http://mockbin.org/request request_host=mockbin.org

host with port

  1. http POST localhost:8001/apis name=localdemo upstream_url=http://localhost:3010/request hosts=localhost

list apis:

  1. http localhost:8001/apis

check admin log

in docker container:

  1. sh-4.2# ls
  2. access.log admin_access.log error.log serf.log

use plugin

  • auth example

    1. http POST localhost:8001/apis/0ee4b228-3089-4ae9-b13a-09ba4df8004e/plugins name=key-auth config.key_names=X-AUTH
    2. http POST localhost:8001/consumers/b7199b84-cbe6-47ef-9cd0-c68ab27dfee0/key-auth key=abc123

verify :

  1. http localhost:8000 HOST:mockbin.org X-AUTH:1234
  2. http localhost:8000 HOST:mockbin.org X-AUTH:abc123

previous one won't work , latter one works, which with the right key

  • rate limit example:

    find your api id by list apis

    http localhost:8001/apis

in my example the api id is: 0ee4b228-3089-4ae9-b13a-09ba4df8004e

  1. http POST localhost:8001/apis/0ee4b228-3089-4ae9-b13a-09ba4df8004e/plugin;5Cs name=rate-limiting config.minute=5 config.hour=10

test it:

  1. http localhost:8000 Host:mockbin.org X-AUTH:abc123
  2. HTTP/1.1 200 OK

after 5 times with 1 minute:

  1. dengwei@RMBAP:~/projects/work$ http localhost:8000 Host:mockbin.org X-AUTH:abc123
  2. HTTP/1.1 429
  3. Connection: keep-alive
  4. Content-Type: application/json; charset=utf-8
  5. Date: Thu, 25 May 2017 12:18:35 GMT
  6. Server: kong/0.10.2
  7. Transfer-Encoding: chunked
  8. X-RateLimit-Limit-hour: 10
  9. X-RateLimit-Limit-minute: 5
  10. X-RateLimit-Remaining-hour: 0
  11. X-RateLimit-Remaining-minute: 5
  12. {
  13. "message": "API rate limit exceeded"
  14. }

how does it work

rest api with other url in sub page

ui for monitor(need enterprise)

plugin with other language?

to do or not

api gateway: to be or not to be

ref

API & Microservices Management with Kong

kong基础使用

kong ui

kong dashboard

docker

使用Kong来管理业务restful api

[聊聊架构:深入浅出聊聊企业级API网关](https://mp.weixin.qq.com/s?__biz=MzA5Nzc4OTA1Mw==&mid=2659599286&idx=1&sn=f41c9dc7f9f2027eab97889b1b01a391&chksm=8be996a4bc9e1fb29ea77d0941bedb60714c6a7ae94edd44bf705a0910979e18e631210ab326)

problems

in docker you will not success in forward your request via kong. issue here

  1. dengwei@RMBAP:~/projects/work$ http POST localhost:8001/apis name=localdemoabc upstream_url=http://localhost:3010/ uris=/abc
  2. HTTP/1.1 201 Created
  3. dengwei@RMBAP:~/projects/work$ http localhost:8000/abc host=localhost
  4. HTTP/1.1 502 Bad Gateway

todo:

nginx + koa sample

how routing work and verify

ui page

speed lost

comparing with other api gateway: loopback.io http://orange.sumory.com/

API Gateway : Kong的更多相关文章

  1. API Gateway - KONG 安装与配置

    简介 Kong,是由Mashape公司开源的,基于Nginx的API gateway 特点 可扩展,支持分布式 模块化 功能:授权.日志.ip限制.限流.api 统计分析(存在商业插件Galileo等 ...

  2. kong API gateway

    参考:https://www.cnblogs.com/chenjinxi/p/8724564.html 一.简介 Kong,是由Mashape公司开源的,基于Nginx的API gateway. 二. ...

  3. API gateway 之 kong 基本操作 (三)

    一.演示环境准备 1.nginx配置 [root@nginx conf.d]# pwd /etc/nginx/conf.d [root@nginx conf.d]# ls conf_bak kong_ ...

  4. API gateway 之 kong 基本介绍 (一)

    一.API网关概念介绍 API 网关,即API Gateway,是大型分布式系统中,为了保护内部服务而设计的一道屏障,可以提供高性能.高可用的 API托管服务,从而帮助服务的开发者便捷地对外提供服务, ...

  5. 关于kong | API Gateway

    目录 为什么需要 API 网关(more) kong的概念 为什么使用Kong Kong 的管理方式 高可扩展性的背后-插件机制 [前言]: Kong是一个云原生,高效,可扩展的分布式 API 网关. ...

  6. Docker安装Kong API Gateway并使用

    我最新最全的文章都在南瓜慢说 www.pkslow.com,文章更新也只在官网,欢迎大家来喝茶~~ 1 简介 Kong不是一个简单的产品,本文讲的Kong主要指的是Kong API Gateway,即 ...

  7. 谈谈微服务中的 API 网关(API Gateway)

    前言 又是很久没写博客了,最近一段时间换了新工作,比较忙,所以没有抽出来太多的时间写给关注我的粉丝写一些干货了,就有人问我怎么最近没有更新博客了,在这里给大家抱歉. 那么,在本篇文章中,我们就一起来探 ...

  8. 聊聊 API Gateway 和 Netflix Zuul

    最近参与了公司 API Gateway 的搭建工作,技术选型是 Netflix Zuul,主要聊一聊其中的一些心得和体会. 本文主要是介绍使用 Zuul 且在不强制使用其他 Neflix OSS 组件 ...

  9. 微服务中的 API 网关(API Gateway)

    API 网关(API Gateway)提供高性能.高可用的 API 托管服务,帮助用户对外开放其部署在 ECS.容器服务等云产品上的应用,提供完整的 API 发布.管理.维护生命周期管理.用户只需进行 ...

随机推荐

  1. Ngnix配置

    server { listen 80; server_name www.local.test; root /data/workspace;  index index.php index.html in ...

  2. JsonWebToken Demo(转)

    namespace TokenTest { using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System. ...

  3. ES6标准之基础

    let和const命令 ES6新增let命令,用于声明变量,是块级作用域. let声明的变量不会像var声明的变量发生“变量提升”现象,所以,变量一定要在声明后使用,不然就会报错. 暂时性死区:只要块 ...

  4. Servelet开发步骤和生命周期

    Servelet开发步骤和生命周期 (1)    程序员开发程序,实现servelet的init和destroy接口 .重写servlet的 doGet.doPost.doPut.doDelete四个 ...

  5. [Spring MVC] 表单提交日期转换问题,比如可能导致封装实体类时400错误

    三种格式的InitBinder @InitBinder//https://stackoverflow.com/questions/20616319/the-request-sent-by-the-cl ...

  6. 4、NFS

    一.NFS简介 4.1.1:什么是NFS NFS(Network File System,网络文件系统)是由SUN公司开发,并于1984年推出的技术,通过使用NF,用户和程序可以向访问本地文件一样访问 ...

  7. 页面检测网络外网连接- 网页基础模块(JavaScript)

    方法一 html 添加图片标签 加载外站图片 <img id="connect-test" style="display:none;" onload=&q ...

  8. RobotFramework--环境安装1

    1.RobotFramework RobotFramework 的架构是一个通用型的验收测试和验收测试驱动开发的自动化测试框架(ATDD).它 具有易于使用的表格来组织测试过程和测试数据. 3.1版本 ...

  9. react-thunk的使用流程

    react-thunk作用:使我们可以在action中返回函数,而不是只能返回一个对象.然后我们可以在函数中做很多事情,比如发送异步的ajax请求. 这就是react-thunk的使用方法.接受一个d ...

  10. CAD小小调整,复制生成二层5.28

    1.栏杆剖切索引:“符号标注”“索引符号",填写文字,标注效果: 2,台阶剖切索引:填写文字,标注效果: 3.符号标注:图名标注: 4一层平面图完成.复制生成二层平面,把图名改为”二层平面图 ...