Fluentd直接传输日志给Elasticsearch
官方文档地址:https://docs.fluentd.org/output/elasticsearch
td-agent的v3.0.1版本以后自带包含out_elasticsearch插件,不用再安装了,可以直接使用。
若是使用的是Fluentd,则需要安装这个插件:
$ fluent-gem install fluent-plugin-elasticsearch
配置示例
<match my.logs>
@type elasticsearch
host localhost
port 9200
logstash_format true
</match>
参数说明
- @type:必填,elasticsearch
- host:可选,elasticsearch连接地址,默认是localhost
- port:可选,elasticsearch使用的端口,默认是9200
- hosts:可选,连接多个elasticsearch时使用,若是使用这个,host和port配置的则会被忽略,则用法如下:
hosts host1:port1,host2:port2,host3:port3
# or
hosts https://customhost.com:443/path,https://username:password@host-failover.com:443
- user:可选,默认nil
- password:可选,默认nil
- scheme:可选,连接协议,默认http
- path: 可选,Elasticsearch的REST API端点,用于发布写请求,默认nil
- index_name,可选,索引名称,默认fluentd,用法示例:
# index by tags
index_name fluentd.${tag}
# by tags and timestamps
# 这种形式的还需要在chunk_keys中设置tag和time,如下所示:
index_name fluentd.${tag}.%Y%m%d
<match my.logs>
@type elasticsearch
host localhost
port 9200
index_name fluentd.${tag}.%Y%m%d => fluentd.my.logs.20201105
<buffer tag,time>
timekey 1m
</buffer>
</match>
- logstash_format:可选,默认false,若为true,则索引名称格式是logstash-%Y.%m.%d,比index_name优先级高
- logstash_prefix:可选,logstash前缀索引名,用于在logstash_format为true时,默认logstash
- @log_level:可选,日志等级,参数有fatal, error, warn, info, debug, trace
其他
可以使用%{}样式占位符来转义URL编码所需的字符
比如:
# 有效配置
user %{demo+}
password %{@secret}
hosts https://%{j+hn}:%{passw@rd}@host1:443/elastic/,http://host2
# 无效配置
user demo+
password @secret
实际使用案例
收集openresty(nginx)日志
# cat /etc/td-agent/td-agent.conf
<source>
@type tail
@id input_tail
<parse>
@type nginx
</parse>
path /usr/local/openresty/nginx/logs/host.access.log
tag td.nginx.access
</source>
<match td.nginx.access>
@type elasticsearch
host localhost
port 9200
index_name fluentd.${tag}.%Y%m%d
<buffer tag,time>
timekey 1m
</buffer>
</match>


关于@type nginx日志过滤的内容
官方文档地址:https://docs.fluentd.org/parser/nginx
使用的正则表达式:
expression /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)"(?:\s+(?<http_x_forwarded_for>[^ ]+))?)?$/
time_format %d/%b/%Y:%H:%M:%S %z
remote, user, method, path, code, size, referer, agent and http_x_forwarded_for 都包含在record中,时间用于事件时间
# 日志内容
127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0" -
# 过滤后的结果
time:
1362020400 (28/Feb/2013:12:00:00 +0900)
record:
{
"remote" : "127.0.0.1",
"host" : "192.168.0.1",
"user" : "-",
"method" : "GET",
"path" : "/",
"code" : "200",
"size" : "777",
"referer" : "-",
"agent" : "Opera/12.0",
"http_x_forwarded_for": "-"
}
假设不用这个参数的话,假若删除
<parse>
@type nginx
</parse>
启动后则会报错:
<parse> section is required
只得使用none替换:
<parse>
@type none
</parse>

Fluentd直接传输日志给Elasticsearch的更多相关文章
- Fluentd直接传输日志给kafka
官方文档地址:https://docs.fluentd.org/output/kafka td-agent版本自带包含out_kafka2插件,不用再安装了,可以直接使用. 若是使用的是Fluentd ...
- Fluentd直接传输日志给MongoDB副本集 (replset)
官方文档地址:https://docs.fluentd.org/output/mongo_replset td-agent版本默认没有包含out_mongo插件,需要安装这个插件才能使用 使用的是td ...
- Fluentd直接传输日志给MongoDB (standalone)
官方文档地址:https://docs.fluentd.org/output/mongo td-agent版本默认没有包含out_mongo插件,需要安装这个插件才能使用 使用的是td-agent,安 ...
- 记一次logback传输日志到logstash根据自定义设置动态创建ElasticSearch索引
先说背景,由于本人工作需要创建很多小应用程序,而且在微服务的大环境下,服务越来越多,然后就导致日志四分五裂,到处都有,然后就有的elk,那么问题来了 不能每个小应用都配置一个 logstash 服务来 ...
- ELK系列~Fluentd对大日志的处理过程~16K
Fluentd是一个日志收集工具,有输入端和输出端的概念,前者主要是日志的来源,你可以走多种来源方式,http,forward,tcp都可以,后者输出端主要指把日志进行持久化的过程,你可以直接把它持久 ...
- log4net将日志写入ElasticSearch
log4net将日志写入ElasticSearch https://www.cnblogs.com/huangxincheng/p/9120028.html 很多小步快跑的公司,开发人员多则3-4个, ...
- 9. Fluentd部署:日志
Fluentd是用来处理其他系统产生的日志的,它本身也会产生一些运行时日志.Fluentd包含两个日志层:全局日志和插件级日志.每个层次的日志都可以进行单独配置. 日志级别 Fluentd的日志包含6 ...
- Kubernetes 集群日志管理 Elasticsearch + fluentd(二十)
目录 一.安装部署 Kubernetes 开发了一个 Elasticsearch 附加组件来实现集群的日志管理.这是一个 Elasticsearch.Fluentd 和 Kibana 的组合.Elas ...
- 关于” 记一次logback传输日志到logstash根据自定义设置动态创建ElasticSearch索引” 这篇博客相关的优化采坑记录
之前写过一篇博客是关于记录日志的简单方式的 主要就是 应用->redis->logstash->elasticsearch 整个流程的配置方法和过程的 虽然我们部分线上应用使用 ...
随机推荐
- Eolink家族成员回归 — 开源服务Eoapi!
Eolink 开源产品又回来了!Eoapi 自 2016 年上架 Github 以来,一直备受国内外开发者的欢迎和好评 ,在2018年 Eolink 为了进一步升级该产品而进行了暂时下架.时隔四年,E ...
- c语言中的gets和fgets的使用差别
gets和fgets的差别 2022年6月30日 #include<stdio.h> #include<string.h> #define STLEN 8 int main(i ...
- Python3.7+Django2.0.4配合Mongodb打造高性能高扩展标签云存储方案
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_141 书接上回,之前有一篇文章提到了标签云系统的构建:Python3.7+jieba(结巴分词)配合Wordcloud2.js来构 ...
- 霜皮剥落紫龙鳞,下里巴人再谈数据库SQL优化,索引(一级/二级/聚簇/非聚簇)原理
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_206 举凡后端面试,面试官不言数据库则已,言则必称SQL优化,说起SQL优化,网络上各种"指南"和" ...
- Linux 系统时间同步服务器配置
# Linux 时间同步 # 查看系统时间: date # 查看硬件日期 # ntp 软件 # chrony 软件 chrony比ntp更精确 # 利用ntp手动瞬间同步时间: ntpdate 172 ...
- 小白之Python基础(四)
条件判断和循环: 1.条件判断类型: 1)if语句:(注意:if中的条件如果是:非零数值.非空字符串.非空list等,就判断为True,否则为False.) 2)if-else语句: 3)if-eli ...
- Prometheus+Grafana+钉钉部署一个单机的MySQL监控告警系统
GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. GreatSQL是MySQL的国产分支版本,使用上与MySQL一致. 目录 一.Prometheus 二.exporter ...
- Linux下一键安装Python3&更改镜像源&虚拟环境管理技巧
前言 之前分享过一篇<Linux系统自带Python2&yum的卸载及重装>,介绍了如何卸载及重装Linux(CentOS)自带的的Python2.7.今天主要介绍如何在Linux ...
- 案例复现,带你分析Priority Blocking Queue比较器异常导致的NPE问题
摘要:本文通过完整的案例复现来演示在什么情况会触发该问题,同时给出了处理建议.希望读者在编程时加以借鉴,避免再次遇到此类问题. 本文分享自华为云社区<Priority Blocking Queu ...
- DolphinScheduler 集群高可用测试:有效分摊服务器压力,达到性能最大优化!
点击上方 蓝字关注我们 1 文档编写目的 Apache DolphinScheduler(简称DS)是一个分布式去中心化,易扩展的可视化DAG工作流任务调度平台.在生产环境中需要确保调度平台的稳定可靠 ...