簡體   English   中英

如何在logstash中為beats輸入添加主機名

[英]How to add host name for beats input in logstash

讓我解釋一下我現有的結構,我有 4 台服務器(Web 服務器,API 服務器,數據庫服務器,SSIS 服務器)並在所有四台服務器中安裝了 filebeat 和 winlog,從那里我在我的 logstash 中獲取所有日志,但這是事情我在消息正文中收到的每條日志,對於某些消息,我很難編寫正確的 GROK 模式,無論如何我可以從 Kibana 獲得模式(僅供參考,我現在將所有日志存儲在 elasticsearch 中,我可以看到基巴納。)

我的 Logstash 配置看起來像 -

1. Api-Pipeline
input {
  beats {
    host => "IP Address where my filebeat (API Server) is running"
    port => 5044
  }
}

2. DB Pipeline
input {
      beats {
        host => "IP Address where my filebeat (Database Server) is running"
        port => 5044
      }
    }

當我只使用端口並且添加主機時它停止工作時它正在工作。 有人能幫我一下嗎。

下面我試圖實現

在此處輸入圖像描述

在這里我進行了更改,它是否有效,因為我需要編寫冗長的過濾器,這就是為什么我想在單獨的文件中

Filebeat.yml on API Server
-----------------------------------------------------------------------------------------
filebeat.inputs:
- type: log
  source: 'ApiServerName' // MyAPIServerName(Same Server Where I have installed filebeat)
  enabled: true
  paths:
    - C:\Windows\System32\LogFiles\SMTPSVC1\*.log
    - E:\AppLogs\*.json

scan_frequency: 10s
ignore_older: 24h

filebeat.config.modules:
  path: C:\Program Files\Filebeat\modules.d\iis.yml
  reload.enabled: false

setup.template.settings:
  index.number_of_shards: 3

setup.kibana:
  host: "kibanaServerName:5601"

output.logstash:
  hosts: ["logstashServerName:5044"]



Logstash Configuration
----------------------------------------------------------------
Pipeline.yml

- pipeline.id: beats-server
  config.string: |
    input { beats { port => 5044 } }
    output {
        if [source] == 'APISERVERNAME' {
          pipeline { send_to => apilog }
        } else if [source] == 'DBSERVERNAME' {
          pipeline { send_to => dblog }
        }
        else{
          pipeline { send_to => defaultlog }
        }
    }

- pipeline.id: apilog-processing
  path.config: "/Logstash/config/pipelines/apilogpipeline.conf"

- pipeline.id: dblog-processing
  path.config: "/Logstash/config/pipelines/dblogpipeline.conf"

- pipeline.id: defaultlog-processing
  path.config: "/Logstash/config/pipelines/defaultlogpipeline.conf"



1. apilogpipeline.conf
----------------------------------------------------------
input { 
    pipeline { 
        address => apilog 
    } 
}
output {
    file {
        path => ["C:/Logs/apilog_%{+yyyy_MM_dd}.log"]
    }
}



2. dbilogpipeline.conf
---------------------------------------------------------
input { 
    pipeline { 
        address => dblog 
    } 
}
output {
    file {
        path => ["C:/Logs/dblog_%{+yyyy_MM_dd}.log"]
    }
}


3. defaultlogpipeline.conf
---------------------------------------------------------
input { 
    pipeline { 
        address => defaultlog 
    } 
}
output {
    file {
        path => ["C:/Logs/defaultlog_%{+yyyy_MM_dd}.log"]
    }
} 

它以相反的方式工作,即連接到 Filebeat 的不是 Logstash,而是向 Logstash 發送數據的 Filebeat。 因此,在您的輸入部分,主機需要是運行 Logstash 的主機的名稱。

beats {
  host => "logstash-host"
  port => 5044
}

然后在您的 Filebeat 配置中,您需要像這樣配置Logstash output

output.logstash:
  hosts: ["logstash-host:5044"]

由於您有多個 Filebeat 源並希望對每個源應用專用管道,您可以做的是在每個 Filebeat 配置中定義一個自定義字段或標簽(例如source: dbsource: api-server等),然后在 Logstash您可以根據這些值應用不同的邏輯。

filebeat.inputs:
- type: log
  fields:
    source: 'APISERVERNAME'
  fields_under_root: true

在 Logstash 中,您可以利用條件管道到管道通信,以便根據事件數據應用不同的邏輯。

在最新的鏈接上,您可以看到一個分銷商模式的示例,這幾乎就是您所追求的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM