日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

centos-install-kong-cassandra

發(fā)布時間:2023/12/18 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos-install-kong-cassandra 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)自:http://blog.54im.com/2016/12/15/centos-install-kong-cassandra/#


前置閱讀

對于一些傳統(tǒng)的大型項(xiàng)目,傳統(tǒng)的方式會有一些缺陷,比如說新人熟悉系統(tǒng)成本高(因?yàn)檎麄€系統(tǒng)作為一個整體,彼此會有一定的牽連),項(xiàng)目重啟時間長,重構(gòu)困難(對于一個新技術(shù)的引入,可能需要對整個項(xiàng)目推到重來),不易于更換新的技術(shù),并且整個項(xiàng)目會慢慢變成巨無霸。

近年來微服務(wù)受到越來越多國內(nèi)企業(yè)的青睞。當(dāng)企業(yè)現(xiàn)有系統(tǒng)的復(fù)雜度、維護(hù)和擴(kuò)展成本成為業(yè)務(wù)發(fā)展瓶頸時,微服務(wù)可以幫助企業(yè)拆分、解耦現(xiàn)有的系統(tǒng),從而提高系統(tǒng)的可維護(hù)和可擴(kuò)展性。Airbnb、Dropbox、Twitter等互聯(lián)網(wǎng)公司,在使用微服務(wù)架構(gòu)之后,功能發(fā)布周期減少了75%,微服務(wù)的核心在于根據(jù)業(yè)務(wù)和具體粒度劃分API,那么如何管理API就顯得尤為重要。

拿日常的電商購物舉例,一個服務(wù)實(shí)現(xiàn)一個不同的特性或者功能。每一個獨(dú)立的微服務(wù)都是一個小型應(yīng)用。一些微服務(wù)可能會暴露一些api 給其他的一些微服務(wù)或者是客戶。

購物車,商品詳情,支付等模塊分別提供單獨(dú)的rest api接口,給上層訪問。所有的請求前面有統(tǒng)一的入口,api網(wǎng)關(guān)負(fù)責(zé)路由,認(rèn)證,性能分析等功能

當(dāng)然,微服務(wù)也有一定的缺陷,比如說每個服務(wù)(每個應(yīng)用) 如果都有一個數(shù)據(jù)庫的話,那么如何維持?jǐn)?shù)據(jù)庫事務(wù)。再比如說,服務(wù)之間的調(diào)用可能會由于網(wǎng)絡(luò)的原因變得不可達(dá),那么代碼中要額外增加請求失敗的代碼。運(yùn)維維護(hù)成本升高,開發(fā)時需注意模塊間耦合。

上面這個架構(gòu)其實(shí)很容易看出,api網(wǎng)關(guān)很容易成為性能瓶頸,而且也存在單點(diǎn)。api層面耦合太高。

架構(gòu)調(diào)整

引入Kong做api網(wǎng)關(guān)

微服務(wù)上層會有許多消費(fèi)者(網(wǎng)站、移動端、甚至物聯(lián)網(wǎng)設(shè)備),而這些消費(fèi)者可能會依賴一些共同的基礎(chǔ)服務(wù),kong可以作為API網(wǎng)關(guān)提供一些插件來實(shí)現(xiàn)這些基礎(chǔ)功能,比如登錄,權(quán)限認(rèn)證等。

Kong簡介

Kong是Mashape開源的一款A(yù)PI網(wǎng)關(guān),起初是用來管理 Mashape 公司15000個微服務(wù)的,后來在2015年開源,現(xiàn)在已經(jīng)在很多創(chuàng)業(yè)公司、大型企業(yè)和政府機(jī)構(gòu)中廣泛使用。基于Lua和Cassandra或PostgreSQL,支持分布式操作,有很強(qiáng)的可移植性和可擴(kuò)展性。可以在任何一種基礎(chǔ)設(shè)施上運(yùn)行,作為應(yīng)用和API之間的中間層,加上眾多功能強(qiáng)大的插件,可以實(shí)現(xiàn)認(rèn)證授權(quán)、訪問控制等功能。并且提供易于使用的RESTful API來操作和配置系統(tǒng)。

Kong可以說是API的得力助手。對需要從事API管理的廣大開發(fā)員來說,它是最出色的工具之一。多年來,Kong一直在支持優(yōu)秀的開發(fā)項(xiàng)目,比如Mashape(世界上規(guī)模最大的API市場)。最棒的是,Kong得到了強(qiáng)大的Nginx的支持。MaxCDN也將Mashape與其無限惡意軟件掃描器(Infinite Malware Scanner)結(jié)合使用,用來檢測其內(nèi)容分發(fā)網(wǎng)絡(luò)(CDN)上的惡意軟件。

https://github.com/Mashape/kong?start 7k+

Kong的主要功能

  • Kong可靈活擴(kuò)展:你可以通過增加更多Kong Server機(jī)器對Kong服務(wù)進(jìn)行水平擴(kuò)展,通過前置的負(fù)載均衡器向這些機(jī)器分發(fā)請求。這樣就可以支持更多流量,同時確保網(wǎng)絡(luò)延遲很短。根據(jù)文檔描述,兩個Cassandra節(jié)點(diǎn)就足以支撐絕大多數(shù)情況,但如果網(wǎng)絡(luò)非常擁擠,可以考慮適當(dāng)增加更多節(jié)點(diǎn)。

  • Kong可在任何地方運(yùn)行:它可以部署在單個或多個數(shù)據(jù)中心環(huán)境的私有云或公有云上。它還支持大多數(shù)流行的操作系統(tǒng),比如Linux、Mac和Windows。Kong包括許多實(shí)用技巧,以便針對大多數(shù)現(xiàn)代平臺完成安裝和配置工作。

  • Kong具有模塊性:它可以與新的插件協(xié)同運(yùn)行,擴(kuò)展基本功能。可將你的API與許多不同的插件整合起來,這些插件在API請求響應(yīng)循環(huán)的生命周期中被執(zhí)行。插件使用Lua編寫,而且Kong還有如下幾個基礎(chǔ)功能:HTTP基本認(rèn)證、密鑰認(rèn)證、CORS( Cross-origin Resource Sharing,跨域資源共享)、TCP、UDP、文件日志、API請求限流、請求轉(zhuǎn)發(fā)以及nginx監(jiān)控。以增強(qiáng)安全、分析、驗(yàn)證、日志及/或監(jiān)測機(jī)制。最好的例子之一就是Nginx Plus插件(https://getkong.org/plugins/nginx-plus-monitoring/),該插件提供了服務(wù)器實(shí)時監(jiān)測機(jī)制,以獲得關(guān)于負(fù)載和請求的度量指標(biāo)和統(tǒng)計數(shù)字。

請求工作流

為了更好地理解系統(tǒng),這是使用Kong的API的典型請求工作流:

Kong提供認(rèn)證,限流,負(fù)載均衡等功能

哪些企業(yè)在用KONG

  • Mashapoe Marketplace
  • Buzzlogix
  • Gengo
  • IBM
  • Intel
  • OpenDNS
  • 餓了么

它是如何工作的?

Kong可與兩種不同的組件協(xié)同工作:

  • Nginx:Kong使用經(jīng)過修改的Nginx web服務(wù)器作為代理服務(wù)器,該服務(wù)器負(fù)責(zé)處理API請求。
  • Apache Cassandra或者PostgreSQL:這用作數(shù)據(jù)存儲(Datastore)服務(wù)器,負(fù)載存儲來自Kong操作的數(shù)據(jù)。

    Kong 當(dāng)前最大支持 PostgreSQL 9.4+ 版本和 Cassandra 2.2.x 版本2個數(shù)據(jù)庫

Kong VS 其他API網(wǎng)關(guān)

  • 開源:沒有黑盒。 對于企業(yè)或免費(fèi)使用,Kong是完全開源的。
  • 基于Nginx:Kong嵌入在Nginx并受益于其令人驚嘆的代理性能。
  • 可定制:編寫插件以涵蓋您的所有架構(gòu)用例。
  • 數(shù)據(jù)所有權(quán):Kong及其基礎(chǔ)數(shù)據(jù)存儲在您的服務(wù)器上運(yùn)行。
  • 容易擴(kuò)展:所有孔節(jié)點(diǎn)是無狀態(tài)的。 在你的集群中產(chǎn)生新的節(jié)點(diǎn)是很容易的。
  • 集成:許多插件與微服務(wù)世界中的流行的第三方服務(wù)集成。

kong性能數(shù)據(jù)

官方在AWS上進(jìn)行性能測試, Kong運(yùn)行在三個m3.medium EC2實(shí)例上; 一個用于部署Kong Server,一個用于Cassandra做數(shù)據(jù)存儲,另一個用于上游API。 在將上游API的upstream_url添加到Kong中之后,我們測試從1到2000個并發(fā)連接的測試。

兩分鐘以上的117,185個請求,平均延遲為10ms,每秒976個請求,或者每天約84,373,200個請求通過Kong返回,只有一個超時。

Kong使用方式

  • 一種應(yīng)用通過攜帶Host頭部來增加API應(yīng)用。
  • 另一種是通過不同的uri來提供API應(yīng)用。

兩種方式對OpenResty或者nginx的使用方式都是基于動態(tài)增加upstream以及對upstream的DNS resolver來實(shí)現(xiàn)。

Kong部署

當(dāng)前使用最新版本kong 0.9,我們部署在Centos 6.5 x64位系統(tǒng)上

$ 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是不是正常啟動了,默認(rèn)不修改配置文件的情況下會報連接不上PostgreSQL,這里先忽略,繼續(xù)裝cassandra

正常啟動的話會輸出:[OK] Started

kong的監(jiān)聽端口:

8000: API請求的代理層。8001: restful的配置管理API。8443: 代理HTTPS7946: 用于和其他Kong節(jié)點(diǎn)通訊,支持TCP/UDP流量7373: 用于本地集群代理通訊

停止kong

$ kong stop

重新加載kong

$ kong reload

cassandra部署

java環(huán)境部署

這里就不演示安裝了,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 Cassandrabaseurl = http://rpm.datastax.com/communityenabled = 1gpgcheck = 0$ yum search dsc已加載插件:fastestmirrorLoading mirror speeds from cached hostfile========================================================= N/S Matched: dsc ==========================================================dsc1.1.noarch : Meta RPM for installation of the DataStax DSC platformdsc12.noarch : Meta RPM for installation of the DataStax DSC platformdsc20.noarch : Meta RPM for installation of the DataStax DSC platformdsc21.noarch : Meta RPM for installation of the DataStax DSC platformdsc22.noarch : Meta RPM for installation of the DataStax DSC platformdsc30.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 startStarting Cassandra: OK

python2.7部署

cqlsh是cassandra的客戶端查詢工具
cqlsh客戶的工具需要python2.7支持,centos6.x默認(rèn)是python2.6版本,這里我新安裝下python2.7

首先安裝 python 工具需要的額外軟件包 SSL, bz2, zlib

yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget

源碼安裝Python 2.7.x,當(dāng)然你也可以偷懶yum安裝,添加相應(yīng)的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 版本并修復(fù)yum

$ python2.7 -VPython 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 -

驗(yàn)證cassadnra

執(zhí)行cqlsh客戶端驗(yàn)證cassadnra安裝

$ cqlshTraceback (most recent call last):File "/usr/bin/cqlsh.py", line 160, in <module>from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandlingImportError: No module named cqlshlib$ pip install cqlshlib$ cqlshConnected 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_tracescqlsh> 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 | francoiscqlsh:testschema>

Kong 配置

將數(shù)據(jù)庫改為cassandra

$ cat /usr/local/kong/kong.confssl_cert_key = /usr/local/kong/ssl/kong-default.keyssl_cert_csr_default = /usr/local/kong/ssl/kong-default.csrnginx_acc_logs = /usr/local/kong/logs/access.lognginx_pid = /usr/local/kong/pids/nginx.pidnginx_conf = /usr/local/kong/nginx.confanonymous_reports = truelua_code_cache = onserf_path = serfnginx_kong_conf = /usr/local/kong/nginx-kong.confnginx_err_logs = /usr/local/kong/logs/error.loglog_level = noticeproxy_listen = 0.0.0.0:8000ssl_cert = /usr/local/kong/ssl/kong-default.crtcassandra_port = 9042lua_ssl_verify_depth = 1admin_listen = 0.0.0.0:8001ssl_cert_key_default = /usr/local/kong/ssl/kong-default.keyssl_cert_default = /usr/local/kong/ssl/kong-default.crtserf_log = /usr/local/kong/logs/serf.logdnsmasq_pid = /usr/local/kong/pids/dnsmasq.pidproxy_listen_ssl = 0.0.0.0:8443nginx_worker_processes = autocassandra_contact_points = 127.0.0.1proxy_ip = 0.0.0.0cluster_profile = wanpg_ssl = falseproxy_ssl_port = 8443cassandra_timeout = 5000pg_database = konglua_package_path = ?/init.lua;./kong/?.luacassandra_consistency = ONEproxy_port = 8000serf_node_id = /usr/local/kong/serf/serf.idproxy_ssl_ip = 0.0.0.0admin_ip = 0.0.0.0kong_conf = /usr/local/kong/kong.confadmin_port = 8001prefix = /usr/local/kongcluster_listen = 0.0.0.0:7946cassandra_username = kongpg_host = 127.0.0.1pg_port = 5432cluster_ttl_on_failure = 3600dnsmasq_port = 8053nginx_daemon = onserf_pid = /usr/local/kong/pids/serf.pidcassandra_repl_strategy = SimpleStrategydnsmasq = truenginx_optimizations = truepg_user = kongpg_ssl_verify = falsecassandra_data_centers = dc1:2,dc2:3cassandra_ssl_verify = falsessl = truedatabase = cassandracassandra_repl_factor = 1serf_event = /usr/local/kong/serf/serf_event.shcassandra_keyspace = kongmem_cache_size = 128mcassandra_ssl = falsecluster_listen_rpc = 127.0.0.1:7373

重啟kong

$ kong restart

Kong使用

新增API

添加你的具體業(yè)務(wù) API 服務(wù)到 Kong 中,Kong 通過 RESTful API 來管理具體的Kong 實(shí)例。具體請求如下,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'

當(dāng)收到一個請求,Kong會檢查它,并嘗試將其路由到正確的API。 Kong支持2種路由機(jī)制

  • 請求的主機(jī)頭中包含的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’

當(dāng)從瀏覽器執(zhí)行請求時,您可能無法設(shè)置主機(jī)頭。 因此,Kong還會檢查一個名為X-Host-Override的頭的請求,并像Host頭一樣設(shè)置它:

$ 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/> 那我們最后的實(shí)際請求地址為 http://api.54im.com/status/200.使用"strip_request_path"屬性> 通過在API上啟用strip_request_path屬性,請求將被代理,而request_path屬性不包含在上游請求中。 讓我們通過向管理API發(fā)出請求來啟用此選項(xiàng):

$ 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 路由到業(yè)務(wù)的 API 使用: path URI 的方式請求 + 設(shè)置 strip_request_path 為 true我現(xiàn)在拿這個api實(shí)驗(yàn)下> 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代理的業(yè)務(wù)的api

curl -i -X GET –url “http://localhost:8000/api/api/member/login?xxx=xxx&xxx=xxx“

> 這里說明下這個結(jié)構(gòu)>http://localhost:8000/api/api/member/login?>http://localhost:8000/ 是kong提供的API代理層接口,提供給外界,當(dāng)然你上層還是可以用負(fù)載均衡>api 是上面新增接口中的 request_path>api/member/login? 是我們業(yè)務(wù)具體的接口了業(yè)務(wù)返回```{"code": 0,"data": {"xxx": "xxx","expires_in": "7200","refresh_token": "xxx","xxx": "xxx","uid": "21000"},"message": "OK","now": 1476348465224}

業(yè)務(wù)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 插件管理

官網(wǎng)目前有這幾類插件

Authentication 認(rèn)證插件

  • 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 分析監(jiān)控插件

  • Galileo
  • Datadog
  • Runscope

Transformations 轉(zhuǎn)換插件

  • 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 CreatedDate: Thu, 13 Oct 2016 09:01:55 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveAccess-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 UnauthorizedDate: Thu, 13 Oct 2016 09:03:17 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveWWW-Authenticate: Key realm="kong"Server: kong/0.9.3{"message":"No API key found in headers or querystring"}

那現(xiàn)在要認(rèn)證了,我該如何訪問接口呢,別急,繼續(xù)往下

添加Consumers消費(fèi)者

現(xiàn)在已經(jīng)配置了 key-auth 插件,還需要添加 consumer 到 API,才能繼續(xù)通過 Kong 代理請求。Consumer 在調(diào)用API時,與單個用戶請求關(guān)聯(lián),能被用來跟蹤、訪問管理等等。

建立一個用戶名稱為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"}

為消費(fèi)者Ivon提供密鑰憑據(jù)

curl -i -X POST \--url http://localhost:8001/consumers/Ivon/key-auth/ \--data 'key=18b4ccb1a20076813c208d8e8a281a94'

如果不指定key參數(shù),kong會為你生成一個,推薦不指定。

返回

{"key": "18b4ccb1a20076813c208d8e8a281a94","consumer_id": "4d6b3281-d26e-416b-b8fc-8185422386d5","created_at": 1476350157000,"id": "9bd5165b-a798-4ff3-91d9-398216bbcb55"}

再試著請求下之前的業(yè)務(wù)接口

$ curl -i -X GET --url "http://localhost:8000/api/api/member/login?xxx=xxx&xxx=xxx"HTTP/1.1 200 OKDate: Thu, 13 Oct 2016 09:20:14 GMTContent-Type: application/json;charset=UTF-8Content-Length: 314Connection: keep-aliveServer: TengineX-Kong-Upstream-Latency: 651X-Kong-Proxy-Latency: 0Via: 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 的第一個參數(shù),否則會報“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/"

返回拼團(tuán)的html

給activity-hub這個API增加賬戶密碼驗(yàn)證

$ 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消費(fèi)者增加認(rèn)證插件的賬戶密碼

$ 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}

再請求下業(yè)務(wù)接口

$ curl -i -X GET --url "http://localhost:8000/activity/"HTTP/1.1 401 UnauthorizedDate: Thu, 13 Oct 2016 10:00:12 GMTContent-Type: application/json; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveWWW-Authenticate: Basic realm="kong"Server: kong/0.9.3{"message":"Unauthorized"}

返回沒有認(rèn)證

加上賬戶密碼后訪問API

curl -u ivon:123456 -i -X GET --url "http://localhost:8000/activity/"可以正常訪問之前的html頁面

IP Restriction 插件演示

IP 限制,黑名單、白名單。支持單IP、多IP、IP區(qū)間等配置。

$ curl -X POST http://localhost:8001/apis/activity/plugins \ --data "name=ip-restriction" \ --data 'config.blacklist=192.168.20.156'

Rate Limiting 插件演示

以下是限制一分鐘內(nèi)只允許同一個IP 有5個請求,一小時內(nèi)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 節(jié)點(diǎn)信息

curl -X GET?http://localhost:8001/

返回

{
“hostname”: “”,
“l(fā)ua_version”: “LuaJIT 2.1.0-alpha”,
“plugins”: {
“available_on_server”: [

],
“enabled_in_cluster”: [

]
},
“configuration” : {

},
“tagline”: “Welcome to Kong”,
“version”: “0.6.0”
}

#### 請求狀態(tài)統(tǒng)計請求狀態(tài)統(tǒng)計,其實(shí)就是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集群狀態(tài)

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}

#### 創(chuàng)建消費(fèi)者

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/

總結(jié)

以上是生活随笔為你收集整理的centos-install-kong-cassandra的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。