1 Konga UI基本使用
一般访问地址:
http://192.168.1.70:8080
1.1创建步骤1:更新流
1.1.1【样品】
Name=VCSAPI_SERVER
Slot=1000
1.2步骤2:配置升级目标
1.2.1【样品】
配置多个节点、多个目标即可。
Target=192.168.10.30:8080
Weight=100
1.3添加step : API服务
1.3.1【样品】
Name=VCSAPI-SERVICE
HOST=VCSAPI_SERVER (注意:对应upstream name )
端口=80
path=/vcs (注意:根据目标传输路径并根据实际部署上下文进行调整) )。
1.4步骤4:配置API路由
1.4.1【样品】
服务=VCS API -服务
paths=/vcs (注意:客户端请求路径,根据实际部署进行调整) ) )。
从Preserve Host:true客户端请求的HOST通过kong透明地传递到上游服务器。
Strip path:true,是否删除匹配的url前缀。
1.5步骤5:配置顾问
1.5.1【样品】
username=icfw
1.6设置step 6:用户JWT身份验证
1.6.1【样品】
结束点
是密钥(ISS )
安全
icfw
qd8 wkwxqwqzvcdhc 05 yzqdprlzmqjmh 8
re1neaucwbqftj0mxi P1 hy1psfbocvez
注意:创建key secret时,系统可以自动生成随机字符串,而无需输入。
1.7 Step7:配置服务JWT插件
1.7.1【样品】
选择Apply to=VCSAPI_SERVICE,service-plugins-jwt
Key_claim_name=iss,固定表示法,与key相对应
Claims_to_verify=exp,固定表示法,jwt token到期日期,unix时间数值列.(可选)
1.7.2生成jwt token
通过访问https://jwt.io/来生成JWT TOKEN
1.7.3客户端调用,HTTP头(Authorization ) :设置Bearer jwtkoken字符串。
1.8配置step 7:限流插件
1.8.1【样品】
Apply to service=,根据场景选择servcie即可
policy=redis,限流策略方式,这里使用redis
limit_by=ip,限流维度,在此用于ip限流
second=10,控制在每秒同时10以内(单ip接入) )
redis_password=redis配置密码
redis_host=192.168.1.203
redis_database=0,选择数据库编号,此处为0
配置限流插件,注意数据库PG中的时间是否与北京时间同步。 由于受时间事件控制,如果时间错误,则尽管配置了限制流,但不会触发限制流。
1.9 Step8:服务降级实现
基于Kong的服务降级思路如下。
1清理需要服务降级的接口
2按降级时返回的数据进行分类,将同一根发送到同一uri ((预先配置了Kong配置) ) ) )。
3接入网关的不同路由配置
通过Kong的请求中断插件实现服务降级,减轻对后台服务器(api等)的访问压力。
在逻辑上,打开限流策略可以避免大部分恶意压力,但也可以将服务降级作为补充方案,而不排除模拟真实APP场景的***方案。
1.9.1【样品】
Apply to=service,选择为每个场景指定的服务
Status_code=200,自定义,通常为200
Content_type=
gt;application/json; charset=utf-8,自定义Response body=>{"result": {},"code": 200,"message": "OK" },需要开发整理
2 访问Kong管理接口
2.1 查看service:http://192.168.20.22:8001/services
{
"next": null, "data": [ { "host": "VCSAPI_SERVER", "created_at": 1551856065, "connect_timeout": 6000, "id": "4fc01ba9-6779-477d-8a49-76982650deed", "protocol": "http", "name": "VCSAPI_SERVICE", "read_timeout": 6000, "port": 80, "path": "/vcs", "updated_at": 1551944738, "retries": 5, "write_timeout": 6000 }, { "host": "192.168.10.30", "created_at": 1551851624, "connect_timeout": 60000, "id": "bc64c9c2-7399-4d2d-a616-2311f450160a", "protocol": "http", "name": "test-service", "read_timeout": 60000, "port": 8080, "path": "/vcs/index.html", "updated_at": 1551853564, "retries": 5, "write_timeout": 60000 } ]}
2.2 查看路由(routes):http://192.168.20.22:8001/routes
{
"next": null,
"data": [
{
"created_at": 1551856120,
"methods": [ ],
"id": "ead9e93a-7b74-4528-8df3-fe7963006317",
"service": {
"id": "4fc01ba9-6779-477d-8a49-76982650deed"
},
"name": "vcs",
"hosts": [ ],
"updated_at": 1551861483,
"preserve_host": true,
"regex_priority": 0,
"paths": [
"/vcs"
],
"sources": [ ],
"destinations": [ ],
"snis": [ ],
"protocols": [
"http",
"https"
],
"strip_path": true
},
{
"created_at": 1551851896,
"methods": [ ],
"id": "fd37c027-3ba3-49e1-9543-a4be07d499e2",
"service": {
"id": "bc64c9c2-7399-4d2d-a616-2311f450160a"
},
"name": "test",
"hosts": [ ],
"updated_at": 1551852181,
"preserve_host": false,
"regex_priority": 0,
"paths": [
"/test1"
],
"sources": [ ],
"destinations": [ ],
"snis": [ ],
"protocols": [
"http",
"https"
],
"strip_path": true
}
]
}
2.3 查看upstreams:http://192.168.20.22:8001/upstreams
{
"next": null,
"data": [
{
"created_at": 1551943496,
"hash_on": "none",
"id": "e8910221-7302-4305-a3e6-e02ea5d673b4",
"name": "VCSAPI_SERVER",
"hash_fallback_header": null,
"hash_on_cookie": null,
"healthchecks": {
"active": {
"unhealthy": {
"http_statuses": [
429,
404,
500,
501,
502,
503,
504,
505
],
"tcp_failures": 0,
"timeouts": 0,
"http_failures": 0,
"interval": 0
},
"type": "http",
"http_path": "/",
"timeout": 1,
"healthy": {
"successes": 0,
"interval": 0,
"http_statuses": [
200,
302
]
},
"https_sni": null,
"https_verify_certificate": true,
"concurrency": 10
},
"passive": {
"unhealthy": {
"http_failures": 0,
"http_statuses": [
429,
500,
503
],
"tcp_failures": 0,
"timeouts": 0
},
"healthy": {
"http_statuses": [
200,
201,
202,
203,
204,
205,
206,
207,
208,
226,
300,
301,
302,
303,
304,
305,
306,
307,
308
],
"successes": 0
},
"type": "http"
}
},
"hash_on_cookie_path": "/",
"hash_fallback": "none",
"hash_on_header": null,
"slots": 1000
}
]
}
2.4 查看Pluginshttp://192.168.20.22:8001/plugins
{
"next": null,
"data": [
{
"created_at": 1551945986,
"config": {
"secret_is_base64": false,
"key_claim_name": "iss",
"cookie_names": [ ],
"maximum_expiration": 0,
"claims_to_verify": null,
"anonymous": null,
"run_on_preflight": true,
"uri_param_names": [ ]
},
"id": "26105b8b-90e0-4e02-89b3-758f47ff74ce",
"service": {
"id": "4fc01ba9-6779-477d-8a49-76982650deed"
},
"enabled": true,
"run_on": "first",
"consumer": null,
"route": null,
"name": "jwt"
}
]
}