官网下载filebeat

下载及介绍,略。注意,保持fielbeat和es的版本一致,否则可能会报错。

配置filebeat.yml

主要是:

日志文件路径

单条日志多行合并

kibana和es连接

可以参考官网:https://www.elastic.co/guide/en/beats/filebeat/6.3/index.html

下面是我的配置:

###################### Filebeat Configuration Example ########################## This file is an example configuration file highlighting only the most common
# options. The filebeat.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/filebeat/index.html# For more available modules and options, please see the filebeat.reference.yml sample
# configuration file.#=========================== Filebeat inputs =============================filebeat.inputs:# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.- type: logenabled: truepaths:- /xxx/*/*/*.log- /xxx/xxx/*/*/*.log# exclude_files: ['/home/zile/prod-log/gateway/*/*/*/*']ignore_older: 12htail_files: false# Optional additional fields. These fields can be freely picked# to add additional information to the crawled log files for filtering### Multiline options 多行处理,匹配以日期开头的multiline.pattern: ^\[?\d{4}\-\d{2}\-\d{2}multiline.negate: truemultiline.match: after#============================== Kibana =====================================# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:# Kibana Host# Scheme and port can be left out and will be set to the default (http and 5601)# In case you specify and additional path, the scheme is required: http://localhost:5601/path# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601host: "https://xxxxx:5601"username: "xxx"password: "xxxx"#================================ Outputs =====================================# Configure what output to use when sending the data collected by the beat.#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:# Array of hosts to connect to.hosts: ["xxxx:9200"]# Optional protocol and basic auth credentials.protocol: "http"username: "xxx"password: "xxx"# 配置es数据预处理管道,这个可以稍后配置pipeline: log-pipe# ......

启动filebeat

debug启动filebeat看看,能否正常运行:

./filebeat -e -d “*"

根据输出信息,可以方便的排查问题。

配置es管道,对日志数据进行预处理

在日志发送到es之前,利用es的管道提前预处理,分离一些字段出来,方便后续的检索

官方文档参考:https://www.elastic.co/guide/en/elasticsearch/reference/6.3/ingest.html

定义管道:kibana开发者工具

grok定义要匹配的日志格式

# set pipeline for common
# <pattern>[%d{yyyy-MM-dd HH:mm:ss:SSS}] [ai-course] [%level] [%thread] [%F.%M:%L] - %msg%n</pattern>
# <pattern>[%d{yyyy-MM-dd HH:mm:ss:SSS}] [ai-course] %level - %msg%n</pattern>
PUT _ingest/pipeline/log-pipe
{"description" : "for log","processors": [{"grok": {"field": "message”,"patterns": ["""\[%{TIMESTAMP_ISO8601:log_time}\] \[%{NOTSPACE:server}\] \[%{LOGLEVEL:log_level}\] \[%{NOTSPACE:thread}\] \[%{NOTSPACE:java_class}\] - %{GREEDYDATA:content}""","""\[%{TIMESTAMP_ISO8601:log_time}\] \[%{NOTSPACE:server}\] %{LOGLEVEL:log_level} - %{GREEDYDATA:content}"""],"ignore_failure": true}},{"date": {"field": "log_time","formats": ["yyyy-MM-dd HH:mm:ss:SSS"],"timezone": "Asia/Shanghai","target_field": "@timestamp","ignore_failure": true}}]
}

稳定运行

参考之前的博客,supervisor运行elastic search:
https://blog.csdn.net/Ayhan_huang/article/details/100096183

supervisor的安装可以参考:

centos 7上的仓库没有supervirosr,需要先安装 EPEL Repository

https://cloudwafer.com/blog/how-to-install-and-configure-supervisor-on-centos-7/

supervisor使用参考:https://blog.csdn.net/Ayhan_huang/article/details/79023553

确保filebeat的运行用户对filebeat目录拥有权限

supervisor配置完成后,执行以下命令:让配置生效并运行

systemctl daemon-reload
systemctl restart supervisord

可以通过supervisorctl status查看filebeat进程的运行情况

定期清除es中的过期日志索引

默认情况下,filebeat按天创建索引,如果日志量很多的话,会占用es大量存储空间,可以考虑定时删除较早的日志

这里用python脚本配合Linux定时任务来搞定:

Linux定时任务参考:https://blog.csdn.net/Ayhan_huang/article/details/72833436

下面是我的python脚本,主要是利用es的如下两个接口:

  • get _cat/indices 获取索引
  • delete /index_name 删除索引
"""
检查ES日志索引,并自动删除3天前的索引,如果不足3个,不删除
"""
import re
import requestsHOST = "xxxx:9200"
USERNAME = "xx"
PASSWORD = "xxx"
LOG_KEEP_DAYS = 3URL = f"http://{USERNAME}:{PASSWORD}@{HOST}"# 获取索引:
# https://www.elastic.co/guide/en/elasticsearch/reference/6.3/cat-indices.html
res = requests.get(f"{URL}/_cat/indices/filebeat*?v&s=index")
indices = re.findall(r"(filebeat.*?)\s", res.text)if len(indices) <= LOG_KEEP_DAYS:exit(0)# 将索引按照日期排序
indices.sort()
print("logs:")
print(indices)"""
自然排序后结果示例:
[
'filebeat-6.3.2-1020.11.26',
'filebeat-6.3.2-2019.12.28',
'filebeat-6.3.2-2020.01.31',
'filebeat-6.3.2-2020.11.27',
'filebeat-6.3.2-2020.12.01',
'filebeat-6.3.2-2021.01.01'
]
"""# 保留最近3天的日志,更早的删除
dropped_indices = indices[0: len(indices) - LOG_KEEP_DAYS]
print("del logs:")
print(dropped_indices)# 删除索引:
# https://www.elastic.co/guide/en/elasticsearch/reference/6.3/indices-delete-index.html
dropped_indices_str = ','.join(dropped_indices)
res = requests.delete(f"{URL}/{dropped_indices_str}")
print(res.text)

filebeat + es 日志分析相关推荐

  1. CentOS 6.8下ELK+filebeat+redis 日志分析平台

    转载来源 :ELK+filebeat+redis 日志分析平台 :https://www.jianshu.com/p/bf2793e85d18 一.简介 ELK Stack是软件集合Elasticse ...

  2. ELK+Filebeat+Kafka+ZooKeeper 构建海量日志分析平台(elk5.2+filebeat2.11)

    ELK+Filebeat+Kafka+ZooKeeper 构建海量日志分析平台 参考:http://www.tuicool.com/articles/R77fieA 我在做ELK日志平台开始之初选择为 ...

  3. Filebeat+Kafka+Logstash+Elasticsearch+Kibana 构建日志分析系统

    文章目录 一.前言 二.背景信息 三.操作流程 四.准备工作 1.Docker 环境 2.Docker Compose 环境 3.版本准备 4.环境初始化 5.服务安装 6.服务设置 五.配置 Fil ...

  4. 小白玩大数据日志分析系统经典入门实操篇FileBeat+ElasticSearch+Kibana 实时日志系统搭建从入门到放弃

    大数据实时日志系统搭建 距离全链路跟踪分析系统第二个迭代已经有一小阵子了,由于在项目中主要在写ES查询\Storm Bolt逻辑,都没有去搭建实时日志分析系统,全链路跟踪分析系统采用的开源产品组合为F ...

  5. 日志分析管理系统ELK+redis+filebeat搭建

    日志分析平台建设方案 1.建设原因 日志文件分散在各个应用服务器,人员需要远程登录才能查看日志,不利于服务器安全管控,加大服务器的风险 各服务器日志配置不统一,分布杂乱,需要进行规范与管理 日志文件信 ...

  6. ELK日志分析平台(三)— kibana数据可视化、kibana监控、采集日志插件filebeat

    1.kibana数据可视化--日志分析 [root@foundation50 network-scripts]# cd /mnt/pub/docs/elk/7.6/ [root@foundation5 ...

  7. 日志分析系统ELK之Kibana、es的替代metricbeat

    Kibana Kibana简介 怎么将数据导入kibana 演示环境 kibana安装与配置 可视化现有 Elasticsearch 索引中的数据 创建索引 创建可视化仪表盘图 创建可视化垂直条形图 ...

  8. ELK+FileBeat日志分析系统

    日志分析系统重新构建了一下,选定的技术方案是ELK,也就是ElasticSearch, LogStash,Kibana.另外加了Filebeat和Kafka 2017.06.28 这两天稍微清闲一些, ...

  9. golang 日志分析_容器日志采集利器:Filebeat深度剖析与实践

    在云原生时代和容器化浪潮中,容器的日志采集是一个看起来不起眼却又无法忽视的重要议题.对于容器日志采集我们常用的工具有filebeat和fluentd,两者对比各有优劣,相比基于ruby的fluentd ...

最新文章

  1. 常量元素记忆口诀_化学口诀表:帮助学生加深记忆提高解题正确率
  2. Kettle日常使用汇总整理
  3. Linux环境上的图形化界面SVN客户端软件“RabbitVCS”
  4. wxpython使用matplot_测试怎么将MatPlotLib嵌入到wxPython中
  5. php导出数据库的指定表数据,MYSQL教程mysql数据库导出指定表数据的方法
  6. android自定义表盘部件,Android自定义view仿支付宝芝麻信用表盘
  7. Java lambda expression
  8. [深度学习]生成对抗网络的实践例子
  9. Helm 3 完整教程(九):Helm 函数讲解(3)类型转换函数、正则表达式函数
  10. oracle apache服务占用80端口
  11. 梯度下降(一)--机器学习
  12. Hadoop学习之web查看HADOOP以及文件的上传和下载
  13. 数字图像处理-直方图均衡化,直方图规定化
  14. 致加西亚的信 名言佳句
  15. 吴恩达机器学习打卡day6
  16. 工作中PUSH用到的统计命令
  17. iOS 防键盘遮挡
  18. 【特征提取】|TSE
  19. 工作十年之感悟 -- 兼谈生活与人生
  20. scratch四级考纲

热门文章

  1. C语言重难点:大端小端
  2. USACO-Section1.4 Ski Course Design (枚举)
  3. Linux之CPU物理核与逻辑核
  4. python判断进程是否存在
  5. List of Javascript Library / Ajax Framework / Web Application Framework
  6. JavaScript常用算法
  7. 企业建立私有云的N个理由
  8. Java—集合框架List
  9. js中setAttribute 的兼容性
  10. Oracle 不同故障的恢复方案