首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何为logstash中的节拍输入添加主机名

如何为logstash中的节拍输入添加主机名
EN

Stack Overflow用户
提问于 2020-06-16 19:55:29
回答 1查看 2.6K关注 0票数 0

让我解释一下我现有的结构,我有4个服务器(Web服务器,API服务器,数据库服务器,SSIS服务器),并且在所有4个服务器上安装了filebeat和winlog,从那里我在我的日志堆栈中获得了所有日志,但这里是我在消息正文中获得的每个日志,对于一些消息,我很难编写正确的GROK模式,有没有什么我可以从Kibana获得模式(仅供参考,我现在将所有日志存储在elasticsearch中,我可以通过Kibana查看)。

我的Logstash配置是这样的-

代码语言:javascript
运行
复制
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
      }
    }

当我只使用端口时,它工作了,当我添加主机时,它就停止工作了。有人能帮我一下吗。

下面是我正在努力实现的

这里我做了修改,它能工作吗,因为我需要编写冗长的过滤器,这就是为什么我想要在单独的文件中

代码语言:javascript
运行
复制
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"]
    }
} 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-16 20:18:52

相反,连接到Filebeat的不是Logstash,而是将数据发送到Logstash的Filebeat。因此,在您的输入部分中,主机需要是运行Logstash的主机的名称。

代码语言:javascript
运行
复制
beats {
  host => "logstash-host"
  port => 5044
}

然后,在您的Filebeat配置中,您需要像这样配置Logstash output

代码语言:javascript
运行
复制
output.logstash:
  hosts: ["logstash-host:5044"]

由于您有多个Filebeat源,并希望对每个源应用专用管道,因此您可以在每个Filebeat配置(例如source: dbsource: api-server等)中定义一个custom field or tag,然后在Logstash中可以基于这些值应用不同的逻辑。

代码语言:javascript
运行
复制
filebeat.inputs:
- type: log
  fields:
    source: 'APISERVERNAME'
  fields_under_root: true

在Logstash中,您可以利用conditionalspipeline to pipeline communication来根据事件数据应用不同的逻辑。

在最新的链接上,你可以看到一个distributor pattern的例子,这几乎就是你想要的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62407849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档