最近,有几个老项目需要做一些限流、安全、灰度发布等这些方面的升级。由于项目中也一直在用Nginx做请求转发。所以在在OpenResty,Kong、APISIX三者之间初步对比了一下。从性能、功能和易用性的角度考虑,最终初步选择APISIX这玩意。 对于安装。我本人是比较偏向于,源码或者二进制手动安装。在安装APISIX时,其他都准备就绪了,就在安装APISIX时,很多代码拉不下来。导致我从源码安装到放弃。最终选择Docker方式安装etcd 去Githubhttps:github。cometcdioetcdreleases下载编译好的二进制。 先创建好配置文件。123mkdirpetcetcdcdetcetcdvimetcd。yaml 复制一下内容123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140Thisistheconfigurationfilefortheetcdserver。Humanreadablenameforthismember。name:etcd1Pathtothedatadirectory。datadir:Pathtothededicatedwaldirectory。waldir:Numberofcommittedtransactionstotriggerasnapshottodisk。snapshotcount:10000Time(inmilliseconds)ofaheartbeatinterval。heartbeatinterval:100Time(inmilliseconds)foranelectiontotimeout。electiontimeout:1000Raisealarmswhenbackendsizeexceedsthegivenquota。0meansusethedefaultquota。quotabackendbytes:0ListofcommaseparatedURLstolistenonforpeertraffic。listenpeerurls:http:172。31。79。250:2380ListofcommaseparatedURLstolistenonforclienttraffic。listenclienturls:http:172。31。79。250:2379Maximumnumberofsnapshotfilestoretain(0isunlimited)。maxsnapshots:5Maximumnumberofwalfilestoretain(0isunlimited)。maxwals:5CommaseparatedwhitelistoforiginsforCORS(crossoriginresourcesharing)。cors:ListofthismemberspeerURLstoadvertisetotherestofthecluster。TheURLsneededtobeacommaseparatedlist。initialadvertisepeerurls:http:172。31。79。250:2380ListofthismembersclientURLstoadvertisetothepublic。TheURLsneededtobeacommaseparatedlist。advertiseclienturls:http:172。31。79。250:2379DiscoveryURLusedtobootstrapthecluster。discovery:Validvaluesincludeexit,proxydiscoveryfallback:proxyHTTPproxytousefortraffictodiscoveryservice。discoveryproxy:DNSdomainusedtobootstrapinitialcluster。discoverysrv:Initialclusterconfigurationforbootstrapping。initialcluster:Initialclustertokenfortheetcdclusterduringbootstrap。initialclustertoken:etcdclusterInitialclusterstate(neworexisting)。initialclusterstate:newRejectreconfigurationrequeststhatwouldcausequorumloss。strictreconfigcheck:falseEnableruntimeprofilingdataviaHTTPserverenablepprof:trueValidvaluesincludeon,readonly,offproxy:offTime(inmilliseconds)anendpointwillbeheldinafailedstate。proxyfailurewait:5000Time(inmilliseconds)oftheendpointsrefreshinterval。proxyrefreshinterval:30000Time(inmilliseconds)foradialtotimeout。proxydialtimeout:1000Time(inmilliseconds)forawritetotimeout。proxywritetimeout:5000Time(inmilliseconds)forareadtotimeout。proxyreadtimeout:0clienttransportsecurity:PathtotheclientserverTLScertfile。certfile:PathtotheclientserverTLSkeyfile。keyfile:Enableclientcertauthentication。clientcertauth:falsePathtotheclientserverTLStrustedCAcertfile。trustedcafile:ClientTLSusinggeneratedcertificatesautotls:falsepeertransportsecurity:PathtothepeerserverTLScertfile。certfile:PathtothepeerserverTLSkeyfile。keyfile:Enablepeerclientcertauthentication。clientcertauth:falsePathtothepeerserverTLStrustedCAcertfile。trustedcafile:PeerTLSusinggeneratedcertificates。autotls:falseThevalidityperiodoftheselfsignedcertificate,theunitisyear。selfsignedcertvalidity:1Enabledebuglevelloggingforetcd。loglevel:debuglogger:zapSpecifystdoutorstderrtoskipjournaldloggingevenwhenrunningundersystemd。logoutputs:〔stderr〕Forcetocreateanewonemembercluster。forcenewcluster:falseautocompactionmode:periodicautocompactionretention:112345wgethttps:github。cometcdioetcdreleasesdownloadv3。5。7etcdv3。5。7linuxamd64。tar。gztarxvfetcdv3。5。7linuxamd64。tar。gzcdetcdv3。5。7linuxamd64cpaetcdetcdctlusrbinnohupetcdconfigfileetcetcdetcd。yamltmpetcd。log21后台启动etcd安装Docker 添加阿里镜像源1yumconfigmanageraddrepohttp:mirrors。aliyun。comdockercelinuxcentosdockerce。repo 安装Docker1yuminstalldockercedockerceclicontainerd。io 启动Docker服务1systemctlstartdocker 设置Docker开机自动启动1systemctlenabledockerDockercompose安装 下载并安装1curlSLhttps:github。comdockercomposereleasesdownloadv2。16。0dockercomposelinuxx8664ousrlocalbindockercompose 上面这个地址非常慢,有时候直接连不通,具体原因,大家肯定都知道。所以下载用国内的镜像地址吧1sudocurlLhttps:get。daocloud。iodockercomposereleasesdownloadv2。16。0dockercomposelinuxx8664ousrlocalbindockercompose 去下载源码https:github。comapacheapisixdocker。git。cdapisixdockerexample进入到example目录 由于etcd我是以二进制方式安装,那么apisixconf和dashboardconf里面的etcd配置信息改为实际地址和端口。12345etcd:host:itspossibletodefinemultipleetcdhostsaddressesofthesameetcdcluster。http:172。31。79。250:2379multipleetcdaddressprefix:apisixapisixconfigurationsprefixtimeout:3030seconds 另外dockercomposearm64。yml里面的ETCD去掉,再去掉dependson,删除下面这段12dependson:etcd 接下来执行启动命令dockercomposefdockercomposearm64。ymlpdockerapisixupd 这样,APISIX便搭建好了 我们使用dashboardconf文件夹中conf。yaml文件里的users属性来登录APISIX。 创建APISIX服务 上游类型可以是,固定维护的节点或者是服务注册 服务注册中心支持目前比较主流的注册中心 这里我们选择的是节点方式 这时候,我们就可以去访问9080端口的web1路径 刷新一下页面。请求会转发到另外一个服务上 APISIX初步安装完成,基本功能我们可以基于webUI界面配置完成,还可以借助插件来保护我们的服务,让服务更加稳定、安全。接下来就是进一步的探究APISIX提供的插件。