麻袋理财基于Docker的容器化实践褚夫元@麻袋理财背景(互联网金融)征信•借款人借款之前会进行资格审核>还款意愿(征信的目的)>还款能力•我们通过两种方式来做征信>查询内部数据>查询外部数据•接口名称•身份验证•进件规则•黑名单查询•灰名单查询•反欺诈规则•…改造之前-MonolithicApplication•提供统一API供内部服务访问•根据业务规则调用不同第三方API•使用HttpClient访问第三方API•SpringMVC•Hibernate•HttpClient架构-服务拆分•原则(TheTwelve-FactorApp)•单一职责:每一个模块(服务)只做一件事情•项目粒度:每一个可以单独进程跑的项目拆分为一个单独的项目•代码与配置分离:Build->Release->Run改造结果-模块化/服务化/Docker化•APIGateway•ServiceAPI•AdminAPI•ScheduleService•Worker•Dubbo(ZooKeeper)•Redis架构图APIGatewayRedisDubboZooKeeperDataProcessingServiceWorkerWorkerScheduleServiceWorkerWorkerWorkerDocker实践-HostLinux版本•HostLinuxUbuntu:14.04.4LTSKernel4.2CentOS:7.2.1511Kernel3.10Dockerminimumrequirement:Kernel3.10Docker1.9:Kernel3.16foroverlaynetworkDocker实践-Docker版本•Docker:版本1.10UpdatingresourceconstraintsonrunningcontainersContent-addressablestorageAllowtosetdaemonconfigurationinafileConfigurationhot-reloadSupportcustomIPaddressesDockerImage•Lessdependency,morecustomization•phusion/baseimagerunit-servicemanagementsyslogcronssh•https://github.com/phusion/baseimage-docker•FatcontainervsThincontainerDockerfileUnionFilesystem1.JDKbaseimageJAVA_OPTS-Dfile.encoding=UTF-8-Duser.timezone=Asia/Shanghai2.mvn-buildtoolsprivatemavenrepository3.mvn-onbuild-dependency4.project-bootstrapDockerRegistry-Harbor•通过GUI可以轻松的浏览和搜索镜像仓库,能够方便的管理项目和权限。•通过项目组织权限•支持接入企业AD/LDAP•所有操作都会被追踪记录用于审计•提供RESTfulAPI•https://github.com/vmware/harborDocker存储COWoverheadDatavolumesarenotcontrolledbythestoragedriverPromotessmallerimagesDocker存储•DevicemapperBlock-levelcopy-on-writesystem-allblocksare64KBThinprovisioning-*data100Gmetadata2GdefaultLooplvmbydefault.directlvmforproduction.Notthemostmemory...