usterWiki | Eglish | 中文 | 日本語
基于HAProxy的高性能HTTP缓存服务器和RESTfulNoSQL缓存服务器。中文版更新可能不及时,最新版请参照英文版README.md
目录介绍性能入门指南使用方法指令CacheNoSQL管理统计开启关闭rule更新生存时间清除StoreSamplefetchesFAQ介绍uster是一个基于HAProxy的高性能HTTP缓存服务器和RESTfulNoSQL缓存服务器,完全兼容HAProxy,并且利用HAProxy的ACL功能来提供非常细致的缓存规则。特性HTTP/TCP负载均衡器uster可以作为HTTP/TCP负载均衡器使用。继承了HAProxy的所有特性,完全兼容HAProxy负载均衡前端后端HTTPSHTTP压缩HTTP重写重定向HTTP信息增删改HTTP2监控粘性访问控制内容切换HTTP缓存服务器uster也可以用作类似Varish或者Ngix那样的HTTP缓存服务器,来缓存动态或者静态的HTTP资源。HAProxy的所有特性(HTTPS,HTTP/2,ACL,etc)非常快强大的动态缓存功能基于HTTPmethod,URI,path,query,header,cookies,etc基于HTTPrequestorresposecotets,etc基于evirometvariables,serverstate,etc基于SSLversio,SNI,etc基于coectiorate,umber,byte,etc缓存管理缓存清除缓存统计信息缓存生存时间持久化RESTfulNoSQL缓存服务器uster也可以用作RESTfulNoSQL缓存服务器,用HTTP POST/GET/DELETE 来添加/取得/删除Key/Value.可以像Memcached或者Redis那样放在应用和数据库之间作为内部KV缓存使用,也可以放在用户和应用之间作为面向用户的NoSQL使用。支持header,cookie等等,所以可以将不同的用户数据存到相同的路劲。HAProxy的所有特性(HTTPS,HTTP/2,ACL,etc)有条件的缓存内部KV缓存面向用户缓存支持任何类型的数据支持所有编程语言,不需要特定的库,只需HTTP支持持久化性能非常快,单进程模式下是gix的3倍,多进程下gix的2倍,varish的3倍。详见bechmark入门指南下载生产环境的话从Dowload下载最新稳定版,其他情况可以gitcloe。编译makeTARGET=liux2628USE_LUA=1LUA_INC=/usr/iclude/lua5.3USE_OPENSSL=1USE_PCRE=1USE_ZLIB=1makeistallPREFIX=/usr/local/uster添加USE_PTHREAD_PSHARED=1使用pthread
如果不需要可以删除USE_LUA=1LUA_INC=/usr/iclude/lua5.3USE_OPENSSL=1USE_PCRE=1USE_ZLIB=1
具体可以参考HAProxyINSTALL。配置文件准备一个配置文件: uster.cfgglobalustercacheodata-size100musterosqlodata-size200mmaster-worker#v3defaultsmodehttpfrotedfebid*:8080#bid*:4433sslcrtexample.com.pemalph2,http/1.1use_backedbe2if{path_beg/_kv/}default_backedbe1backedbe1ustercacheousterruleimgttl1dif{path_beg/img/}usterruleapittl30sif{path/api/some/api}servers1127.0.0.1:8081servers2127.0.0.1:8082backedbe2usterosqlousterruler1ttl3600uster监听8080端口,接受HTTP请求。 /_kv/开头的请求分配到backed be2,可以发送HTTP POST/GET/DELETE到/_kv/ay_key 来添加/取得/删除Key/Value.其他的请求都被分配到backed be1,并且会被转发到服务器s1 or s2.其中/img/*请求会被缓存1天,而/api/some/api会被缓存30秒。启动/usr/local/uster/sbi/uster-fuster.cfgDockerdockerpulluster/usterdockerru-d-v/path/to/uster.cfg:/etc/uster/uster.cfg:ro-p8080:8080uster/uster使用方法uster基于HAProxy,支持所有的HAProxy指令。基本配置文件里有四个基本的sectios: global, defaults, froted ad backed。global定义全局指令需要定义ustercacheo or usterosqlo,否则cache和osql无法使用defaults定义froted, backed的默认参数可以在froted or backed sectio重新定义froted定义监听端口等等面向用户的设置baked定义后端服务器等等设置需要设置ustercacheo or usterosqlo,否则该backed没有osql或者osql功能需要设置usterrule可以定义多个froted or backed .如果定义了ustercache|osqloff或者没有ustercache|osqlo|off,uster就是一个HAProxy。无法在liste里定义uster。具体参考/doc下的HAProxy文档,或者在线HAProxy文档AsTCPloaderbalacerfrotedmysql-lbbid*:3306modetcpdefault_backedmysql-clusterbackedmysql-clusterbalaceroudrobimodetcpservers110.0.0.101:3306servers210.0.0.102:3306servers310.0.0.103:3306AsHTTP/HTTPSloaderbalacerfrotedweb-lbbid*:80#bid*:443sslcrtXXX.pemmodehttpdefault_backedappsbackedappsbalaceroudrobimodehttpservers110.0.0.101:8080servers210.0.0.102:8080servers310.0.0.103:8080#servers410.0.0.101:8443sslverifyoeAsHTTPcacheserverglobalustercacheodata-size200mfrotedfebid*:8080default_backedbebackedbeustercacheousterruleallservers1127.0.0.1:8081AsRESTfulNoSQLcacheserverglobalusterosqlodata-size200mfrotedfebid*:8080default_backedbebackedbeusterosqlousterruler1ttl3600指令global:ustermaagersytax:ustermaagero|off[uriURI][purge-methodmethod]default: offcotext: global定义并开启maager/stats/purgeAPI,uri和purgemethod。默认是关闭的.如果开启了,注意开启访问控制(see FAQ).具体请参考管理.uri自定义管理URI,默认是 /usterpurge-method自定义PURGE用的HTTPmethod,默认是 PURGE.global:ustercache|osqlsytax:ustercacheo|off[data-sizesize][dict-sizesize][dirDIR][dict-cleaer][data-cleaer][disk-cleaer][disk-loader][disk-saver]usterosqlo|off[data-sizesize][dict-sizesize][dirDIR][dict-cleaer][data-cleaer][disk-cleaer][disk-loader][disk-saver]default: oecotext: global控制是否开启cache或者osql。会分配一块data-size+dict-size的共享内存来存储HTTP头,数据,key等等,临时数据从系统内存池分配。如果没有足够内存,新的请求不会被缓存直到有内存被释放。data-size和dict-size一起决定内存块的大小。可以使用m, M, g 和 G.默认是1MB,同时也是最小值。dict-size决定hashtable的大小.可以使用m, M, g 和 G.默认是1MB,同时也是最小值。这个决定hashtablebuckets的大小,并非key的大小,key存在共享内存中。dict-size(bucket数) 不等于 key数.就算key的数量超过了dict-size,只要整个共享内存有空间,新的key仍然可以被添加。不过如果key数超过dict-size(bucket数)性能也许会下降.dict-size可以设为大概的最大key数乘以8。当然越大越好。查看statsAPI:dict.osql.legth:131072dict.osql.used:0如果dict.osql.used 比dict.osql.legth大,调高dict-size比较好。将来版本会删除dict-size,像第一版本那样自动伸缩
dir设置硬盘缓存文件的根目录,必须设置以开启硬盘缓存功能。dict-cleaer每次检查最多 dict-cleaer 个etry,无效的etry将被删除(默认1000)data-cleaer每次检查最多 data-cleaer 个etry,无效的data将被删除(默认1000)disk-cleaer每次检查最多 disk-cleaer 个硬盘缓存文件,无效的文件将被删除(默认100)disk-loader启动后每次加载最多 disk-loader 个硬盘缓存文件的信息到内存(默认100)disk-saver每次检查最多 disk-saver 个data,并将需要保存至硬盘的data保存到硬盘(默认100)详细请参考Store.proxy:ustercache|osqlsytax:ustercache[o|off]usterosql[o|off]default: ocotext: backed决定是否在这个backed开启cache/osql。如果这个sectio有filter,记得放在最后。proxy:usterrulesytax:usterruleame[keyKEY][ttlTTL][extedEXTEND][codeCODE][memoryo|off][disko|off|syc][etago|off][last-modifiedo|off][if|ulesscoditio]default: oecotext: backed定义cache/osql的生效条件,需要定义至少一个rule。ustercacheo#cacherequest`/asdf`for30secodsusterruleasdfttl30if{path/asdf}#cacheiftherequestpathbegiswith/img/usterruleimgif{path_beg/img/}#cacheiftheresposeheader`cache`is`yes`aclresHdrCacheres.hdr(cache)yesusterruler1ifresHdrCache可以定义多个rule,按定义顺序先后匹配。aclpathApath/a.htmlustercacheousterruleallttl3600usterrulepath01ttl60ifpathArule path01永远不会被匹配。ame定义rule的ame。在cachemaagerAPI中使用,不必唯一但是建议不同的rule用不同的ame,否则相同ame的rule视作一样。keyKEY定义cache/osql的key,由下列关键字加.组成method:httpmethod,GET/POST...scheme:httporhttpshost:thehostitherequesturi:firstslashtoedoftheurlpath:theURLpathoftherequestdelimiter:'?'ifqueryexistsotherwiseemptyquery:thewholequerystrigoftherequestheader_NAME:thevalueofheader NAMEcookie_NAME:thevalueofcookie NAMEparam_NAME:thevalueofquery NAMEbody:thebodyoftherequestCACHE的默认key是 method.scheme.host.uri,NoSQL的默认key是 GET.scheme.host.uri.ExampleGEThttps://www.example.com/q?ame=X&type=Yhttpheader:GET/q?ame=X&type=YHTTP/1.1Host:www.example.comASDF:ZCookie:logged_i=yes;user=uster;生成:method:GETscheme:httphost: www.example.comuri:/q?ame=X&type=Ypath:/qdelimiter:?query:ame=X&type=Yheader_ASDF:Zcookie_user:usterparam_type:Ybody:(empty)默认key产生GET\0http\0www.example.com\0/q?ame=X&type=Y\0,而keymethod.scheme.host.path.header_ASDF.cookie_user.param_type 则生成 GET\0http\0www.example.com\0/q\0Z\0uster\0Y\0.\0是NULL字符
相同key的请求则会直接返回cache给客户端。ttlTTL设置缓存生存时间,过期后缓存会被删除。可以使用 d, h, m ad s。默认0秒.如果不希望失效则设为0可以通过设置 exted 关键词来自动延长缓存的ttl。extedEXTEND自动延长缓存ttl。格式extedo|off|1,2,3,4默认:off.1,2,3,4:小于100的正整数,1+2+3之和也小于100.他们定义四个时间段:time:0ttlttl*(1+4%)access:|A1|A2|A3|A4|||---------------------------|---------|---------|---------|---------|percetage:|<-(100-1-2-3)%->|<-1%->|<-2%->|<-3%->|<-4%->|满足下列条件缓存的ttl将被延长:A4>A3>A2在 ttl 和 ttl*(1+4%) 之间有新的请求o 其实是33,33,33,33
codeCODE1,CODE2...默认只缓存200的响应,如果需要缓存其他的则可以添加,all会缓存任何状态码。cache-ruleoly200cache-rule200ad404code200,404cache-ruleallcodeallmemoryo|off是否保存数据到内存,默认o。详见Storedisko|off|syc是否保存数据到硬盘,已经如何保存,默认off需要设置memoryo 以使用 disksyc详见Storeetago|off定义是否处理etag条件请求.如果没有 ETag 则添加。默认off.last-modifiedo|off定义是否处理last-modified条件请求.如果没有 Last-Modified 则添加.默认off.if|ulesscoditio定义ACL条件ACL分别在请求阶段和响应阶段执行。当下述条件满足时,会进行缓存:在请求阶段ACL为真请求阶段ACL为假,但是响应阶段ACL为真当使用否定的ACL或者某些样本获取方法时,需要特别注意比如缓存以/img/开头的请求
usterruleimgif{path_beg/img/}
请求阶段要么为真要么为假,因为在响应阶段无法获取path所以永远为假。缓存响应的http头部Cotet-Type 为 image/jpeg
usterrulejpegif{res.hdr(Cotet-Type)image/jpeg}
因为在请求阶段无法获取res.hdr所以永远为假,在响应阶段要么为真要么为假。以/img/开头,并且响应头 Cotet-Type 为image/jpeg时缓存如果定义为下面的规则,则不会成功:usterruleimgif{path_beg/img/}{res.hdr(Cotet-Type)image/jpeg}因为在响应阶段无法获取path所以永远为假,而在请求阶段无法获取res.hdr所以永远为假,那么这个ACL就永远无法匹配。需要如下来定义:http-requestset-var(tx.pathImg)pathaclpathImgvar(tx.pathImg)-mbeg/img/aclresHdrCTres.hdr(Cotet-Type)image/jpegusterruler3ifpathImgresHdrCT或者uster.path(v5):usterruler3if{uster.path-mbeg/img}{res.hdr(Cotet-Type)image/jpeg}另一个例子,缓存所有不以 /api/ 开头的请求下面不正确:aclNoCachepath_beg/api/usterruler3if!NoCache因为虽然在响应阶段path并不存在,所以NoCache永远为假,而 !NoCache 为真,所有的请求都会被缓存。需要改成:http-requestset-var(tx.path)pathaclNoCachevar(tx.path)-mbeg/api/usterruler1if!NoCache新samplefetch详见Samplefetches详见HAProxycofiguratio的7.UsigACLsadfetchigsamplesCacheuster也可以用作类似Varish或者Ngix那样的HTTP缓存服务器,来缓存动态或者静态的HTTP资源。出了HAProxy的SSL,HTTP,HTTP2,重写重定向,增删改Header等等,还提供了下面的功能。globalustercacheodata-size200mfrotedfebid*:8080default_backedbebackedbeustercacheousterruler1if{path/a1}usterruler2keymethod.scheme.host.path.delimiter.query.cookie_userIdif{path/a2}usterruler3ttl10if{path/a3}usterruler4diskolyif{path/a4}servers1127.0.0.1:8081uster会依次检查rule,先生成key然后查找,如果找到则返回缓存,否则就测试ACL,如果ACL通过则缓存响应。NoSQLuster也可以用作RESTfulNoSQL缓存服务器,用HTTP POST/GET/DELETE 来添加/取得/删除Key/Value.基本操作Setcurl-v-XPOST-dvalue1https://127.0.0.1:8080/key1curl-v-XPOST--data-biary@ico.jpghttps://127.0.0.1:8080/imgs/ico.jpgGetcurl-vhttps://127.0.0.1:8080/key1Deletecurl-v-XDELETEhttps://127.0.0.1:8080/key1ResposeCheckstatuscode.200OKPOST/GET:成功DELETE:总是400Badrequest空值不正确的acl,rules,etc404NotFoudPOST:ruletests失败GET:otfoud405MethodNotAllowed其他的methods500IteralServerError发生未知错误507IsufficietStorage超过data-size分用户的data通过在key里加入header,cookie等等,可以将不同的用户数据存到相同的路劲。usterruler1keymethod.scheme.host.uri.header_userIdif{path/mypoit}usterruler2keymethod.scheme.host.uri.cookie_sessioIdif{path/mydata}Setcurl-v-XPOST-d"333"-H"userId:1000"https://127.0.0.1:8080/mypoitcurl-v-XPOST-d"555"-H"userId:1001"https://127.0.0.1:8080/mypoitcurl-v-XPOST-d"userAdata"--cookie"sessioId=ijsf023xe"https://127.0.0.1:8080/mydatacurl-v-XPOST-d"userBdata"--cookie"sessioId=rosre329x"https://127.0.0.1:8080/mydataGetcurl-vhttps://127.0.0.1:8080/mypoit<404NotFoudcurl-v-H"userId:1000"https://127.0.0.1:8080/mypoit<200OK333curl-v--cookie"sessioId=ijsf023xe"https://127.0.0.1:8080/mydata<200OKuserAdata客户端支持任何支持HTTP的客户端,库: curl, postma,pytho requests,go et/http,etc.管理可以通过uri定义一个edpoit并发送HTTP请求来进行管理。定义并且开启ustermaagerouri/iteral/usterpurge-methodPURGEX方法一览METHODEdpoitdescriptioGET/iteral/uster获得statsPOST/iteral/uster开启关闭rule,更新ttlDELETE/iteral/uster高级PurgePURGEX/ay/real/path基础Purge统计可以通过GET uri定义的edpoit来获取统计信息。Usagecurlhttps://127.0.0.1/usterOutput**NUSTER**uster.cache:ouster.osql:ouster.maager:o**MANAGER**maager.uri:/ustermaager.purge_method:PURGE**DICT**dict.cache.size:1048576dict.cache.legth:131072dict.cache.used:0dict.cache.cleaup_idx:0dict.cache.syc_idx:0dict.osql.size:1048576dict.osql.legth:131072dict.osql.used:0dict.osql.cleaup_idx:0dict.osql.syc_idx:0**STOREMEMORY**store.memory.cache.size:2098200576store.memory.cache.used:1048960store.memory.cache.cout:0store.memory.osql.size:11534336store.memory.osql.used:1048960store.memory.osql.cout:0**STOREDISK**store.disk.cache.dir:/tmp/uster/cachestore.disk.cache.loaded:yesstore.disk.osql.dir:/tmp/uster/osqlstore.disk.osql.loaded:yes**STATS**stats.cache.total:0stats.cache.hit:0stats.cache.fetch:0stats.cache.abort:0stats.cache.bytes:0stats.osql.total:0stats.osql.get:0stats.osql.post:0stats.osql.delete:0**PROXYcacheapp1**app1.rule.rule1:state=omemory=odisk=offttl=10app1.rule.rule2:state=omemory=odisk=ottl=10app1.rule.rule3:state=omemory=odisk=sycttl=10app1.rule.rule4:state=omemory=offdisk=ottl=10app1.rule.rule5:state=omemory=offdisk=offttl=10**PROXYosqlapp2**app2.rule.ruleA:state=omemory=odisk=offttl=10app2.rule.ruleB:state=omemory=odisk=ottl=10app2.rule.ruleC:state=omemory=odisk=sycttl=10app2.rule.ruleD:state=omemory=offdisk=ottl=10app2.rule.ruleE:state=omemory=offdisk=offttl=10开启关闭rulerule可以通过maageruri动态开启关闭,关闭的rule不会再进行匹配。headersheadervaluedescriptiostateeableeablerule disabledisableruleameruleNAMEtheruletobeeabled/disabled proxyNAMEallrulesofproxyNAME *allrules相同ame的rule都会被开启关闭。Examples关闭ruler1
curl-XPOST-H"ame:r1"-H"state:disable"https://127.0.0.1/uster
关闭backedapp1b的所有rule
curl-XPOST-H"ame:app1b"-H"state:disable"https://127.0.0.1/uster
开启所有的rule
curl-XPOST-H"ame:*"-H"state:eable"https://127.0.0.1/uster
更新生存时间更改TTL,只会影响后续的新缓存,不会影响已经存在的缓存。headersheadervaluedescriptiottlewTTLsee ttl i usterruleameruleNAMEtheruletobechaged proxyNAMEallrulesofproxyNAME *allrulesExamplescurl-XPOST-H"ame:r1"-H"ttl:0"https://127.0.0.1/ustercurl-XPOST-H"ame:r2"-H"ttl:2h"https://127.0.0.1/uster同时设置state和ttl同时设置state和ttlcurl-XPOST-H"ame:r1"-H"ttl:0"-H"state:eabled"https://127.0.0.1/uster清除有两种清除模式:基础Purge:发送 purge-methodMYPURGE 定义的方法到想要删除的Path高级Purge:发送DELETE到maageruri基础Purge:删除一个特定URLcurl-XPURGEhttps://127.0.0.1/imgs/test.jpg根据rule生成key并删除那个key。只对GET请求生成的缓存有效。默认key包含Host,如果缓存时用了https://example.com/test 而在localhost删除是需要Host header:curl-XPURGE-H"Host:example.com"https://127.0.0.1/test对cache和osql都有效,osql模式相当于 DELETE。高级Purge:通过ame删除可以通过带上ame header来 PURGEheadersheadervaluedescriptioameusterruleNAMEcachesofrule${NAME}willbepurged proxyNAMEcachesofproxy${NAME} *allcachesExamples#删除所有缓存curl-XDELETE-H"ame:*"https://127.0.0.1/uster#删除backedapplb的所有缓存curl-XDELETE-H"ame:app1b"https://127.0.0.1/uster#删除所有ruler1生成的缓存curl-XDELETE-H"ame:r1"https://127.0.0.1/uster高级Purge:通过host删除通过带上uster-hostheader来删除所有属于这个host的缓存。headersheadervaluedescriptiohostHOSTthe${HOST}uster-hostHOSTuster-host存在则使用uster-hostmodecache,osqlpurgecacheorosqldataExamplescurl-XDELETE-H"uster-host:127.0.0.1:8080"https://127.0.0.1/uster高级Purge:通过path删除默认情况下,query部分也包含在key中,所以相同的path不同的query会产生不同的缓存。比如usterruleimgsif{path_beg/imgs/},然后请求curlhttps://127.0.0.1/imgs/test.jpg?w=120&h=120curlhttps://127.0.0.1/imgs/test.jpg?w=180&h=180会生成两个缓存,因为query不一样。如果要删除这些缓存,可以如果知道所有的query,那么可以一个一个删除curl-XPURGEhttps://127.0.0.1/imgs/test.jpg?w=120&h=120curl-XPURGEhttps://127.0.0.1/imgs/test.jpg?w=180&h=180大多数情况下不知道所有的query如果query部分不重要,则可以从key里面删除query定义usterruleimgskeymethod.scheme.host.pathif{path_beg/imgs},这样的话只会生成一个缓存,那么就可以不用query删除缓存curl-XPURGEhttps://127.0.0.1/imgs/test.jpg大多数情况需要query通过ruleame删除curl-XPURGE-H"ame:imgs"https://127.0.0.1/uster/cache但是如果rule被定义成了 usterrulestaticif{path_beg/imgs//css/},则无法只删除imgs因此,可以通过path删除headersheadervaluedescriptiopathPATHcacheswith${PATH}willbepurgedhostHOSTadhostis${HOST}uster-hostHOSTuster-hosthashigherprecedeceoverhostmodecache,osqlpurgecacheorosqldataExamples#删除所有path是/imgs/test.jpg的缓存curl-XDELETE-H"path:/imgs/test.jpg"https://127.0.0.1/uster#删除所有path是/imgs/test.jpg并且host是127.0.0.1:8080的缓存curl-XDELETE-H"path:/imgs/test.jpg"-H"uster-host:127.0.0.1:8080"https://127.0.0.1/uster高级Purge:通过正则删除也可以通过正则删除,所有匹配正则的缓存将被删除。headersheadervaluedescriptioregexREGEXcacheswhichpathmatchwith${REGEX}willbepurgedhostHOSTadhostis${HOST}uster-hostHOSTuster-hosthashigherprecedeceoverhostmodecache,osqlpurgecacheorosqldataExamples#删除所有/imgs开头.jpg结尾的缓存curl-XDELETE-H"regex:^/imgs/.*\.jpg$"https://127.0.0.1/uster#deleteallcacheswhichpathstartswith/imgsadedswith.jpgadwithhostof127.0.0.1:8080curl-XDELETE-H"regex:^/imgs/.*\.jpg$"-H"127.0.0.1:8080"https://127.0.0.1/usterPURGE注意事项开启访问控制
如果有多个header,按照ame, path&host, path, regex&host, regex, host的顺序处理
curl-XDELETE-H"ame:rule1"-H"path:/imgs/a.jpg":purgebyame
如果有重复的header,处理第一个
curl-XDELETE-H"ame:rule1"-H"ame:rule2":purgeby rule1
regex 不是glob
比如/imgs下的.jpg文件是^/imgs/.*\.jpg$ 而不是 /imgs/*.jpg
通过ruleame或proxyame删除缓存时,需要注意这两种方法只在当前进程有效。如果重启了进程则无法通过这两种方法删除缓存文件,因为ruleame信息和proxyame信息并没有保存在缓存文件中。
只有diskload结束后才能通过hostorpathorregex来删除缓存文件。是否已经load结束可以查看statsURL。
StoreNuster(cache和osql)支持多种后端存储.目前支持memory和disk。计划添加其他后段。Memory数据被存在一个大小由data-size定义的内存区域。重启后数据会消失。Disk数据被存到硬盘由dir定义的目录下。重启后数据不会消失。有三种模式:off:默认,不保存到硬盘o:保存到硬盘syc:需要设置memoryo。先保存至内存然后由master进程在一定时间后同步到硬盘,每次同步dict-saver个缓存。SamplefetchesNuster加入了一些新的samplefetches[cache]uster.cache.hit:boolea表示是否是HIT缓存,可以像如下使用http-resposeset-headerx-cachehitif{uster.cache.hit}[cache|osql]uster.host:strig类似HAProxy的 req.hdr(Host),但是请求和响应中都可使用[cache|osql]uster.uri:strig等同于HAProxy的capture.req.uri.[cache|osql]uster.path:strig类似HAProxy的 path,但是请求和响应中都可使用[cache|osql]uster.query:strig类似HAProxy的 query,但是请求和响应中都可使用FAQ无法启动,报错:otimaster-workermode在global 添加 master-worker 或者启动时使用-W参数。如何调试?在global添加debug,或者带-d启动usteruster相关的调试信息以[uster开头如何缓存POST请求?添加optiohttp-buffer-request如果自定义了key的话需要使用body关键字请求body可能不完整,详见HAProxycofiguratio 的 optiohttp-buffer-request小节另外可以为post请求单独设置一个后端如何做访问控制?类似acletwork_allowedsrc127.0.0.1aclpurge_methodmethodPURGEhttp-requestdeyifpurge_method!etwork_allowed如何开启HTTP2?bid:443sslcrtpub.pemalph2,http/1.1Exampleglobalustercacheodata-size100musterosqlodata-size100mmaster-worker#v3#daemo#debugdefaultsretries3optioredispatchtimeoutcliet30stimeoutcoect30stimeoutserver30sfrotedweb1bid*:8080modehttpaclpathPostpath/searchuse_backedapp1aifpathPostdefault_backedapp1bbackedapp1abalaceroudrobi#modemustbehttpmodehttp#http-buffer-requestmustbeeabledtocachepostrequestoptiohttp-buffer-requestaclpathPostpath/search#eablecacheforthisproxyustercache#cache/searchfor120secods.OlyworkswhePOST/PUTusterrulerpostkeymethod.scheme.host.uri.bodyttl120ifpathPostservers110.0.0.10:8080backedapp1bbalaceroudrobimodehttpustercacheo#cache/a.jpg,otexpireaclpathApath/a.jpgusterruler1ttl0ifpathA#cache/mypage,keycotaiscookie[userId],soitwillbecachedperuseraclpathBpath/mypageusterruler2keymethod.scheme.host.path.delimiter.query.cookie_userIdttl60ifpathB#cache/a.htmlifrespose'sheader[cache]isyeshttp-requestset-var(tx.pathC)pathaclpathCvar(tx.pathC)-mstr/a.htmlaclresHdrCache1res.hdr(cache)yesusterruler3ifpathCresHdrCache1#cache/heavyfor100secodsifbe_cogreatertha10aclheavypagepath/heavyacltooFastbe_coge100usterruleheavyttl100ifheavypagetooFast#cacheallifrespose'sheader[asdf]isfdsaaclresHdrCache2res.hdr(asdf)fdsausterruleresCachettl0ifresHdrCache1servers110.0.0.10:8080frotedweb2bid*:8081modehttpdefault_backedapp2backedapp2balaceroudrobimodehttp#disablecacheothisproxyustercacheoffusterruleallservers210.0.0.11:8080frotedosql_febid*:9090default_backedosql_bebackedosql_beusterosqlousterruler1ttl3600
评论