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

相关推荐
馨羽的玩具27 分钟前
查哪个程序一直登录sql server失败
运维·服务器·数据库
苹果醋337 分钟前
[MySQL] MySQL 版本不支持 ST_Distance_Sphere替代方案和解决方案
java·运维·spring boot·mysql·nginx
F_D_Z1 小时前
【解决办法】pip install albumentations安装下载遇19kB/s超级慢细水管
linux·运维·python·pip
luoqice1 小时前
在嵌入式 Linux 系统中,配置 DNS 以实现内网或外网连接
linux·运维·服务器
中心观察者1 小时前
haproxy应用详解
运维
青草地溪水旁1 小时前
Ubuntu上开通Samba网络共享
linux·运维·ubuntu·samba
芥子沫1 小时前
ElasticSearch 的3种数据迁移方案
运维·elasticsearch·搜索引擎
IvanCodes1 小时前
三、Linux用户与权限管理详解
linux·运维·服务器
蝉明✘2 小时前
HAproxy负载均衡
运维·负载均衡
格发许可优化管理系统2 小时前
GTSuite许可证性能优化建议
大数据·运维·数据库·安全·性能优化·数据分析