• 为什么写博客,是因为遇到的坑,不希望别人在踩一遍!
  • 选择了,剩下的就是坚持和努力-------致自己!
  • 当能力达不到梦想时,更需要学习,努力,拼搏

ELK5系列日志收集平台(八) Filebeat 收集日志

ELK 雪豹 6年前 (2018-02-11) 674次浏览 0个评论

images

1.1 filebeat 简介

filebeat 是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门周几日志。

网址:https://www.elastic.co/downloads/beats/filebeat

images

https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.5.2-x86_64.rpm

1.1 yum安装

[root@elk1 tools]# yum install https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.4.1-x86_64.rpm -y

8.2.1 查看目录结构

[root@elk1 filebeat]# cd /etc/filebeat/
[root@elk1 filebeat]# ls -l
总用量 136
-rw-r--r-- 1 root root   381 9月   4 17:21 @
-rw-r--r-- 1 root root 37819 5月  29 23:58 filebeat.full.yml
-rw-r--r-- 1 root root 24203 5月  29 23:58 filebeat.template-es2x.json
-rw-r--r-- 1 root root 19419 5月  29 23:58 filebeat.template-es6x.json
-rw-r--r-- 1 root root 19467 5月  29 23:58 filebeat.template.json
-rw-r--r-- 1 root root   120 9月   1 14:20 filebeat.txt
-rwx--x--x 1 root root  4306 9月   4 21:32 filebeat.yml
-rw------- 1 root root  4196 9月   1 14:21 filebeat.yml_back
-rwxr-xr-x 1 root root  4319 9月   4 20:56 filebeat.yml.rpmsave

8.3 测试文件并输出写到本地文件(测试用)

[root@elk1 filebeat]# egrep -v "#|^$" filebeat.yml
filebeat.prospectors:
- input_type: log
  paths:
    - /var/log/messages
  exclude_lines: ["^DBG","^$"]
  document_type: system-test
output.file:
  path: "/home/yunwei/tools"
  name: "filebeat.txt

提示:其中注意
1、exclude_lines: [“^DBG”,”^$”]为取消空格
2、document_type: system-test 备注名,
3、output 输出在/home/yunwei/tools 下创建一个filebeat_test.txt
4、一定要记得在output中需要空一个格子,不然报错(这是个坑,如下图)

images

1.1 filebeat 写入 logstash 中

# 查看配置文件

[root@elk2 tools]# cat /etc/filebeat/filebeat.yml 
filebeat.prospectors:
- input_type: log
  paths:
    - /home/yunwei/tools/test.log
  exclude_lines: ["^DBG","^$"]
  document_type: system-log-21
output.logstash:
#logstash 服务器地址
  hosts: ["172.16.1.21:5044"]  
#是否开启输出到logstash
  enadled: true 
#工作线程数
  worker: 2
#压缩级别
  compression_level: 3

8.5 filebeat 写入redis中

8.5.1 #查看配置文件

[root@elk2 filebeat]# cat /etc/filebeat/filebeat.yml 
filebeat.prospectors:
- input_type: log
  paths:
    - /var/log/messages
  exclude_lines: ["^DBG","^$"]
  document_type: system-log-62
output.redis:
  hosts: "172.16.1.61"
  db: "3"
  port: "6379"
  key: "system-log-test"

#提示:修改后记得重启filebeat
[root@elk2 filebeat]# /etc/init.d/filebeat restart

8.5.2 登录到redis中查看

[root@elk2 ~]# redis-cli 
127.0.0.1:6379> key *
#切换到
127.0.0.1:6379> SELECT 3
OK
127.0.0.1:6379[3]> keys *
(empty list or set)
#通过echo 测试数据到 /var/log/messages
[root@elk2 ~]# echo "redis" >>/var/log/messages
[root@elk2 ~]# echo "redis" >>/var/log/messa
8.5.3 #在此查看redis
127.0.0.1:6379[3]> keys *
1) "system-log-test"

有需要可以联系微信xuebao19930721和加入微信群
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址