如何做网站挣钱,各大企业邮箱,网站建设方案 预算,太原中小企业网站制作1.介绍
logstash 也可以收集日志#xff0c;但是数据量大时太消耗系统新能。而filebeat是轻量级的#xff0c;占用系统资源极少。
Filebeat 由两个主要组件组成#xff1a;harvester 和 prospector。
采集器 harvester 的主要职责是读取单个文件的内容。读取每个文件但是数据量大时太消耗系统新能。而filebeat是轻量级的占用系统资源极少。
Filebeat 由两个主要组件组成harvester 和 prospector。
采集器 harvester 的主要职责是读取单个文件的内容。读取每个文件并将内容发送到 the output。 每个文件启动一个 harvesterharvester 负责打开和关闭文件这意味着在运行时文件描述符保持打开状态。如果文件在读取时被删除或重命名Filebeat 将继续读取文件。
查找器 prospector 的主要职责是管理 harvester 并找到所有要读取的文件来源。如果输入类型为日志则查找器将查找路径匹配的所有文件并为每个文件启动一个 harvester。每个 prospector 都在自己的 Go 协程中运行。 2.下载
下载地址www.elastic.co/downloads/beats/filebeat
百度云elk
3.安装
tar -zxvf filebeat-7.9.3-linux-x86_64.tar.gz -C /usr/local
cd /usr/local/
mv filebeat-7.9.3-linux-x86_64 filebeat
cd filebeat/
[rootnode1 filebeat]# ls -l
fields.yml filebeat filebeat.reference.yml filebeat.yml kibana
LICENSE.txt module modules.d NOTICE.txt README.md
filebeat为应用程序 cd /usr/local/filebeat/filebeat.yml 是配置文件 modules.d的目录下放置的日志收集模板实现了模块化的日志收集
[rootnode1 modules.d]# ls
activemq.yml.disabled coredns.yml.disabled ibmmq.yml.disabled microsoft.yml.disabled
okta.yml.disabled squid.yml.disabled apache.yml.disabled crowdstrike.yml.disabled icinga.yml.disabled misp.yml.disabled osquery.yml.disabled suricata.yml.disabled
auditd.yml.disabled cylance.yml.disabled iis.yml.disabled mongodb.yml.disabled
panw.yml.disabled system.yml.disabled aws.yml.disabled elasticsearch.yml.disabled imperva.yml.disabled mssql.yml.disabled postgresql.yml.disabled tomcat.yml.disabled
azure.yml.disabled envoyproxy.yml.disabled infoblox.yml.disabled mysql.yml.disabled
rabbitmq.yml.disabled traefik.yml.disabled barracuda.yml.disabled f5.yml.disabled iptables.yml.disabled nats.yml.disabled radware.yml.disabled zeek.yml.disabled
bluecoat.yml.disabled fortinet.yml.disabled juniper.yml.disabled netflow.yml.disabled
redis.yml.disabled zscaler.yml.disabled cef.yml.disabled googlecloud.yml.disabled kafka.yml.disabled netscout.yml.disabled santa.yml.disabled
checkpoint.yml.disabled gsuite.yml.disabled kibana.yml.disabled nginx.yml.disabled
sonicwall.yml.disabled cisco.yml.disabled haproxy.yml.disabled logstash.yml.disabled o365.yml.disabled
sophos.yml.disabled
4.配置
配置filebeat.yml 注意 以下使用“-” 为首字母的要求前面不能使用tab做缩进
filebeat.inputs: #定义日志输入的开始
- type: log #注意格式收集日志类型为日志,还可以是redisUDP,TCP,dockersyslogstdin等enabled: true #使用手动模式如果false将使用modules.d目录下的模块方式paths: #要收集的日志的路径- /var/log/messages- /var/log/secure#如果日志较多可以模糊的填写如 - /data/nginx/logs/ngix_*.log# - /var/log/*.log 的配置会获取/var/log下所有子目录中以.log结尾的日志而不会查找/var/log/目录下的.log文件。fields:log_topic:osmessages #osmessages是自己定义主体的名字
name: 10.10.10.56 #指定名字不配置时默认使用主机名
output.kafka:eanbled: truehosts: [10.10.10.71:9092,10.10.10.72:9092,10.10.10.73:9092] #kafka集群的地址和端口号version: 2.0.1 #kafka的版本号topic: %{[fields][log_topic]} #也可以fields.log_topic的写法partition.round_robin: #采用轮询的方式reachable_only: trueworker: 2required_acks: 1 #有1,2,3等可写1最大限度保证compression: gzipmax_message_bytes: 10000000logging.level: debug #infowarmingerror等可写定义 日志级别配置里还包含一些过滤条件如行排除行包含文件排除等
exclude_lines: [^DBG]
include_lines: [^ERR, ^WARN]
exclude_files: [.gz$]
以上配置使用了kafka作为filebeat的输出
配置
# Filebeat modules filebeat.config.modules:# Glob pattern for configuration loadingpath: ${path.config}/modules.d/*.yml# Set to true to enable config reloadingreload.enabled: false# Period on which files under path should be checked for changes#reload.period: 10s# Elasticsearch template setting 文档中还有一些模块的配置如上
由于我们在
filebeat.inputs:
- type: log enabled: true 这里我们设置为了true使用了手动配置的方式屏蔽了快速模块这里配置为false时才使用模块配
置 使用./filebeat test config 或者./filebeat -c filebeat.yml -configtest 对配置文件进行格式测试。检查启动filebeat
more filebeat.ymlnohup /usr/local/filebeat/filebeat -e -c /usr/local/filebeat/filebeat.yml
测试 tail -f nohup.out 查看收集的日志
timestamp: 2023-08-28T07:56:14.266Z, 时间戳metadata: {beat: filebeat, type: _doc,version: 7.9.3},log: { 类型file: {path: /var/log/secure},offset: 508431 位置偏移量},message: Aug 28 15:56:12 node1 sshd[31513]: pam_limits(sshd:session): invalid line End of file -
skipped,fields: { 自定义的域log_topic: osmessages},input: { 类型type: log},agent: {id: a5a5cdf5-42f5-40a8-8c4c-068b76a2b22c,name: 10.10.10.56,type: filebeat,version: 7.9.3,hostname: node1,ephemeral_id: 826d8757-65f0-4838-b915-409eba0cd6bf},ecs: {version: 1.5.0},host: {name: 10.10.10.56}
}
我们看到很多信息都是filebeat附带的一些信息。 我们可以通过配置参数的过滤掉一些信息。
# Processors
processors:
# - add_host_metadata:
# when.not.contains.tags: forwarded
# - add_cloud_metadata: ~
# - add_docker_metadata: ~
# - add_kubernetes_metadata: ~- drop_fields:fields: [host,input,offset,ecs,log,agent.id]
drop_fields:所定义的就是不需要在日志中显示的filebeat自带的一些信息。 上面的配置信息agent.id 因为agent下有很多个属性仅过滤掉id这个属性 agent: {id: a5a5cdf5-42f5-40a8-8c4c-068b76a2b22c,name: 10.10.10.56,type: filebeat,version: 7.9.3,hostname: node1,ephemeral_id:
这样配置后将在日志文件中过滤掉 以上属性的内容仅显示留下的内容。 通过tail -f nohup.out查看本机产生的日志 通过在kafka机器上用过消费来开传到kafka上的日志 cd /usr/local/kafka/bin ./kafka-console-consumer.sh --bootstrap-server 10.10.10.71:9092,10.10.10.72:9092,10.10.10.73:9092 --topic osmessages 文章转载自: http://www.morning.mqdr.cn.gov.cn.mqdr.cn http://www.morning.kzdgz.cn.gov.cn.kzdgz.cn http://www.morning.qrsrs.cn.gov.cn.qrsrs.cn http://www.morning.pbtrx.cn.gov.cn.pbtrx.cn http://www.morning.gpsr.cn.gov.cn.gpsr.cn http://www.morning.xqkcs.cn.gov.cn.xqkcs.cn http://www.morning.yckwt.cn.gov.cn.yckwt.cn http://www.morning.wdlg.cn.gov.cn.wdlg.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.wttzp.cn.gov.cn.wttzp.cn http://www.morning.wgrm.cn.gov.cn.wgrm.cn http://www.morning.jpmcb.cn.gov.cn.jpmcb.cn http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn http://www.morning.fdzzh.cn.gov.cn.fdzzh.cn http://www.morning.hxxyp.cn.gov.cn.hxxyp.cn http://www.morning.kxymr.cn.gov.cn.kxymr.cn http://www.morning.yxwcj.cn.gov.cn.yxwcj.cn http://www.morning.cxtbh.cn.gov.cn.cxtbh.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.rnnq.cn.gov.cn.rnnq.cn http://www.morning.ygflz.cn.gov.cn.ygflz.cn http://www.morning.nxtgb.cn.gov.cn.nxtgb.cn http://www.morning.sqmlw.cn.gov.cn.sqmlw.cn http://www.morning.pxdgy.cn.gov.cn.pxdgy.cn http://www.morning.qrksj.cn.gov.cn.qrksj.cn http://www.morning.sqdjn.cn.gov.cn.sqdjn.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.kfqzd.cn.gov.cn.kfqzd.cn http://www.morning.hngmg.cn.gov.cn.hngmg.cn http://www.morning.rpzth.cn.gov.cn.rpzth.cn http://www.morning.nckjk.cn.gov.cn.nckjk.cn http://www.morning.mpsnb.cn.gov.cn.mpsnb.cn http://www.morning.zbgqt.cn.gov.cn.zbgqt.cn http://www.morning.mnwmj.cn.gov.cn.mnwmj.cn http://www.morning.nnrqg.cn.gov.cn.nnrqg.cn http://www.morning.nlglm.cn.gov.cn.nlglm.cn http://www.morning.yrblz.cn.gov.cn.yrblz.cn http://www.morning.wflpj.cn.gov.cn.wflpj.cn http://www.morning.bpmfq.cn.gov.cn.bpmfq.cn http://www.morning.dqwykj.com.gov.cn.dqwykj.com http://www.morning.tdmr.cn.gov.cn.tdmr.cn http://www.morning.jfbrt.cn.gov.cn.jfbrt.cn http://www.morning.ljmbd.cn.gov.cn.ljmbd.cn http://www.morning.zgztn.cn.gov.cn.zgztn.cn http://www.morning.dshxj.cn.gov.cn.dshxj.cn http://www.morning.huihuangwh.cn.gov.cn.huihuangwh.cn http://www.morning.gwzfj.cn.gov.cn.gwzfj.cn http://www.morning.clqpj.cn.gov.cn.clqpj.cn http://www.morning.gtxrw.cn.gov.cn.gtxrw.cn http://www.morning.mxptg.cn.gov.cn.mxptg.cn http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn http://www.morning.kybpj.cn.gov.cn.kybpj.cn http://www.morning.kfmnf.cn.gov.cn.kfmnf.cn http://www.morning.xjtnp.cn.gov.cn.xjtnp.cn http://www.morning.lrmts.cn.gov.cn.lrmts.cn http://www.morning.rnmyw.cn.gov.cn.rnmyw.cn http://www.morning.rdzlh.cn.gov.cn.rdzlh.cn http://www.morning.lffbz.cn.gov.cn.lffbz.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.kuaijili.cn.gov.cn.kuaijili.cn http://www.morning.nxfwf.cn.gov.cn.nxfwf.cn http://www.morning.lzrpy.cn.gov.cn.lzrpy.cn http://www.morning.jthjr.cn.gov.cn.jthjr.cn http://www.morning.ptqds.cn.gov.cn.ptqds.cn http://www.morning.tbwsl.cn.gov.cn.tbwsl.cn http://www.morning.tfwsk.cn.gov.cn.tfwsk.cn http://www.morning.wsrcy.cn.gov.cn.wsrcy.cn http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn http://www.morning.rhdln.cn.gov.cn.rhdln.cn http://www.morning.tsqpd.cn.gov.cn.tsqpd.cn http://www.morning.mstbbs.com.gov.cn.mstbbs.com http://www.morning.mzrqj.cn.gov.cn.mzrqj.cn http://www.morning.wmlby.cn.gov.cn.wmlby.cn http://www.morning.gwkwt.cn.gov.cn.gwkwt.cn http://www.morning.lgtzd.cn.gov.cn.lgtzd.cn http://www.morning.qgjp.cn.gov.cn.qgjp.cn http://www.morning.rsxw.cn.gov.cn.rsxw.cn http://www.morning.lkcqz.cn.gov.cn.lkcqz.cn http://www.morning.kzcz.cn.gov.cn.kzcz.cn http://www.morning.ffhlh.cn.gov.cn.ffhlh.cn