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

相关推荐
yuankoudaodaokou2 小时前
革新自动化产线调试,扫描生成点云精准引导机器人路径
运维·python·机器人·自动化
wengad2 小时前
podman搭建nginx服务
运维·nginx·podman
阡陌..2 小时前
Linux下的vi和vim使用方法
linux·运维·vim
hweiyu002 小时前
Linux 命令:diff
linux·运维·服务器
进击切图仔2 小时前
基于 linux 20.04 构建 ros1 noetic 开发环境 -离线版本
linux·运维·服务器
晚风吹长发2 小时前
初步了解Linux中的线程同步问题及线程安全和死锁与生产消费者模型
linux·运维·服务器·开发语言·数据结构·安全
mi20063 小时前
银河麒麟上tabby和electerm两款终端工具比较
linux·运维
muyan93 小时前
浅吐槽一下统信uos linux
linux·运维·国产化·uos·统信·去ioe
市场部需要一个软件开发岗位3 小时前
docker操作记录
运维·docker·容器
angushine3 小时前
TDSQL创建分区表
运维·mysql