您的位置:首页 > 其它

Kong api 网关 安装简单应用

2018-01-25 17:34 204 查看
Kong是一个可伸缩的开源API层(也称为API网关或API中间件)。Kong最初是由Kong Inc.(前身为Mashape)建造的,用于为其API市场提供超过15000个微服务,每月产生数十亿个请求。
在经过实战检验的NGINX的支持下,该公司专注于高性能,在2015年成为开源平台。在积极的发展下,Kong现在已被用于从创业公司到大型企业和政府部门的数百个组织的生产,包括:《纽约时报》

支持 权限控制,安全,负载均衡,请求分发,监控,限流 等等。

github :
docker安装 :https://github.com/Kong/docker-kong
Kong 源码:https://github.com/Kong/kong
官网地址:https://getkong.org/
官网文档:https://getkong.org/docs/0.12.x/proxy/

安装:
cd /data/
git clone https://github.com/Kong/docker-kong.git cd docker-kong/compose
docker-compose up -d




Kong 项目会监控两个端口,一个是 8000,一个是 8001。 8000端口是可以给用户访问,就是说用户发送请求先到 Kong 项目的 8000 端口,然后Kong 项目帮你转到你的后端应用api。 8001 端口是管理端口,比如说,管理员可以通过 8001端口来得到你加入过的 api。

二:kong  api 增删改查
1、添加API
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=test1' \
-d 'upstream_url=http://10.4.21.101' \
-d 'uris=/admin' \
-d 'strip_uri=false'

curl -i -X POST http://localhost:8001/apis/ \
-d 'name=test2' \
-d 'upstream_url=http://10.4.37.242' \
-d 'uris=/admin/login.html'

url:8001端口是Kong的管理端口。
name: api名称
upstream_url:提供服务的后端url。
uris:请求的地址
strip_uri:是否截断url    #  /admin/order.html  会把admin去掉

2、查询api
curl -X GET http://localhost:8001/apis/ curl -X GET http://localhost:8001/apis/test1 
3、删除api
curl -X  DELETE http://localhost:8001/apis/test1 
4、更新api
curl -i -X PATCH http://localhost:8001/apis/test1 -d 'name=test3'

5、验证 kong是否成功路由
通过上面创建的api  根据不同的URL请求到后端不同的服务器;
/admin/login.html---http://10.4.37.242
/admin 其他----http://10.4.21.101
/      {"message":"no API found with those values"}
/agent    {"message":"no API found with those values"}






类似于nginx反向代理,可动态调整、相当灵活;
还有其他功能待验证。。。。。

图形化客户端 工具可以管理API;





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  微服务 API 网关