Kong的基本使用
简介Kong是一个在Nginx中运行的Lua应用程序,可以通过lua-nginx模块实现,Kong不是用这个模块编译Nginx,而是与OpenRestry一起发布,OpenRestry已经包含了lua-nginx-module,OpenRestry是Nginx的一组扩展功能模块。
Nginx的负载均衡配置
upstream my_stream {
server localhost:3000 weight=100;
}
server {
listen 80;
location /hello {
proxy_pass http://my_steam;
}
}
上面就是nginx最简单的nginx配置,可以转回http请求。
Kong配置
我们将上面nginx的配置转换成Kong的配置,操作如下:
1、配置upstream
[root@localhost ~]# curl -X POST http://localhost:8001/upstreams --data "name=my_stream"
{"created_at":1591599502,"hash_on":"none","id":"3524f785-9373-4020-be5f-bac876a08354","algorithm":"round-robin","name":"my_stream","tags":null,"hash_fallback_header":null,"hash_fallback":"none","hash_on_cookie":null,"host_header":null,"hash_on_cookie_path":"\/","healthchecks":{"threshold":0,"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_header":null,"slots":10000}
2、配置target
[root@localhost ~]# curl -X POST http://localhost:8001/upstreams/my_stream/targets --data "target=localhost:3000" --data "weight=100"
{"created_at":1591599638.753,"upstream":{"id":"3524f785-9373-4020-be5f-bac876a08354"},"id":"d3c6d09b-5779-480b-9573-a986f4c96083","target":"localhost:3000","weight":100}
3、配置service
[root@localhost ~]# curl -X POST http://localhost:8001/services --data "name=hello" --data "host=my_stream"
{"host":"my_stream","created_at":1591599716,"connect_timeout":60000,"id":"8a05e22b-8b88-4e86-b510-1943b4a5d8db","protocol":"http","name":"hello","read_timeout":60000,"port":80,"path":null,"updated_at":1591599716,"retries":5,"write_timeout":60000,"tags":null,"client_certificate":null}
这里会产生一个ID号:8a05e22b-8b88-4e86-b510-1943b4a5d8db
4、配置路由
[root@localhost ~]# curl -X POST http://localhost:8001/routes --data "paths[]=/hello" --data "service.id=8a05e22b-8b88-4e86-b510-1943b4a5d8db"
{"id":"341028c7-d2b4-4f0c-af67-3ee9b3be422c","path_handling":"v0","paths":["\/hello"],"destinations":null,"headers":null,"protocols":["http","https"],"methods":null,"snis":null,"service":{"id":"8a05e22b-8b88-4e86-b510-1943b4a5d8db"},"name":null,"strip_path":true,"preserve_host":false,"regex_priority":0,"updated_at":1591599797,"sources":null,"hosts":null,"https_redirect_status_code":426,"tags":null,"created_at":1591599797}
这里一切都是动态配置的,无需手动去配置。
为Kong新增路由信息需要操作upstream、target、service、route等,这边便是Kong最核心的四个对象。但是Kong不只是这些功能,如:
为hello服务添加50次/秒的限流:
curl -X POST http://localhost:8001/services/hello/plugins --data "name=rate-limiting" --data "config.second=50"
为hello服务jwt:
curl -X POST http://localhost:8001/services/hello/plugins --data "name=jwt"
插件也可以用在route上:
curl -X POST http://localhost:8001/services/{routeId}/plugins --data "name=rate-limiting" --data "config.second=50"
curl -X POST http://localhost:8001/services/{routeId}/plugins --data "name=jwt"
Editor.md 是一个可嵌入的开源 Markdown 在线编辑器组件,你可以很方便用在浏览器、NW.js(Node-webkit)等地方,基于CodeMirror、jQuery 和 Marked 构建。
APM(Application Performance Management)即应用性能管理系统,是对企业系统及时监控以实现对应用程序性能管理和故障管理的系统化解决方案。应用性能管理,主要指对企业的关键业务应用进行监控、优化,提高企业的应用的可靠性和治理,保证用户得到良好的服务,减低IT总拥有成本。
在于前端攻城狮的兄弟们开发接口的时候,总会遇到一些奇怪的问题。比如IOS对某个字段要求要整数,如果PHP这边返回过去是字符串那么APP就会崩溃。虽然他们可以捕获异常,但是有些时候我们更想后端的攻城狮能否提供一种统一的数据类型,前端想怎么转换就是他们自己的事情,本文我们将给大家带来这方面的处理。
Kong是一个在Nginx中运行的Lua应用程序,可以通过lua-nginx模块实现,Kong不是用这个模块编译Nginx,而是与OpenRestry一起发布,OpenRestry已经包含了lua-nginx-module,OpenRestry是Nginx的一组扩展功能模块。
经常使用npm下载相关包,但是由于npm的官方源在国外,所以每次下载相关包特别的慢,就算把源改成了国内镜像也还是不容易成功,所以干脆使用cnpm了。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题