3.2实验filebeat->logstash->es

简单实验:filebeat->logstash

filebeat配置:

cd /usr/local/filebeat/

cp filebeat.yml filebeat2.yml

vim filebeat2.yml

复制代码
filebeat.inputs:
- type: log
  paths:
    - /var/log/httpd/access_log

output.logstash:
  hosts: ["192.168.148.131:5044"]

./filebeat -c filebeat2.yml &

logstash配置:

vim /usr/local/logstash/config/logstash-filebeat.conf

复制代码
input {
    beats {
        port => 5044
        codec => json
    }
}
output {
    stdout {}
}

logstash -f /usr/local/logstash/config/logstash-filebeat.conf

curl 192.168.148.131:80 访问httpd测试

复杂实验:filebeat->logstash->es并采集多个日志

##用field和if、elif

filebeat配置:

cd /usr/local/filebeat/

cp filebeat.yml filebeat3.yml

vim filebeat3.yml

grep -vE "^$|^[[:space:]]*#" filebeat3.yml

复制代码
filebeat.inputs:
- type: log
  paths:
    - /var/log/httpd/access_log
  fields:
    filetype: web                              # 用于区别不同的日志
  fields_under_root: true                   # 将自定义字段置于顶层

- type: log
  paths:
    - /var/log/secure
  fields:
    filetype: sys
  fields_under_root: true

output.logstash:
  hosts: ["192.168.148.131:5044"]

./filebeat -c filebeat3.yml &

logstash配置:

vim /usr/local/logstash/config/logs.conf

复制代码
input {
    beats {
        port => 5044
     }
}

filter {
    if [filetype] == "web" {
        grok {
            match => {
                "message" => "%{COMBINEDAPACHELOG}"
            }
            remove_field => ["message","beat","offset","tags","prospector"]
        }
    }
}

output {
    if [filetype] == "web" {
        elasticsearch {
            hosts => ["192.168.148.132:9200"]
            index => "http-%{+YYYY.MM.dd}"
        }
    } 
    else if [filetype] == "sys" {
        elasticsearch {
            hosts => ["192.168.148.132:9200"]
            index => "syslog-%{+YYYY.MM.dd}"
        }
    }
}

logstash -f /usr/local/logstash/config/logs.conf

curl 192.168.148.132:9200/_cat/indices? #测试查看

相关推荐
测试开发Kevin44 分钟前
详解Jenkins Pipeline 中git 命令的使用方法
运维·jenkins
什么半岛铁盒1 小时前
Linux线程与进程关系及底层实现
java·linux·运维
langmeng1101 小时前
使用docker在3台服务器上搭建基于版本redis 6.x的一主两从模式
运维·redis·docker·容器·集群
jllllyuz2 小时前
如何为服务器生成TLS证书
运维·服务器·数据库
简朴-ocean2 小时前
如何删除linux空的文件夹
linux·运维·服务器
rit84324992 小时前
ELK实现nginx、mysql、http的日志可视化实验
mysql·nginx·elk
leblancAndSherry2 小时前
Gitlab + Jenkins 实现 CICD
linux·运维·docker·kubernetes·gitlab·jenkins
半桔3 小时前
【Linux手册】探秘系统世界:从用户交互到硬件底层的全链路工作之旅
linux·运维·服务器·面试·centos
wanhengidc3 小时前
服务器中CC攻击的特点有哪些?
运维·服务器
小杜的生信筆記3 小时前
生信服务器 | 做生信为什么推荐使用Linux服务器?
linux·运维·服务器