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"
网页扫描二维码库:Html5-Qrcode,官网地址:https://scanapp.org/html5-qrcode-docs/
nodejs中使用npm和yarn,使用最新阿里云镜像 aliyun mirror,网上很多还是文章用的是下面这个地址~~yarn config set registry https://registry.npm.taobao.org~~
《康熙王朝》是一部非常优秀的电视连续剧,陈道明演的康熙是我觉得最有帝王气魄,让人意犹未尽,本文主要记录一小段非常经典的对白。
HI博客上线啦!这一刻不知道等待了多少年,做为以为技术开发人员,没有自己的博客怎么能行呢!最近利用换工作的空余的时间,为自己搭建了该博客,也在自己人生中很重要的日子上线了该博客。也希望该博客能将自己在工作中比较好的技术整理成文章和一些其他比较好文章转载过来,为需要用到相关技术的同行提供有用的帮助。还希望以后大家能指出相关文章中出现的错误,让看到相关博文的人受益,别被我的个人错误而误导他人。
默认情况下 pip 使用的是国外的镜像,在下载的时候速度非常慢,本文我们介绍使用国内源对pip进行加速。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
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问题
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。