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

相关推荐
卤炖阑尾炎40 分钟前
PostgreSQL 日常运维全指南:从基础操作到备份恢复
运维·数据库·postgresql
handsomestWei1 小时前
Docker引擎API接入配置
运维·http·docker·容器·api
Tingjct1 小时前
Linux常用指令
linux·运维·服务器
daad7772 小时前
wifi_note
运维·服务器·数据库
IT界的老黄牛2 小时前
Linux 压缩命令实战:tar、gzip、bzip2、xz、zstd 怎么选?一篇讲清楚
linux·运维·服务器
12345,catch a tiger2 小时前
虚拟机ubuntu安装Vmware Tools
linux·运维·ubuntu
程序猿编码4 小时前
一个授予普通进程ROOT权限的Linux内核级后门:原理与实现深度解析
linux·运维·服务器·内核·root权限
小夏子_riotous4 小时前
openstack的使用——9. 密钥管理服务Barbican
linux·运维·服务器·系统架构·centos·云计算·openstack
梦想的旅途25 小时前
自动化运营如何防封?解析 API 协议下的拟人化风控算法
运维·自动化
AC赳赳老秦6 小时前
OpenClaw text-translate技能:多语言批量翻译,解决跨境工作沟通难题
大数据·运维·数据库·人工智能·python·deepseek·openclaw