Technology Sharing

ELfK logstash filter module commonly used plug-ins and ELFK deployment

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Common plug-ins for ELK filter module

Commonly used plug-ins for logstash filter module:

filter: represents the data processing layer, including data formatting, data type conversion, data filtering, etc., and supports regular expressions

  1. grok splits several large text fields into several small fields (?<field name> regular expression) Field name: the content matched by the regular expression
  2. date unifies and formats the time format in the data
  3. mutate can rename, delete, replace and modify fields in events. For example, you can remove some useless fields or add custom fields.
  4. multiline unifies multiple lines of data and aggregates them into a single line

GROK: Regular Expression Capture Plugin

Use text fragment segmentation to segment log events, which are divided into built-in regular expressions and custom regular expressions.

Built-in regular expression call: %(built-in regular expression: field name)
 

Custom regular expression call: (?<field name>custom regular)

         

multiline: Unify multiple lines of data and aggregate them into a single line

pattern (match lines by regular expression)
negate (false|true, whether to negate. False means not to negate, and merge the lines matched by the regular expression according to the setting of what
True means negation, and the lines matched by the regular expression are not merged according to the setting of what)
what (previous|next, previous means upward merge, next means downward merge

date: unifies the format of the timestamp @timestamp of the log event collected by logstash and the actual printing time of the log

1. First configure the grok plug-in to split the log time and print the time field
2. Use match to match the time format of the log time field in the date plugin configuration
3. Then use target to output to the @timestamp field to unify the time format
 

ELK optimized Filebeat deployment

Host AddressnameServe
192.168.73.80es01elasticsearch
192.168.73.100es02elasticsearch
192.168.73.110es03elasticsearch
192.168.73.120ngixn01nginx kibana
192.168.73.130FILEngixn filebeat

Install NGINX

  1. cd /etc/yum.repos.d/
  2. 上传nginx.repo文件
  3. yum install -y nginx
  4. systemctl enable --now nginx
  5. cd /usr/share/nginx/html
  6. #准备测试页面
  7. echo '<h1>this is web page</h1>' > test.html
  8. echo '<h1>this is web2 page</h1>' > test1.html

Install Filebeat

  1. 上传软件包 filebeat-6.7.2-linux-x86_64.tar.gz 到/opt目录
  2. tar xf filebeat-6.7.2-linux-x86_64.tar.gz
  3. mv filebeat-6.7.2-linux-x86_64 /usr/local/filebeat

Set the main configuration file of filebeat

  1. cd /usr/local/filebeat
  2. cp filebeat.yml filebeat.yml.bak
  3. vim filebeat.yml
  4. filebeat.inputs:
  5. - type: log #指定 log 类型,从日志文件中读取消息
  6. enabled: true #24
  7. paths:
  8. - /var/log/nginx/access.log #28行指定监控的日志文件
  9. - /var/log/nginx/error.log
  10. tags: ["filebeat"] #设置索引标签
  11. fields: #46行可以使用 fields 配置选项设置一些参数字段添加到 output
  12. service_name: nginx
  13. log_from: 192.168.73.130
  14. --------------output-------------------
  15. (全部注释掉)
  16. ----------------Logstash output---------------------
  17. output.logstash: #162
  18. hosts: ["192.168.73.120:5044"] #164行指定 logstash 的 IP 和端口

Modify Logstash configuration

  1. cd /etc/logstash/conf.d
  2. vim filebeat.conf
  3. input {
  4. beats {
  5. port => "5044"
  6. }
  7. }
  8. #filter {}
  9. output {
  10. elasticsearch {
  11. hosts => ["192.168.73.80:9200", "192.168.73.100:9200", "192.168.73.110:9200"] #集群els地址
  12. index => "nginx-%{+yyyy.MM.dd}"
  13. }
  14. }
  15. logstash -t -f filebeat.conf #检查文件

Start and configure filebeat

192.168.73.130

Start ./filebeat -e -c filebeat.yml

Start logstash

192.168.73.120

Start logstashlogstash -f filebeat.conf