生活工程体验信仰哲学精神
投稿投诉
精神世界
探索历史
哲学文学
艺术价值
信仰创造
境界审美
体验技术
技能工具
工程信息
医学生产
生活运用
操作能力

电商架构实战(一)

12月24日 相思宫投稿
  一、架构讲解
  大型电商系统架构图:
  1、缓存架构
  nginx本地缓存redis分布式缓存tomcat堆缓存
  2、缓存数据库读写模式读的时候先从缓存读,没有再去读数据库,从数据库读到了之后写入缓存更新数据时,需要删除缓存
  更新数据时删除缓存原因:因为有很多时候,缓存不仅仅是数据库取出来的值,而是经过复杂的计算了的。那么更新的代价就比较大。
  如果更新了100次数据,但是实际只访问几次,那么每次都更新缓存就不划算了。不如等他访问的时候再计算。
  3、Nginx双层缓存模型
  第一层是ngnix分发服务器,第二层是ngnix后端服务器,可以避免每个商品走不同得ngnix,提升ngnix本地缓存命中率二、Nginx双层缓存架构
  NginxLua部署
  1、部署openrestymkdirpusrserverscdusrserversyuminstallyreadlinedevelpcredevelopenssldevelgccwgethttp:openresty。orgdownloadngxopenresty1。7。7。2。tar。gztarxzvfngxopenresty1。7。7。2。tar。gzcdusrserversngxopenresty1。7。7。2cdbundleLuaJIT2。120150120makecleanmakemakeinstalllnsfluajit2。1。0alphausrlocalbinluajitcdbundlewgethttps:github。comFRiCKLEngxcachepurgearchive2。3。tar。gztarxvf2。3。tar。gzcdbundlewgethttps:github。comyaoweibinnginxupstreamcheckmodulearchivev0。3。0。tar。gztarxvfv0。3。0。tar。gzcdusrserversngxopenresty1。7。7。2。configureprefixusrserverswithhttprealipmodulewithpcrewithluajitaddmodule。bundlengxcachepurge2。3addmodule。bundlenginxupstreamcheckmodule0。3。0j2makemakeinstallcdusrserversllusrserversluajitusrserverslualibusrserversnginxusrserversnginxsbinnginxV启动nginx:usrserversnginxsbinnginx
  注意:启动遇到这个问题
  〔rootcentos01conf〕
  nginx:〔error〕invalidPIDnumberinusrserversnginxlogsnginx。pid
  解决方法:usrserversnginxsbinnginxcusrserversnginxconfnginx。conf
  2、配置ngnixlua
  1。编辑nginx配置
  viusrserversnginxconfnginx。conf
  在http部分添加:luapackagepathusrhellolualib?。;;luapackagecpathusrhellolualib?。;;includeusrhellohello。创建hello。confmkdirusrhello
  编辑vihello。confserver{listen80;locationhello{contentbyluafileusrhelloluahello。}}
  编辑hello。lua
  mkdirusrhellolua
  cdusrhellolua
  vihello。luangx。say(helloworld);
  拷贝所需资源cprusrserverslualibusrhello
  重新加载配置usrserversnginxsbinnginxsreload
  若有三台ngnix服务器,两台作为应用服务器,一台作为分发服务器。
  3、分发服务器lua配置:
  1、安装http包cdusrhellolualibrestywgethttps:raw。githubusercontent。compintsizedluarestyhttpmasterlibrestyhttpheaders。luawgethttps:raw。githubusercontent。compintsizedluarestyhttpmasterlibrestyhttp。lua
  2、编辑lua脚本
  其中hostl里面换成另外两台服务器的ip
  viusrhelloluahello。lualocaluriargsngx。req。geturiargs()localproductIduriargs〔productId〕localhost{192。168。1。12,192。168。1。13}localhashngx。crc32long(productId)hash(hash2)1backendhttp:。。host〔hash〕localmethoduriargs〔method〕localrequestBody。。method。。?productId。。productIdlocalhttprequire(resty。http)localhttpchttp。new()localresp,errhttpc:requesturi(backend,{methodGET,pathrequestBody,keepalivefalse})ifnotrespthenngx。say(requesterror:,err)returnendngx。say(resp。body)httpc:close()
  重启nginx
  3、请求测试
  修改productId的值查看效果
  http:192。168。1。14hello?methodhelloproductId5
  4、应用nginx服务器配置
  1、下载依赖的包cdusrhellolualibrestywgethttps:raw。githubusercontent。compintsizedluarestyhttpmasterlibrestyhttpheaders。luawgethttps:raw。githubusercontent。compintsizedluarestyhttpmasterlibrestyhttp。luawgethttps:raw。githubusercontent。combungleluarestytemplatemasterlibrestytemplate。luamkdirusrhellolualibrestyhtmlcdusrhellolualibrestyhtmlwgethttps:raw。githubusercontent。combungleluarestytemplatemasterlibrestytemplatehtml。lua
  2、修改配置cdusrhellovihello。conf
  整体内容为:server{listen80;locationhello{contentbyluafileusrhelloluahello。}}
  3、创建html模板:mkdirusrhellotemplatescdusrhellotemplatesviproduct。htmlhtmlheadmetahttpequivContentTcharsetUTF8title商品详情页titleheadbodyproductid:{productId}
  productname:{productName}
  productpicturelist:{productPictureList}
  productspecification:{productSpecification}
  productservice:{productService}
  productcolor:{productColor}
  productsize:{productSize}
  shopid:{shopId}
  shopname:{shopName}
  shoplevel:{shopLevel}
  shopgoodcoomentrate:{shopGoodCommentRate}
  bodyhtml
  4、修改lua脚本localuriargsngx。req。geturiargs()localproductIduriargs〔productId〕localshopIduriargs〔shopId〕localcachengxngx。shared。mycachelocalproductCacheKeyproductinfo。。productIdlocalshopCacheKeyshopinfo。。shopIdlocalproductCachecachengx:get(productCacheKey)localshopCachecachengx:get(shopCacheKey)ifproductCacheorproductCachenilthenlocalhttprequire(resty。http)localhttpchttp。new()localresp,errhttpc:requesturi(http:192。168。31。179:8080,{methodGET,pathgetProductInfo?productId。。productId})productCacheresp。bodycachengx:set(productCacheKey,productCache,1060)endifshopCacheorshopCachenilthenlocalhttprequire(resty。http)localhttpchttp。new()localresp,errhttpc:requesturi(http:192。168。31。179:8080,{methodGET,pathgetShopInfo?shopId。。shopId})shopCacheresp。bodycachengx:set(shopCacheKey,shopCache,1060)endlocalcjsonrequire(cjson)localproductCacheJSONcjson。decode(productCache)localshopCacheJSONcjson。decode(shopCache)localcontext{productIdproductCacheJSON。id,productNameproductCacheJSON。name,productPriceproductCacheJSON。price,productPictureListproductCacheJSON。pictureList,productSpecificationproductCacheJSON。specification,productServiceproductCacheJSON。service,productColorproductCacheJSON。color,productSizeproductCacheJSON。size,shopIdshopCacheJSON。id,shopNameshopCacheJSON。name,shopLevelshopCacheJSON。level,shopGoodCommentRateshopCacheJSON。goodCommentRate}localtemplaterequire(resty。template)template。render(product。html,context)
  5、修改nginx配置viusrserversnginxconfnginx。conf在http里加入http{luashareddictmycache128m;}
  6、启动后台服务器
  提供getProductInfo接口,访问分发的nginx服务器测试:http:192。168。1。14hello?methodhelloproductId2shopId2
投诉 评论

为什么iPhone13比iPhone12便宜那么多?苹果每代的升级都没什么好说的,不存在哪一代挤牙膏,哪一代把牙膏挤炸了。只是在定价这方面,苹果的策略一直是隔代降价。比方说iPhoneXR我记得起售价是6499,结果……爸爸检查作业有原则,帮孩子大大减少低级错误,让专注成为本能文闹闹爸有一回,我去妹妹家做客,她忙着做饭,就让我帮忙检查外甥谦谦的作业。我找到几个低级错误后告诉谦谦:里面有错的!孩子问:哪里错了?我希望孩子养成检查的习惯……糖尿病睡觉也影响血糖,4不宜,要牢记其实,除了吃,糖尿病患者在晚上睡觉的时候也有很多需要注意的事情,只有注意了这些才能保持自己的血糖正常。No。1睡前不宜多吃进食后胃肠蠕动增强,大量的血液流向胃肠,流……NBA早报湖人三巨头电话会议,哈登想先得分再组织,三球改穿1关注NBA的朋友们,大家好!NBA夏季联赛昨日收官,开拓者获得冠军,穆迪当选夏联得分王,默里当选为MVP。目前交易市场的三条大鱼杜兰特、欧文、米切尔还没有确定下家,这给很多球队……董卿的经典哲理语录你的气质,来自于你走过的路,读过的书和遇见过的人。读书让人学会思考,让人能够沉静下来,享受一种灵魂深处的愉悦。每个人都有一段默默付出,但没有回报的日子,我们把它称之……故事连环画战地红缨(上册)。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。……连环画精品鉴赏血与沙(下册)汪晓曙绘。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。……电商架构实战(一)一、架构讲解大型电商系统架构图:1、缓存架构nginx本地缓存redis分布式缓存tomcat堆缓存2、缓存数据库读写模式读的时候先从缓存读,没有再去读……人民日报金句选编(八十一)事物有根本与末梢;事情有开端和结尾。事物有根本与末梢;事情有开端和结尾现在的你,是十年前你的决定,十年后的你,是现在你的决定。种一棵树,最好是十年前,其次是现在。想要改变,从此……热搜第一发现从鱼到人关键证据!4。4亿年前鱼类化石揭示有颌脊9月29日,话题我国科学家证实人类是从鱼进化来的冲上微博热搜榜首位置有网友自嘲:可我为什么还要学游泳16个字的热搜话题无法详细解释我国科学家……入选长三角精品目的地!你去过吗?近日,2022年长三角地区体育旅游精品项目榜单揭晓,江阴海澜飞马水城入选长三角地区体育旅游精品目的地。海澜飞马水城海澜飞马水城包含了马术表演馆、马文化博物馆、海澜美……什么样的女人活的最漂亮1。越养不起自己的女人,男人越不想养;越养的起自己的女人,男人越想养!2。越不攀附他人的女人,男人越尊重,女人越钦佩。3。越努力自我成长的女人,男人越刮目相看;女人……
换季如何呵护宝宝健康?葵花药业发来护娃宝典科尔接下来克莱和普尔都会发挥出高水准球队表现会更加稳定有一个地方叫鲅鱼圈生了病的城市水果和蔬菜都要吃王思聪也来投新材料了大量中企入局后,腾讯也要发力RISCV芯片?20221123尿素钾肥行情名导太太陈红封杀杨幂打压谢霆锋,踩洪晃上位获陈凯歌独宠106公斤独立分区全能洗烘,TCL双子舱复式分区洗衣机Q10刘加林鄱阳故乡处暑徐如玉酒后有感秋游有感教育部发布新版职业教育专业简介,工业互联网专业建设全面提速自制腊肠的保存方法自制腊肠的保存方法是什么漂亮的小鱼作文带孩子湖边散步如何预防落水七个小技巧助您实现完美“节俭”养车有趣的一堂课关于雪的作文雪山感恩老师消费清单查老公出轨(微信转账一个人记录怎么查)显男士成熟气质发型图片打造专属我的型男魅力资本论之个人感想银行述职报告参考借鉴例文山东隐藏在大山中的古村落,曾是齐鲁古商道,如今成为网红打卡地

友情链接:中准网聚热点快百科快传网快生活快软网快好知文好找