轉自:http://blog.54im.com/2016/12/15/centos-install-kong-cassandra/#
前置閱讀
對于一些傳統的大型項目,傳統的方式會有一些缺陷,比如說新人熟悉系統成本高(因為整個系統作為一個整體,彼此會有一定的牽連),項目重啟時間長,重構困難(對于一個新技術的引入,可能需要對整個項目推到重來),不易于更換新的技術,并且整個項目會慢慢變成巨無霸。
近年來微服務受到越來越多國內企業的青睞。當企業現有系統的復雜度、維護和擴展成本成為業務發展瓶頸時,微服務可以幫助企業拆分、解耦現有的系統,從而提高系統的可維護和可擴展性。Airbnb、Dropbox、Twitter等互聯網公司,在使用微服務架構之后,功能發布周期減少了75%,微服務的核心在于根據業務和具體粒度劃分API,那么如何管理API就顯得尤為重要。
拿日常的電商購物舉例,一個服務實現一個不同的特性或者功能。每一個獨立的微服務都是一個小型應用。一些微服務可能會暴露一些api 給其他的一些微服務或者是客戶。
購物車,商品詳情,支付等模塊分別提供單獨的rest api接口,給上層訪問。所有的請求前面有統一的入口,api網關負責路由,認證,性能分析等功能
當然,微服務也有一定的缺陷,比如說每個服務(每個應用) 如果都有一個數據庫的話,那么如何維持數據庫事務。再比如說,服務之間的調用可能會由于網絡的原因變得不可達,那么代碼中要額外增加請求失敗的代碼。運維維護成本升高,開發時需注意模塊間耦合。
上面這個架構其實很容易看出,api網關很容易成為性能瓶頸,而且也存在單點。api層面耦合太高。
架構調整
引入Kong做api網關
微服務上層會有許多消費者(網站、移動端、甚至物聯網設備),而這些消費者可能會依賴一些共同的基礎服務,kong可以作為API網關提供一些插件來實現這些基礎功能,比如登錄,權限認證等。
Kong簡介
Kong是Mashape開源的一款API網關,起初是用來管理 Mashape 公司15000個微服務的,后來在2015年開源,現在已經在很多創業公司、大型企業和政府機構中廣泛使用。基于Lua和Cassandra或PostgreSQL,支持分布式操作,有很強的可移植性和可擴展性。可以在任何一種基礎設施上運行,作為應用和API之間的中間層,加上眾多功能強大的插件,可以實現認證授權、訪問控制等功能。并且提供易于使用的RESTful API來操作和配置系統。
Kong可以說是API的得力助手。對需要從事API管理的廣大開發員來說,它是最出色的工具之一。多年來,Kong一直在支持優秀的開發項目,比如Mashape(世界上規模最大的API市場)。最棒的是,Kong得到了強大的Nginx的支持。MaxCDN也將Mashape與其無限惡意軟件掃描器(Infinite Malware Scanner)結合使用,用來檢測其內容分發網絡(CDN)上的惡意軟件。
https://github.com/Mashape/kong?start 7k+
Kong的主要功能
Kong可靈活擴展:你可以通過增加更多Kong Server機器對Kong服務進行水平擴展,通過前置的負載均衡器向這些機器分發請求。這樣就可以支持更多流量,同時確保網絡延遲很短。根據文檔描述,兩個Cassandra節點就足以支撐絕大多數情況,但如果網絡非常擁擠,可以考慮適當增加更多節點。
Kong可在任何地方運行:它可以部署在單個或多個數據中心環境的私有云或公有云上。它還支持大多數流行的操作系統,比如Linux、Mac和Windows。Kong包括許多實用技巧,以便針對大多數現代平臺完成安裝和配置工作。
Kong具有模塊性:它可以與新的插件協同運行,擴展基本功能。可將你的API與許多不同的插件整合起來,這些插件在API請求響應循環的生命周期中被執行。插件使用Lua編寫,而且Kong還有如下幾個基礎功能:HTTP基本認證、密鑰認證、CORS( Cross-origin Resource Sharing,跨域資源共享)、TCP、UDP、文件日志、API請求限流、請求轉發以及nginx監控。以增強安全、分析、驗證、日志及/或監測機制。最好的例子之一就是Nginx Plus插件(https://getkong.org/plugins/nginx-plus-monitoring/),該插件提供了服務器實時監測機制,以獲得關于負載和請求的度量指標和統計數字。
請求工作流
為了更好地理解系統,這是使用Kong的API的典型請求工作流:
Kong提供認證,限流,負載均衡等功能
哪些企業在用KONG
- Mashapoe Marketplace
- Buzzlogix
- Gengo
- IBM
- Intel
- OpenDNS
- 餓了么
它是如何工作的?
Kong可與兩種不同的組件協同工作:
- Nginx:Kong使用經過修改的Nginx web服務器作為代理服務器,該服務器負責處理API請求。
- Apache Cassandra或者PostgreSQL:這用作數據存儲(Datastore)服務器,負載存儲來自Kong操作的數據。
Kong 當前最大支持 PostgreSQL 9.4+ 版本和 Cassandra 2.2.x 版本2個數據庫
Kong VS 其他API網關
- 開源:沒有黑盒。 對于企業或免費使用,Kong是完全開源的。
- 基于Nginx:Kong嵌入在Nginx并受益于其令人驚嘆的代理性能。
- 可定制:編寫插件以涵蓋您的所有架構用例。
- 數據所有權:Kong及其基礎數據存儲在您的服務器上運行。
- 容易擴展:所有孔節點是無狀態的。 在你的集群中產生新的節點是很容易的。
- 集成:許多插件與微服務世界中的流行的第三方服務集成。
kong性能數據
官方在AWS上進行性能測試, Kong運行在三個m3.medium EC2實例上; 一個用于部署Kong Server,一個用于Cassandra做數據存儲,另一個用于上游API。 在將上游API的upstream_url添加到Kong中之后,我們測試從1到2000個并發連接的測試。
兩分鐘以上的117,185個請求,平均延遲為10ms,每秒976個請求,或者每天約84,373,200個請求通過Kong返回,只有一個超時。
Kong使用方式
- 一種應用通過攜帶Host頭部來增加API應用。
- 另一種是通過不同的uri來提供API應用。
兩種方式對OpenResty或者nginx的使用方式都是基于動態增加upstream以及對upstream的DNS resolver來實現。
Kong部署
當前使用最新版本kong 0.9,我們部署在Centos 6.5 x64位系統上
$ wget https://bintray.com/mashape/kong-rpm-el6-0.9.x/rpm -O bintray-mashape-kong-rpm-el6-0.9.x.repo $ mv bintray-mashape-kong-rpm-el6-0.9.x.repo /etc/yum.repos.d/ $ yum install kong |
啟動kong
$ kong start -c <path_to_config> |
檢查kong是不是正常啟動了,默認不修改配置文件的情況下會報連接不上PostgreSQL,這里先忽略,繼續裝cassandra
正常啟動的話會輸出:[OK] Started
kong的監聽端口:
8000: API請求的代理層。 8001: restful的配置管理API。 8443: 代理HTTPS 7946: 用于和其他Kong節點通訊,支持TCP/UDP流量 7373: 用于本地集群代理通訊 |
停止kong
$ kong stop |
重新加載kong
$ kong reload |
cassandra部署
java環境部署
這里就不演示安裝了,yum也行,綠色版解壓也行。java1.7 或者1.8都可以,注意cassandra3.0必須要jdk1.8版本才行。這里我們由于kong的支持版本是2.x,這里介紹2.x的安裝。
yum源添加
$ vim /etc/yum.repos.d/datastax.repo [datastax] name = DataStax Repo for Apache Cassandra baseurl = http://rpm.datastax.com/community enabled = 1 gpgcheck = 0 $ yum search dsc 已加載插件:fastestmirror Loading mirror speeds from cached hostfile ========================================================= N/S Matched: dsc ========================================================== dsc1.1.noarch : Meta RPM for installation of the DataStax DSC platform dsc12.noarch : Meta RPM for installation of the DataStax DSC platform dsc20.noarch : Meta RPM for installation of the DataStax DSC platform dsc21.noarch : Meta RPM for installation of the DataStax DSC platform dsc22.noarch : Meta RPM for installation of the DataStax DSC platform dsc30.noarch : Meta RPM for installation of the DataStax DSC platform 雖然有3.0,但是目前kong只支持2.2.x ,這里我就安裝2.2版本 $ yum install dsc22 |
啟動cassandra
$ /etc/init.d/cassandra start Starting Cassandra: OK |
python2.7部署
cqlsh是cassandra的客戶端查詢工具
cqlsh客戶的工具需要python2.7支持,centos6.x默認是python2.6版本,這里我新安裝下python2.7
首先安裝 python 工具需要的額外軟件包 SSL, bz2, zlib
yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget |
源碼安裝Python 2.7.x,當然你也可以偷懶yum安裝,添加相應的yum就可以
$ wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz $ xz -d Python-2.7.8.tar.xz $ tar -xvf Python-2.7.8.tar $ cd Python-2.7.8 $ ./configure --prefix=/usr/local $ make $ make altinstall |
檢查 Python 版本并修復yum
$ python2.7 -V Python 2.7.8 $ mv /usr/bin/python /usr/bin/python2.6.6 $ ln -s /usr/local/bin/python2.7 /usr/bin/python $ which yum /usr/bin/yum #修改 yum中的python 將第一行 #!/usr/bin/python 改為 #!/usr/bin/python2.6 |
安裝pip
$curl https://bootstrap.pypa.io/get-pip.py | python2.7 - |
驗證cassadnra
執行cqlsh客戶端驗證cassadnra安裝
$ cqlsh Traceback (most recent call last): File "/usr/bin/cqlsh.py", line 160, in <module> from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling ImportError: No module named cqlshlib $ pip install cqlshlib $ cqlsh Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 2.2.8 | CQL spec 3.3.1 | Native protocol v4] Use HELP for help. cqlsh> create schema testschema ... with replication = {'class':'SimpleStrategy', 'replication_factor':1}; cqlsh> describe keyspaces; system testschema system_traces cqlsh> use testschema; cqlsh:testschema> create table user ( ... user_id varchar primary key, ... first varchar, ... last varchar, ... age int ... ); ... user_id varchar primary key, ... first varchar, ... last varchar, ... age int ... ); cqlsh:testschema> cqlsh:testschema> insert into user (user_id, first, last, age) values ('rfroncois', 'ronn', 'francois', 20); cqlsh:testschema> select * from user; user_id | age | first | last -----------+-----+-------+---------- rfroncois | 20 | ronn | francois cqlsh:testschema> |
Kong 配置
將數據庫改為cassandra
$ cat /usr/local/kong/kong.conf ssl_cert_key = /usr/local/kong/ssl/kong-default.key ssl_cert_csr_default = /usr/local/kong/ssl/kong-default.csr nginx_acc_logs = /usr/local/kong/logs/access.log nginx_pid = /usr/local/kong/pids/nginx.pid nginx_conf = /usr/local/kong/nginx.conf anonymous_reports = true lua_code_cache = on serf_path = serf nginx_kong_conf = /usr/local/kong/nginx-kong.conf nginx_err_logs = /usr/local/kong/logs/error.log log_level = notice proxy_listen = 0.0.0.0:8000 ssl_cert = /usr/local/kong/ssl/kong-default.crt cassandra_port = 9042 lua_ssl_verify_depth = 1 admin_listen = 0.0.0.0:8001 ssl_cert_key_default = /usr/local/kong/ssl/kong-default.key ssl_cert_default = /usr/local/kong/ssl/kong-default.crt serf_log = /usr/local/kong/logs/serf.log dnsmasq_pid = /usr/local/kong/pids/dnsmasq.pid proxy_listen_ssl = 0.0.0.0:8443 nginx_worker_processes = auto cassandra_contact_points = 127.0.0.1 proxy_ip = 0.0.0.0 cluster_profile = wan pg_ssl = false proxy_ssl_port = 8443 cassandra_timeout = 5000 pg_database = kong lua_package_path = ?/init.lua;./kong/?.lua cassandra_consistency = ONE proxy_port = 8000 serf_node_id = /usr/local/kong/serf/serf.id proxy_ssl_ip = 0.0.0.0 admin_ip = 0.0.0.0 kong_conf = /usr/local/kong/kong.conf admin_port = 8001 prefix = /usr/local/kong cluster_listen = 0.0.0.0:7946 cassandra_username = kong pg_host = 127.0.0.1 pg_port = 5432 cluster_ttl_on_failure = 3600 dnsmasq_port = 8053 nginx_daemon = on serf_pid = /usr/local/kong/pids/serf.pid cassandra_repl_strategy = SimpleStrategy dnsmasq = true nginx_optimizations = true pg_user = kong pg_ssl_verify = false cassandra_data_centers = dc1:2,dc2:3 cassandra_ssl_verify = false ssl = true database = cassandra cassandra_repl_factor = 1 serf_event = /usr/local/kong/serf/serf_event.sh cassandra_keyspace = kong mem_cache_size = 128m cassandra_ssl = false cluster_listen_rpc = 127.0.0.1:7373 |
重啟kong
$ kong restart |
Kong使用
新增API
添加你的具體業務 API 服務到 Kong 中,Kong 通過 RESTful API 來管理具體的Kong 實例。具體請求如下,Kong 管理的 API 在8001 端口。請求配置如下:
$ curl -i -X POST \ --url http://localhost:8001/apis/ \ --data 'name=api-rest' \ --data 'upstream_url=http://api.yonghuivip.com/api/' \ --data 'request_host=api.yonghuivip.com' |
當收到一個請求,Kong會檢查它,并嘗試將其路由到正確的API。 Kong支持2種路由機制
- 請求的主機頭中包含的DNS值。
- 請求的路徑(URI)。
$ curl -i -X POST \ --url http://localhost:8001/apis/ \ -d 'name=mockbin' \ -d 'upstream_url=http://api.yonghuivip/' \ -d 'request_host=api.yonghuivip' \ -d 'request_path=/status' ``` 這里首先看下DNS方式 |
$ curl -i -X GET \
–url?http://localhost:8000/?\
–header ‘Host: api.yonghuivip’
當從瀏覽器執行請求時,您可能無法設置主機頭。 因此,Kong還會檢查一個名為X-Host-Override的頭的請求,并像Host頭一樣設置它: |
$ curl -i -X GET \
–url?http://localhost:8000/?\
–header ‘X-Host-Override: api.yonghuivip.com’
URI方式 |
$ curl -i -X GET \
–url?http://localhost:8000/status/200
> 通過kong代理請求的url 是 KONG_URL:PROXY_PORT/status/200 (http://localhost:8000/status/200) > 我們配置的upstream_url 是 http://api.54im.com/ > 那我們最后的實際請求地址為 http://api.54im.com/status/200. 使用"strip_request_path"屬性 > 通過在API上啟用strip_request_path屬性,請求將被代理,而request_path屬性不包含在上游請求中。 讓我們通過向管理API發出請求來啟用此選項: |
$ curl -i -X PATCH \
–url?http://localhost:8001/apis/api?\
-d ‘strip_request_path=true’ \
-d ‘request_path=/api’
可以看下使用strip_request_path后,請求路徑的變化 request_path | strip_request_path | incoming request |upstream request ---|---|---|--- /api-rest| false | /some_path | not proxied /api-rest | false | /api | /api /api-rest | false | /api/some_path | /api/some_path /api-rest | true | /some_path | not proxied /api-rest | true | /api | / /api-rest | true | /api/some_path | /some_path 我們這邊就使用 Request URI方式測試 KONG 路由到業務的 API 使用: path URI 的方式請求 + 設置 strip_request_path 為 true 我現在拿這個api實驗下 > http://api.54im.com/api/member/login?xxx=xxx&xxx=xxx 新增API |
$ curl -i -X POST \
–url?http://localhost:8001/apis/?\
-d ‘name=api’ \
-d ‘upstream_url=http://api.54im.com/‘ \
-d ‘request_host=api.54im.com’ \
-d ‘strip_request_path=true’ \
-d ‘request_path=/api’
返回 |
{
“upstream_url”: “http://api.54im.com/“,
“strip_request_path”: true,
“request_path”: “/api”,
“id”: “be9bb14d-f665-4d53-866c-1cd6e77bfc8b”,
“created_at”: 1476347080000,
“preserve_host”: false,
“name”: “api-rest”,
“request_host”: “api.54im.com”
}
我們來請求通過kong代理的業務的api |
curl -i -X GET –url “http://localhost:8000/api/api/member/login?xxx=xxx&xxx=xxx“
> 這里說明下這個結構 >http://localhost:8000/api/api/member/login? >http://localhost:8000/ 是kong提供的API代理層接口,提供給外界,當然你上層還是可以用負載均衡 >api 是上面新增接口中的 request_path >api/member/login? 是我們業務具體的接口了 業務返回 ```{ "code": 0, "data": { "xxx": "xxx", "expires_in": "7200", "refresh_token": "xxx", "xxx": "xxx", "uid": "21000" }, "message": "OK", "now": 1476348465224 } |
業務nginx日志也可以看到該請求
10.10.1.2 - - [13/Oct/2016:16:33:10 +0800] "GET /api/member/login?v=2%2e0%2e1 HTTP/1.0" 500 184 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2" 127.0.0.1 0.005 - |
Kong 插件管理
官網目前有這幾類插件
Authentication 認證插件
- basic-authentication
- Key Authentication
- OAuth 2.0 Authentication
- HMAC Authentication
- JWT
- LDAP Authentication
Security 安全插件
- ACL
- CORS
- Dynamic SSL
- IP Restriction
- Bot Detection
Traffic Control 流控插件
- Rate Limiting
- Response Rate Limiting
- Request Size Limiting
Analytics & Monitoring 分析監控插件
- Galileo
- Datadog
- Runscope
Transformations 轉換插件
- Request Transformer
- Response Transformer
- Correlation ID
Logging 日志插件
- TCP
- UDP
- HTTP
- File
- Syslog
- StatsD
- Loggly
Key Authentication 演示
新增一個key-auth插件給api-rest這個api
[root@10-19-63-216:~]$ curl -i -X POST \ > --url http://localhost:8001/apis/api/plugins/ \ > --data 'name=key-auth' HTTP/1.1 201 Created Date: Thu, 13 Oct 2016 09:01:55 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Access-Control-Allow-Origin: * Server: kong/0.9.3 |
返回
{ "api_id": "be9bb14d-f665-4d53-866c-1cd6e77bfc8b", "id": "9018a2c9-f532-4ea0-96aa-a7165181d8fe", "created_at": 1476349315000, "enabled": true, "name": "key-auth", "config": { "key_names": [ "apikey" ], "hide_credentials": false } } |
我們同樣請求之前那個接口看下
$ curl -i -X GET --url "http://localhost:8000/api/api/member/login?xxx=xxx&xxx=xxx" HTTP/1.1 401 Unauthorized Date: Thu, 13 Oct 2016 09:03:17 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive WWW-Authenticate: Key realm="kong" Server: kong/0.9.3 {"message":"No API key found in headers or querystring"} |
那現在要認證了,我該如何訪問接口呢,別急,繼續往下
添加Consumers消費者
現在已經配置了 key-auth 插件,還需要添加 consumer 到 API,才能繼續通過 Kong 代理請求。Consumer 在調用API時,與單個用戶請求關聯,能被用來跟蹤、訪問管理等等。
建立一個用戶名稱為Ivon 的 consumer,下面請求命令成功之后,Kong 還會為Jason 用戶建立一個唯一的 custom_id。
$ curl -i -X POST \ --url http://localhost:8001/consumers/ \ --data "username=Jason" |
返回
{ "username": "Ivon", "created_at": 1476349684000, "id": "4d6b3281-d26e-416b-b8fc-8185422386d5" } |
為消費者Ivon提供密鑰憑據
curl -i -X POST \ --url http://localhost:8001/consumers/Ivon/key-auth/ \ --data 'key=18b4ccb1a20076813c208d8e8a281a94' |
如果不指定key參數,kong會為你生成一個,推薦不指定。
返回
{ "key": "18b4ccb1a20076813c208d8e8a281a94", "consumer_id": "4d6b3281-d26e-416b-b8fc-8185422386d5", "created_at": 1476350157000, "id": "9bd5165b-a798-4ff3-91d9-398216bbcb55" } |
再試著請求下之前的業務接口
$ curl -i -X GET --url "http://localhost:8000/api/api/member/login?xxx=xxx&xxx=xxx" HTTP/1.1 200 OK Date: Thu, 13 Oct 2016 09:20:14 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 314 Connection: keep-alive Server: Tengine X-Kong-Upstream-Latency: 651 X-Kong-Proxy-Latency: 0 Via: kong/0.9.3 {"code":0,"data":{"access_token":"xxx","expires_in":"7200","refresh_token":"c57300c0-9301-4b2c-b7f8-32b9a8cba9c5","token":"xxx","uid":"21000"},"message":"OK","now":1476350414858} |
apikey 必須寫在 url 的第一個參數,否則會報“No API Key found in headers, body or querystring”的錯誤。
Basic Authentication 插件演示
- 瀏覽器彈框需要輸入用戶名密碼才能訪問
這里新增一個api
curl -i -X POST \ --url http://localhost:8001/apis/ \ -d 'name=activity' \ -d 'upstream_url=http://activity.54im.com/' \ -d 'request_host=activity.54im.com' \ -d 'strip_request_path=true' \ -d 'request_path=/activity' |
請求下
curl -i -X GET --url "http://localhost:8000/activity/" |
返回拼團的html
給activity-hub這個API增加賬戶密碼驗證
$ curl -X POST http://localhost:8001/apis/activity/plugins \ --data "name=basic-auth" \ --data "config.hide_credentials=true" |
返回
{"api_id":"5e40fba2-bc19-4a11-9cdb-568922e9d7d8","id":"27ac00a6-dbf0-4b6b-85bb-88db1f3ff2d6","created_at":1476352721000,"enabled":true,"name":"basic-auth","config":{"hide_credentials":true}} |
給Ivon消費者增加認證插件的賬戶密碼
$ curl -X POST http://localhost:8001/consumers/Ivon/basic-auth \ > --data "username=ivon" \ > --data "password=123456" 返回 {"password":"d1a3724559dc3d79c8bfdda72ebcd29728cfc7c5","consumer_id":"4d6b3281-d26e-416b-b8fc-8185422386d5","id":"e966af78-16e7-44f0-84e9-3d1b145a5cfc","username":"ivon","created_at":1476352923000} |
再請求下業務接口
$ curl -i -X GET --url "http://localhost:8000/activity/" HTTP/1.1 401 Unauthorized Date: Thu, 13 Oct 2016 10:00:12 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive WWW-Authenticate: Basic realm="kong" Server: kong/0.9.3 {"message":"Unauthorized"} |
返回沒有認證
加上賬戶密碼后訪問API
curl -u ivon:123456 -i -X GET --url "http://localhost:8000/activity/" 可以正常訪問之前的html頁面 |
IP Restriction 插件演示
IP 限制,黑名單、白名單。支持單IP、多IP、IP區間等配置。
$ curl -X POST http://localhost:8001/apis/activity/plugins \ --data "name=ip-restriction" \ --data 'config.blacklist=192.168.20.156' |
Rate Limiting 插件演示
以下是限制一分鐘內只允許同一個IP 有5個請求,一小時內10000個請求
$ curl -X POST http://localhost:8001/apis/activity/plugins \ --data "name=rate-limiting" \ --data "config.minute=5" \ --data "config.hour=10000" ``` ### Request Size Limiting 插件演示 > 防止 DOS 攻擊,限制訪問的請求body 大于多megabytes 的請求。 |
$ curl -X POST?http://localhost:8001/apis/activity/plugins?\
–data “name=request-size-limiting” \
–data “config.allowed_payload_size=128”
# Kong 管理api #### 查看Kong 節點信息 |
curl -X GET?http://localhost:8001/
返回 |
{
“hostname”: “”,
“lua_version”: “LuaJIT 2.1.0-alpha”,
“plugins”: {
“available_on_server”: [
…
],
“enabled_in_cluster”: [
…
]
},
“configuration” : {
…
},
“tagline”: “Welcome to Kong”,
“version”: “0.6.0”
}
#### 請求狀態統計 請求狀態統計,其實就是nginx的status模塊 |
curl -X GET?http://localhost:8001/status
返回 |
{
“server”: {
“total_requests”: 3203,
“connections_active”: 1,
“connections_accepted”: 1,
“connections_handled”: 1,
“connections_reading”: 0,
“connections_writing”: 1,
“connections_waiting”: 0
},
“database”: {
“apis”: 2,
“consumers”: 0,
“plugins”: 2,
“nodes”: 1,
…
}
}
#### Kong集群狀態 |
curl -X GET?http://localhost:8001/status
#### 檢索API |
curl -X GET?http://localhost:8001/apis/{name?or id}
#### 查看API列表 |
curl -X GET?http://localhost:8001/apis
#### 更新API |
curl -X PATCH?http://localhost:8001/apis/{name?or id}
#### 刪除API |
curl -X DELETE?http://localhost:8001/apis/{name?or id}
#### 創建消費者 |
curl -X GET?http://localhost:8001/consumers/{username?or id}
#### 增加插件 |
curl -X POST?http://localhost:8001/{name?or id}/plugins
```
Here is a list of third-party?tools?maintained by the community:
- Ansible role for Kong on Ubuntu
- Biplane: declarative configuration in Crystal
- Bonobo: key management (with Mashery migration scripts)
- Chef cookbook
- Django Kong Admin: Admin UI in Python
- Jungle: Admin UI in JavaScript
- Kong Dashboard: Admin UI in JavaScript
- Kong for CanopyCloud
- Kong image waiting for Cassandra
- Kong image for Tutum
- Kong-UI: Admin UI in JavaScript
- Konga: CLI Admin tool in JavaScript
- Kongfig: Declarative configuration in JavaScript
- Kongfig on Puppet Forge
- Puppet recipe
- Puppet module on Puppet Forge
- Python-Kong: Admin client library for Python
- .NET-Kong: Admin client library for .NET
參考文檔
- https://www.sdk.cn/news/
- https://getkong.org/about/
- http://www.jianshu.com/p/89dc0d24823d
- http://blog.100dos.com/2016/07/25/the-installation-and-configuration-of-kong/
- https://getkong.org/docs/0.9.x/admin-api/#create-consume
- http://blog.csdn.net/pzxwhc/article/details/49873623
- http://weibo.com/ttarticle/p/show?id=2309404009535101606529
- http://blog.yichicloud.com/%E5%BE%AE%E6%9C%8D%E5%8A%A1/kong-introduction-with-setup-demo
- http://www.infoq.com/cn/news/2015/04/kong
- https://github.com/Mashape/kong/blob/master/README.md
- https://baioradba.wordpress.com/2014/06/13/how-to-install-cassandra-on-centos-6-5/