设为首页 收藏本站
查看: 1432|回复: 0

[经验分享] EFK之filebeat线上使用方法个人线上应用及参考地址

[复制链接]

尚未签到

发表于 2019-1-29 14:01:42 | 显示全部楼层 |阅读模式
  Filebeat是一个轻量级的托运人,用于转发和集中日志数据。Filebeat作为代理安装在服务器上,监视您指定的日志文件或位置,收集日志事件,并将它们转发到Elasticsearch或 Logstash进行索引。
  以下是Filebeat的工作原理:启动Filebeat时,它会启动一个或多个输入,这些输入将查找您为日志数据指定的位置。对于Filebeat找到的每个日志,Filebeat启动一个收集器。每个收集器为新内容读取单个日志,并将新日志数据发送到libbeat,libbeat聚合事件并将聚合数据发送到您为Filebeat配置的输出。

  Filebeat是一个Beat,它基于libbeat框架。
  Step 1: Install Filebeat
  要下载并安装Filebeat,请使用适用于您的系统的命令:
DEB:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-amd64.deb
sudo dpkg -i filebeat-6.5.4-amd64.deb~~
  转:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-x86_64.rpm
sudo rpm -vi filebeat-6.5.4-x86_64.rpm
  苹果电脑:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-darwin-x86_64.tar.gz
tar xzvf filebeat-6.5.4-darwin-x86_64.tar.gz
  Linux的:

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.5.4-linux-x86_64.tar.gz
tar xzvf filebeat-6.5.4-linux-x86_64.tar.gz
  第二步、配置Filebeat
要配置Filebeat,请编辑配置文件。调用默认配置文件 filebeat.yml。文件的位置因平台而异。
还有一个名为的完整示例配置文件filebeat.reference.yml ,显示了所有未弃用的选项
(注意主配置文件filebeat.yml可以不唯一,启动时可以制定自己写的yml)
以下是filebeat该filebeat.yml文件部分的示例。Filebeat使用大多数配置选项的预定义默认值。

filebeat.inputs:
-  type:log
enabled:true
paths:
-
/ var / log / * 。log # -  c:\ programdata \ elasticsearch \ logs \ *
  配置Filebeat:
  定义日志文件的路径(或路径)。
  对于最基本的Filebeat配置,您可以使用单个路径定义单个输入。例如:

filebeat.inputs:
-  type:log
enabled:true
paths:
-  /var/log/*.log
  此示例中的输入收集路径中的所有文件/var/log/*.log,这意味着Filebeat将收集目录/var/log/结尾的所有文件.log。
  要从预定义级别的子目录中获取所有文件,可以使用以下模式: /var/log//.log。这.log将从子文件夹中获取所有文件/var/log。它不从/var/log文件夹本身获取日志文件。目前,无法以递归方式获取目录的所有子目录中的所有文件。
配置输出。Filebeat支持各种 输出,但通常您可以将事件直接发送到Elasticsearch,也可以发送到Logstash以进行其他处理。
  要将输出直接发送到Elasticsearch(不使用Logstash),请设置Elasticsearch安装的位置:


  • 如果您 在Elastic Cloud上运行我们 托管的Elasticsearch Service,请指定您的Cloud ID。例如:
  cloud.id:“staging:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw ==”


  • 如果您在自己的硬件上运行Elasticsearch,请设置Filebeat可以找到Elasticsearch安装的主机和端口。例如:

output.elasticsearch:
hosts:[“myEShost:9200”]
  如果您计划使用随Filebeat提供的示例Kibana仪表板,请配置Kibana端点。如果Kibana与Elasticsearch在同一主机上运行,​​则可以跳过此步骤。

setup.kibana:
host:“mykibanahost:5601”
  例如,运行Kibana的计算机的主机名和端口mykibanahost:5601。如果在端口号后面指定路径,请包括方案和端口:http://mykibanahost:5601/path
  如果要使用Logstash对Filebeat收集的数据执行其他处理,则需要配置Filebeat以使用Logstash。
第三步
要执行此操作,请编辑Filebeat配置文件以通过注释掉它来禁用Elasticsearch输出,并通过取消注释logstash部分来启用Logstash输出:
  #----------------------------- Logstash输出------------------ --------------

output.logstash:
hosts: ["127.0.0.1:5044"]
  该hosts选项指定Logstash服务器和port(5044),其中Logstash配置为侦听传入的Beats连接。
  对于此配置,您必须手动将索引模板加载到Elasticsearch中, 因为自动加载模板的选项仅适用于Elasticsearch输出。
  第四步 在elasticsearch中加载索引模板
  在Elasticsearch中,索引模板用于定义确定如何分析字段的设置和映射。
  Filebeat的推荐索引模板文件由Filebeat包安装。如果接受filebeat.yml配置文件中的默认配置,则 Filebeat会在成功连接到Elasticsearch后自动加载模板。如果模板已存在,则除非您配置Filebeat,否则不会覆盖该模板。
  配置模板加载编辑
默认情况下,fields.yml如果启用了Elasticsearch输出,Filebeat会自动加载推荐的模板文件 。如果要使用默认索引模板,则不需要其他配置。否则,您可以将filebeat.yml配置文件中的默认值更改为:


  • 加载不同的模板

setup.template.name:“your_template_name”
setup.template.fields:“path / to / fields.yml”
  如果模板已存在,则除非您配置Filebeat,否则不会覆盖该模板。


  • 覆盖现有模板
  setup.template.overwrite:true

* 禁用自动模板加载
  setup.template.enabled:false


*  更改索引名称
默认情况下,Filebeat将事件写入命名的索引 filebeat-6.5.4-yyyy.MM.dd,其中yyyy.MM.dd是事件索引的日期。要使用其他名称,请index在Elasticsearch输出中设置该 选项。您指定的值应包括索引的根名称以及版本和日期信息。您还需要配置setup.template.name和 setup.template.pattern选项以匹配新名称。例如:

  output.elasticsearch.index:“customname  - %{[beat.version]}  - %{+ yyyy.MM.dd}”
setup.template.name:“customname”
setup.template.pattern:“customname- *”

如果您使用的是预先构建的Kibana仪表板,请同时设置该 setup.dashboards.index选项。例如:
  `setup.dashboards.index:“customname- *”``


**手动加载模板编辑**
要手动加载模板,请运行该setup命令。需要连接到Elasticsearch。如果启用了另一个输出,则需要暂时​​禁用该输出并使用该-E选项启用Elasticsearch 。此处的示例假定已启用Logstash输出。-E如果已启用Elasticsearch输出,则可以省略标志。
如果要连接到安全的Elasticsearch集群,请确保已按照步骤2:配置Filebeat中所述配置凭据。
如果运行Filebeat的主机没有与Elasticsearch的直接连接,请参阅手动加载模板(备用方法)。
要加载模板,请使用适用于您系统的命令。
deb和rpm:
> filebeat setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'
苹果电脑:
> ./filebeat setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'
Linux的:
./filebeat setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'
docker:
> docker run docker.elastic.co/beats/filebeat:6.5.4 setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'
win:
以管理员身份打开PowerShell提示符(右键单击PowerShell图标,然后选择“以管理员身份运行”)。
在PowerShell提示符下,切换到Filebeat的安装目录,然后运行:
> PS>。\ filebeat.exe setup --template -E output.logstash.enabled = false -E'output.elasticsearch.hosts = [“localhost:9200”]'
强制Kibana查看最新的文档编辑
如果您已经使用Filebeat将数据索引到Elasticsearch,则索引可能包含旧文档。加载索引模板后,您可以删除旧文档filebeat-*以强制Kibana查看最新文档。
使用此命令:
deb和rpm:
> curl -XDELETE'http:// localhost:9200 / filebeat- *'
苹果电脑:
> curl -XDELETE'http:// localhost:9200 / filebeat- *'
Linux的:
> curl -XDELETE'http:// localhost:9200 / filebeat- *'
win:
> PS> Invoke-RestMethod -Method删除“http:// localhost:9200 / filebeat- *”
此命令删除与模式匹配的所有索引filebeat-*。在运行此命令之前,请确保要删除与该模式匹配的所有索引。
手动加载模板(备用方法)编辑
If the host running Filebeat does not have direct connectivity to Elasticsearch, you can export the index template to a file, move it to a machine that does have connectivity, and then install the template manually.
To export the index template, run:
deb and rpm:
> filebeat export template > filebeat.template.json
mac:
> ./filebeat export template > filebeat.template.json
linux:
> ./filebeat export template > filebeat.template.json
win:
> PS > .\filebeat.exe export template --es.version 6.5.4 | Out-File -Encoding UTF8 filebeat.template.json
> To install the template, run:
deb and rpm:
> curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-6.5.4 -d@filebeat.template.json
mac:
> curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-6.5.4 -d@filebeat.template.json
linux:
> curl -XPUT -H 'Content-Type: application/json' http://localhost:9200/_template/filebeat-6.5.4 -d@filebeat.template.json
win:
> PS > Invoke-RestMethod -Method Put -ContentType "application/json" -InFile filebeat.template.json -Uri http://localhost:9200/_template/filebeat-6.5.4
好了今天入门就到这里了,改天整理文档的时候继续。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-669255-1-1.html 上篇帖子: Centos7 之安装Logstash ELK stack 日志管理系统 下篇帖子: mysql初始化、增删改查用户、授权
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表