EFK架构(elasticsearchfilebeatkibana) 1、filebeat采集日志(可以采集多种日志类型loghttpsystemcpmqdockeraws。。。,具体采集配置参照:https:www。elastic。coguideenbeatsfilebeatcurrentconfigurationfilebeatoptions。html) 2、filebeat将采集到的日志解析推送至es 3、kibana展示 如果日志量特别大,可以参考此方案 1、filebeat采集日志到kafka,利用kafka高并发处理能力,kafka也可以是集群 2、logstash消费kafka数据,并存储到es集群,logstash也可以是集群 当然可以选择其他方案,大型日志系统复杂性高,选择自己合适的日志解决方案 本次部署版本为7。12。0,部署的时候确保版本一致。 1、下载elasticsearch、kibana、filebeat 〔rootecs7efk〕curlLOhttps:artifacts。elastic。codownloadselasticsearchelasticsearch7。12。0linuxx8664。tar。gz 〔rootecs7efk〕curlLOhttps:artifacts。elastic。codownloadskibanakibana7。12。0linuxx8664。tar。gz 〔rootecs7efk〕curlLOhttps:artifacts。elastic。codownloadsbeatsfilebeatfilebeat7。12。0linuxx8664。tar。gz 2、创建用户并授权 〔rootecs7efk〕groupaddelastic 〔rootecs7efk〕useraddgelasticelasticsearch 〔rootecs7efk〕chownRelasticsearch:elasticdataefk 3、安装并启动 3。1使用elasticsearch账号安装启动 3。1。1解压elasticsearch 〔rootecs7efk〕suelasticsearch 〔elasticsearchecs7efk〕tarzxvfelasticsearch7。12。0linuxx8664。tar。gz 3。1。2配置elasticsearch 〔elasticsearchecs7efk〕cdelasticsearch7。12。0config 备份原始配置文件 〔elasticsearchecs7config〕cpelasticsearch。ymlelasticsearch。yml。org elasticsearch。yml全文(本次部署为单节点部署) 集群名称 cluster。name:testefk 节点名称 node。name:master 索引数据存储目录 path。data:dataefkelasticsearch7。12。0data 日志 path。logs:dataefkelasticsearch7。12。0dlogs 外网访问 network。host:0。0。0。0 端口 http。port:9200 自动创建索引 action。autocreateindex:。security,。monitoring,。watches,。triggeredwatches,。watcherhistory,appa,appb 节点网络 discovery。seedhosts:〔191。168。0。107〕 当前节点类型 cluster。initialmasternodes:〔master〕 3。1。3启动elasticsearch 〔elasticsearchecs7efk〕cdelasticsearch7。12。0bin 〔elasticsearchecs7bin〕。elasticsearchd 〔elasticsearchecs7bin〕ERROR:〔1〕bootstrapchecksfailed。Youmustaddressthepointsdescribedinthefollowing〔1〕linesbeforestartingElasticsearch。 bootstrapcheckfailure〔1〕of〔1〕:maxvirtualmemoryareasvm。maxmapcount〔65530〕istoolow,increasetoatleast〔262144〕 ERROR:Elasticsearchdidnotexitnormallycheckthelogsatdataefkelasticsearch7。12。0dlogstestefk。log 启动es会有出现异常,解决方案,参照博客:https:blog。csdn。netF1004145107articledetails106279907 3。1。4访问 http:localhost:9200 〔elasticsearchecs7bin〕curlhttp:localhost:9200 { name:master, clustername:testefk, clusteruuid:Hovo67CRTF2zMnygQJ2NQ, version:{ number:7。12。0, buildflavor:default, buildtype:tar, buildhash:78722783c38caa25a70982b5b042074cde5d3b3a, builddate:20210318T06:17:15。410153305Z, buildsnapshot:false, luceneversion:8。8。0, minimumwirecompatibilityversion:6。8。0, minimumindexcompatibilityversion:6。0。0beta1 }, tagline:YouKnow,forSearch } 3。2安装启动kibana 3。2。1解压kibana 〔rootecs7efk〕suelasticsearch 〔elasticsearchecs7efk〕tarzxvfkibana7。12。0linuxx8664。tar。gz 3。2。2配置kibana 〔elasticsearchecs7efk〕cdkibana7。12。0linuxx8664 〔elasticsearchecs7kibana7。12。0linuxx8664〕cdconfig 〔elasticsearchecs7config〕cpkibana。ymlkibana。yml。org 备份原始配置文件 〔elasticsearchecs7config〕cpkibana。ymlkibana。yml。org kibana。yml全文 端口 server。port:5601 主机 server。host:0。0。0。0 名称 server。name:master es集群地址 elasticsearch。hosts:〔http:127。0。0。1:9200〕 日志目录 logging。dest:dataefkkibana7。12。0linuxx8664logskibana。log 3。2。3启动kibana 〔elasticsearchecs7kibana7。12。0linuxx8664〕ll total1476 drwxrxrx2elasticsearchelastic4096Mar1813:56bin drwxrxrx2elasticsearchelastic4096Apr1309:53config drwxrxrx2elasticsearchelastic4096Apr711:26data rwrr1elasticsearchelastic3860Mar1813:55LICENSE。txt drwxrxrx2elasticsearchelastic4096Apr711:26logs drwxrxrx6elasticsearchelastic4096Mar1813:55node drwxrxrx831elasticsearchelastic36864Mar1813:55nodemodules rwrr1elasticsearchelastic1428396Mar1813:55NOTICE。txt rwrr1elasticsearchelastic740Mar1813:55package。json drwxrxrx2elasticsearchelastic4096Mar1813:55plugins rwrr1elasticsearchelastic3968Mar1813:55README。txt drwxrxrx12elasticsearchelastic4096Mar1813:55src drwxrxrx3elasticsearchelastic4096Mar1813:55xpack 〔elasticsearchecs7kibana7。12。0linuxx8664〕cdbin 〔elasticsearchecs7bin〕ll total16 rwxrxrx1elasticsearchelastic850Mar1813:55kibana rwxrxrx1elasticsearchelastic783Mar1813:55kibanaencryptionkeys rwxrxrx1elasticsearchelastic776Mar1813:55kibanakeystore rwxrxrx1elasticsearchelastic813Mar1813:55kibanaplugin 〔elasticsearchecs7bin〕。kibana 3。2。4访问 浏览器访问http:localhost:5601 3。3安装启动filebeat filebeat不一定要跟es放在同一台服务器,可以是本机可以是其他服务器,它是一个采集工具,可以将数据推送至es,以下采用本机演示 3。3。1解压配置filebeat 备份原始配置文件 filebeat。yml全文 Filebeatinputs filebeat。inputs: type:log enabled:true encoding:UTF8 Pathsthatshouldbecrawledandfetched。Globbasedpaths。 paths: 需要采集的日志文件 D:data。log json。keyunderroot:true json。overwritekeys:true json。messagekey:message json。adderrorkey:true tags:〔saas〕 Filebeatmodules filebeat。config。modules: Globpatternforconfigurationloading path:{path。config}modules。d。yml Settotruetoenableconfigreloading reload。enabled:false Periodonwhichfilesunderpathshouldbecheckedforchanges reload。period:10s Elasticsearchtemplatesetting setup。template。settings: index。numberofshards:1 index。codec:bestcompression source。enabled:false setup。kibana: ElasticsearchOutput output。elasticsearch: Arrayofhoststoconnectto。 es地址 hosts:〔191。168。0。107:9200〕 processors: addhostmetadata: when。not。contains。tags:forwarded addcloudmetadata: adddockermetadata: addkubernetesmetadata: 日志时间处理 timestamp: field:json。timestamp timezone:AsiaShanghai layouts: 20060102T15:04:0508:00 20060102T15:04:05。99908:00 test: 20190622T16:33:5108:00 20191118T04:59:51。12308:00 删除相关字段 dropfields: fields:〔json。version,json。levelvalue,json。timestamp〕 重命名字段 rename: fields: from:json。logName to:json。appName ignoremissing:false failonerror:true 3。3。3启动filebeat 使用cmd运行filebeat。exe 3。4springbootlogback配置 pom。xml新增logstashlogbackencoder依赖,logstashlogbackencoder可以将日志以json的方式输出,也不用我们单独处理多行记录问题 net。logstash。logback logstashlogbackencoderartifactId 5。3 dependency ?xmlversion1。0encodingUTF8? d{yyyyMMddHH:mm:ss。SSS}〔thread〕5levelloggermsgn UTF8 encoder appender logs{logName}{logName}。log trueappend logs{logName}{logName}d{yyyyMMdd}。log。i 64MB 30hr1GB rollingPolicy AsiaShanghai timestamp {level:level,class:logger{40},message:message,stacktrace:exception} pattern providers encoder appender