Filebeat 日志收集
Filebeat 介绍
Filebeat 安装
# 上传代码包
[root@redis03 ~]# rz filebeat-6.6.0-x86_64.rpm
# 安装
[root@redis03 ~]# rpm -ivh filebeat-6.6.0-x86_64.rpm
Filebeat 配置
# Filebeat 配置文件
[root@redis03 ~]# rpm -qc filebeat
/etc/filebeat/filebeat.yml
Filebeat 日志
# Filebeat 日志位置
[root@web01 ~]# tail -f -n 100 /var/log/filebeat/filebeat
Log-file => Filebeat => File
编辑配置文件
# 备份原始配置文件
[root@redis03 ~]# cp /etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml.bak
# 配置
[root@web01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
output.file:
path: "/tmp"
filename: "filebeat.log"
启动 Filebeat
[root@m01 ~]# systemctl start filebeat.service
# 验证
[root@m01 ~]# ps -ef | grep filebeat
root 3415 1 0 11:04 ? 00:00:00 /usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat.yml -path.home /usr/sharefilebeat -path.config /etc/filebeat -path.data /var/lib/filebeat -path.logs /var/log/filebeat
root 3434 125832 0 11:04 pts/0 00:00:00 grep --color=auto filebeat
访问目录测试
# 访问 nginx 以后,查看 /tmp目录下
[root@web01 ~]# ll /tmp/
total 52
-rw------- 1 root root 3037 May 25 11:08 filebeat.log
Log-file => Filebeat => ElasticSearch
编辑配置文件
[root@web01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
output.elasticsearch:
hosts: ["10.0.0.121:9200"]
重启 Filebeat
[root@web01 ~]# systemctl restart filebeat.service
访问页面测试
Filebeat 收集日志格式设置(JSON)
编辑配置文件
[root@m01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
output.elasticsearch:
hosts: ["10.0.0.121:9200"]
# keys_under_root
默认情况下,解码后的 JSON 放在输出文档中的 “json” 键下。 如果启用此设置,则会将键复制到输出文档的顶层。 默认值是 false
# overwrite_keys
如果启用了 keys_under_root 和此设置,则来自解码的JSON对象的值会覆盖 Filebeat 通常添加的字段(类型,源,偏移量等)以防冲突
配置 Nginx 日志格式
[root@m01 ~]# vim /etc/nginx/nginx.conf
........
log_format json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"status":"$status"}';
access_log /var/log/nginx/access.log json;
........
# 上面的 Nginx 日志格式,某些情况,无法收集到 ElasticSearch 数据库中
# 如果 ElasticSearch 数据库中,只出现了索引,但不能够收集到日志数据,试试改成下面的 Json 格式
[root@m01 ~]# vim /etc/nginx/nginx.conf
........
log_format json '{ "time_local": "$time_local", '
'"remote_addr": "$remote_addr", '
'"referer": "$http_referer", '
'"request": "$request", '
'"status": $status, '
'"bytes": $body_bytes_sent, '
'"agent": "$http_user_agent", '
'"x_forwarded": "$http_x_forwarded_for", '
'"up_addr": "$upstream_addr",'
'"up_host": "$upstream_http_host",'
'"upstream_time": "$upstream_response_time",'
'"request_time": "$request_time" }';
access_log /var/log/nginx/access.log json;
........
# 删除原来的索引,重启 nginx
[root@m01 ~]# systemctl reload nginx
访问页面测试
Log-file => Filebeat => ElasticSearch(指定索引)
编辑配置文件
[root@m01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
output.elasticsearch:
hosts: ["10.0.0.121:9200"]
index: "nginx-%{+yyyy.MM.dd}"
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
setup.template.overwrite: false
setup.template.enabled: false
#============== 参数说明 ================#
# 模板的名称
setup.template.name: "nginx"
# 模板模式,通配符 * 用于匹配每日索引
setup.template.pattern: "nginx-*"
# 禁用模板加载
setup.template.enabled: false
# 是否覆盖现有模板(不加也可以)
setup.template.overwrite: false
重启 Filebeat
# 重启 filebeat
[root@m01 ~]# systemctl restart filebeat.service
访问页面测试
指定分片和副本数
setup.template.settings:
index.number_of_shards: 2
index.number_of_replicas: 1
Log-file => Filebeat => Redis
编辑配置文件
[root@m01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
output.redis:
hosts: ["172.16.1.121:6379"]
key: "nginx_log"
db: 0
password: 123
重启 Filebeat(略)
访问页面查看 Redis
[root@redis01 ~]# redis-cli
127.0.0.1:6379> keys *
1) "nginx_log"
127.0.0.1:6379> LLEN nginx_log
(integer) 342
127.0.0.1:6379> LRANGE nginx_log 0 -1
Redis => Logstash => ElasticSearch
[root@web01 ~]# vim /etc/logstash/conf.d/beats_redis_logstash_es.conf
input {
redis {
data_type => "list"
host => ["172.16.1.121"]
port => 6379
key => "nginx_log"
db => "0"
codec => "json"
}
}
output {
elasticsearch {
hosts => ["10.0.0.121:9200"]
index => "redis-%{+YYYY-MM-dd}"
}
}
# 运行后观察 ES-head ,若有 redis 索引及数据,成功
Log-file => Filebeat => Logstash => ElasticSearch
编辑配置文件
# 配置 filebeat
[root@web01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
output.logstash:
hosts: ["10.0.0.7:6666"]
# 配置 logstash
[root@web01 ~]# vim /etc/logstash/conf.d/beats_logstash_es.conf
input {
beats {
port => 6666
codec => "json"
}
}
output {
elasticsearch {
hosts => ["10.0.0.121:9200"]
index => "filebeat-%{+YYYY-MM-dd}"
}
}
# 运行后观察 ES-head ,若有 filebeat 索引及数据,成功
Log-flies => Filebeat => ElasticSearch(多份日志)
方法一(通过 source 字段划分)
[root@web01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enable: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
- type: log
enable: true
paths:
- /var/log/messages
output.elasticsearch:
hosts: ["10.0.0.121:9200"]
indices:
- index: "nginx_%{+YYYY-MM-dd}"
when.contains:
source: "/var/log/nginx/access.log"
- index: "message_%{+YYYY-MM-dd}"
when.contains:
source: "/var/log/messages"
setup.template.enabled: false
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
方法二(通过 tag 字段划分)
[root@web01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enable: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["nginx"]
- type: log
enable: true
paths:
- /var/log/messages
tags: ["messages"]
output.elasticsearch:
hosts: ["10.0.0.121:9200"]
indices:
- index: "nginx_%{+YYYY-MM-dd}"
when.contains:
tags: "nginx"
- index: "message_%{+YYYY-MM-dd}"
when.contains:
tags: "messages"
setup.template.enabled: false
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
Log-files => Filebeat => Redis => Logstash => ElasticSearch(多日志)
# 配置 filebeat
[root@db05 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["nginx"]
- type: log
enabled: true
paths:
- /var/log/messages
tags: ["messages"]
output.redis:
hosts: ["172.16.1.121:6379"]
password: "123"
keys:
- key: "nginx_log"
when.contains:
tags: "nginx"
- key: "messages_log"
when.contains:
tags: "messages"
db: "0"
# 配置 logstash
[root@db05 ~]# vim /etc/logstash/conf.d/redis.conf
input {
redis {
data_type => "list"
host => ["172.16.1.121"]
port => 6379
key => "nginx_log"
password => "123"
db => "0"
codec => "json"
type => "nginx"
}
redis {
data_type => "list"
host => ["172.16.1.121"]
port => 6379
key => "messages_log"
password => "123"
db => "0"
codec => "json"
type => "messages"
}
}
output {
elasticsearch {
hosts => ["10.0.0.121:9200"]
index => "%{type}-%{+YYYY-MM-dd}"
}
}
Filebeat 收集 Java 报错
# 编辑配置文件,收集 tomcat 错误日志
[root@web01 ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enable: true
paths:
- /usr/local/tomcat/logs/catalina.*.log
multiline.pattern: '^\['
multiline.negate: true
multiline.match: after
output.elasticsearch:
hosts: ["10.0.0.121:9200"]
index: "tomcat_error_%{+YYYY-MM-dd}"
setup.template.enabled: false
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
# 下载测试日志
[root@web01 ~]# wget https://www.linuxyz.top/download/software/test_log/tomcat_error.log
[root@web01 ~]# cat tomcat_error.log >> /usr/local/tomcat/logs/catalina.2019-06-12.log
Filebeat 日志收集的更多相关文章
- 【linux】【ELK】搭建Elasticsearch+Logstash+Kibana+Filebeat日志收集系统
前言 ELK是Elasticsearch.Logstash.Kibana的简称,这三者是核心套件,但并非全部. Elasticsearch是实时全文搜索和分析引擎,提供搜集.分析.存储数据三大功能:是 ...
- Filebeat 日志收集器 安装和配置
Filebeat的配置文件是/etc/filebeat/filebeat.yml,遵循YAML语法.具体可以配置如下几个项目: Filebeat Output Shipper Logging(可选) ...
- Filebeat日志收集简单使用
1.简略介绍 轻量型日志采集器,用于转发和汇总日志与文件. 官网: https://www.elastic.co/cn/beats/filebeat 2.本文实现的功能 3.事先必备: 至少一台Kaf ...
- ELK Stack 介绍 & Logstash 日志收集
ELK Stack 组成 Software Description Function E:Elasticsearch Java 程序 存储,查询日志 L:Logstash Java 程序 收集.过滤日 ...
- 快速搭建应用服务日志收集系统(Filebeat + ElasticSearch + kibana)
快速搭建应用服务日志收集系统(Filebeat + ElasticSearch + kibana) 概要说明 需求场景,系统环境是CentOS,多个应用部署在多台服务器上,平时查看应用日志及排查问题十 ...
- CentOS7下 简单安装和配置Elasticsearch Kibana Filebeat 快速搭建集群日志收集平台
目录 1.添加elasticsearch官网的yum源 2.Elasticsearch 安装elasticsearch 配置elasticsearch 启动elasticsearch并设为开机启动 3 ...
- FILEBEAT+ELK日志收集平台搭建流程
filebeat+elk日志收集平台搭建流程 1. 整体简介: 模式:单机 平台:Linux - centos - 7 ELK:elasticsearch.logstash.kiban ...
- 日志分析平台ELK之日志收集器filebeat
前面我们了解了elk集群中的logstash的用法,使用logstash处理日志挺好的,但是有一个缺陷,就是太慢了:当然logstash慢的原因是它依赖jruby虚拟机,jruby虚拟机就是用java ...
- 日志收集之filebeat使用介绍
此系列文章一共分为三部分,分为filebeat部分,logstash部分,es部分.这里会按照每天几百亿条的数据量来考虑,去设计.部署.优化这个日志系统,来最大限度的利用资源,并达到一个最优的性能.本 ...
随机推荐
- kubernets之向外部应用暴露应用
一 通过NodePort来暴露服务 前面已经介绍的服务的一些作用,例如将集群内部的应用暴露给集群内部的pod使用,将外部的应用通过服务暴露给内部应用使用,但是服务最大的作用不仅仅是这些 而是将集群内 ...
- SDUST数据结构 - chap4 串
函数题: 6-1 查找子串: 裁判测试程序样例: #include <stdio.h> #define MAXS 30 char *search(char *s, char *t); vo ...
- ctfhub技能树—信息泄露—备份文件下载—网站源码
打开靶机 查看网页内容 使用dirsearch进行扫描 命令如下 python3 dirsearch.py -u http://challenge-91f1f5e6a791ab02.sandbox.c ...
- Java中的NIO进阶
目录 前言 NIO与多线程 Readable和Writeable的空触发 请求与返回的处理 事件的处理机制 NIO多线程使用的一个例子 前言 之前一篇文章简单介绍了NIO,并附了一个简单的例子,但是自 ...
- Linux设置开机自动挂载镜像文件
1.将文件上传到服务器上(本例上传到/Data/software下) 2.挂载 mount -o loop /Data/software/rhel-server-7.6-x86_64-dvd.iso ...
- 1.2V升压到3V和3.3V的升压芯片
1.2V镍氢电池升压到3V和3.3V输出,1.2V升压3V,1.2V升压3.3V稳压输出供电的芯片. PW5100 是一款低静态电流.达效率. PFM 模式控制的同步升压变换器. PW5100 所需的 ...
- 阿里云VPC网络内网实例通过SNAT连接外网
场景: 1.有多个ECS实例,其中A实例有公网IP,可以上外网 其它实例没有公网IP,不能上外网 2.所有实例在一个交换机,也就是一个网络(172.16.0.0/16) 实例 内网IP 外网IP A ...
- winform 窗体中顶部标题居中显示
在网上看了很多例子,都不能居中,都有或多或少的问题 自己根据网友的代码改编入下: 先确随便写一个标题的内容: string titleMsg ="Winfrom Title" 获取 ...
- 时序数据库 Apache-IoTDB 源码解析之元数据索引块(六)
上一章聊到 TsFile 索引块的详细介绍,以及一个查询所经过的步骤.详情请见: 时序数据库 Apache-IoTDB 源码解析之文件索引块(五) 打一波广告,欢迎大家访问 IoTDB 仓库,求一波 ...
- HMS Core华为分析丨受众细分,多场景促进精益运营
用户的偏好不同,对产品的需求也不一样,要想更好地培养用户粘性,就需要因人施策,精细化运营,而受众细分是精细化运营的重要方法之一.受众细分是根据用户属性和行为数据,将具有相同或类似特征的用户归为一个群组 ...