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? #测试查看

相关推荐
但老师22 分钟前
Jenkins垃圾清理指南
java·运维·jenkins
山茶花.2 小时前
seacmsv9管理员账号+密码注入
运维
suzhou_speeder3 小时前
了解 PoE 扩展模式(Extend Mode)及其对数据速率的影响
运维·网络·交换机·poe·poe交换机
AustinCien4 小时前
1.4常规es报错问题
运维·elk·elasticsearch
DC_BLOG6 小时前
Linux-Ansible模块完结
linux·运维·服务器·ansible
WIN赢6 小时前
【Deepseek+Browser-Use搭建 Web UI自动化】
运维·自动化
DataDynamos数动实验室6 小时前
BGP状态和机制
运维·网络·计算机网络·智能路由器
A~taoker6 小时前
分享httprunner 结合django实现平台接口自动化方案
运维·自动化
Henry_Wu0016 小时前
ubuntu 安全策略(等保)
linux·运维·ubuntu