下载安装

下载安装比较简单,只需要到官网进行压缩包下载,上传到服务器解压即可;


logstash下载地址: https://www.elastic.co/downloads/logstash

filebeat下载地址: https://www.elastic.co/downloads/beats/filebeat


配置文件

先进行logstash配置:

在bin目录下创建logstash.conf文件,内容如下:

input {
  beats {
    port => "5044"
  }
}

output { 
file { 
  path => "/data/log/logstash/all.log" # 指定写入文件路径
  codec => line { format => "%{host} %{message}" } # 指定写入格式
  flush_interval => 0 # 指定刷新间隔,0代表实时写入
}
stdout {
  codec => rubydebug
  }
}

路径也可以按天按服务器生成如:

path => "/data/log/logstash/%{host}/%{+yyyyMMdd}/all.log"


再进行filebeat配置:

  • 编辑filebeat下的filebeat.yml文件

  • 配置需要监控的日志文件,这里示例为:/var/log/test.log

  • 为了快速看到效果每隔1s检测一次;记得enable改为true

  • 然后关闭Kibana配置,关闭elasticsearch配置;如果需要请保留

  • 开启logstash配置


- type: log

  # Change to true to enable this prospector configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /var/log/test.log
    #- c:\programdata\elasticsearch\logs\*
  close_inactive: 5m
  scan_frequency: 1s
  
  ………………
  output.logstash:
    # The Logstash hosts
    hosts: ["localhost:5044"]


启动命令

filebeat启动命令:

./filebeat -e -c filebeat.yml -d "publish"

logstash启动命令:

./logstash -f logstash.conf  --config.reload.automatic

--config.reload.automatic 可以自动重载配置文件

后台启动可以

nohup ./filebeat -e -c filebeat.yml -d "publish" >/dev/null 2>&1 &
nohup ./logstash -f logstash.conf >/dev/null 2>&1 &

测试

创建/var/log/test.log文件

# touch /var/log/test.log 
# echo "hello world" >> /var/log/test.log 
# tail -f /data/log/logstash/all.log
localhost hello world

all.log会打印:localhost hello world 测试成功


没有登录不能评论