如何在logstash中为beats输入添加主机名
How to add host name for beats input in logstash
让我解释一下我现有的结构,我有 4 台服务器(Web 服务器、API 服务器、数据库服务器、SSIS 服务器)并在所有四台服务器中安装了 filebeat 和 winlog,我从那里获取所有日志在我的 logstash 中,但这是我在消息正文中收到的每条日志,对于某些消息,我很难编写正确的 GROK 模式,无论如何我可以从 Kibana 获得模式(仅供参考,我现在正在存储我可以通过 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"]
}
}
反之亦然,即不是 Logstash 连接到 Filebeat,而是 Filebeat 将数据发送到 Logstash。因此,在您的输入部分,主机需要是 Logstash 所在主机的名称 运行.
beats {
host => "logstash-host"
port => 5044
}
然后在您的 Filebeat 配置中,您需要像这样配置 Logstash output:
output.logstash:
hosts: ["logstash-host:5044"]
由于您有多个 Filebeat 源并且想为每个源应用专用管道,您可以做的是在每个 Filebeat 配置中定义一个 custom field or tag(例如 source: db
、source: api-server
, 等等),然后在 Logstash 中,您可以根据这些值应用不同的逻辑。
filebeat.inputs:
- type: log
fields:
source: 'APISERVERNAME'
fields_under_root: true
在 Logstash 中,您可以利用 conditionals or pipeline to pipeline communication 以根据事件数据应用不同的逻辑。
在最新的 link 上,您可以看到 distributor pattern 的示例,这正是您所追求的。
让我解释一下我现有的结构,我有 4 台服务器(Web 服务器、API 服务器、数据库服务器、SSIS 服务器)并在所有四台服务器中安装了 filebeat 和 winlog,我从那里获取所有日志在我的 logstash 中,但这是我在消息正文中收到的每条日志,对于某些消息,我很难编写正确的 GROK 模式,无论如何我可以从 Kibana 获得模式(仅供参考,我现在正在存储我可以通过 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"]
}
}
反之亦然,即不是 Logstash 连接到 Filebeat,而是 Filebeat 将数据发送到 Logstash。因此,在您的输入部分,主机需要是 Logstash 所在主机的名称 运行.
beats {
host => "logstash-host"
port => 5044
}
然后在您的 Filebeat 配置中,您需要像这样配置 Logstash output:
output.logstash:
hosts: ["logstash-host:5044"]
由于您有多个 Filebeat 源并且想为每个源应用专用管道,您可以做的是在每个 Filebeat 配置中定义一个 custom field or tag(例如 source: db
、source: api-server
, 等等),然后在 Logstash 中,您可以根据这些值应用不同的逻辑。
filebeat.inputs:
- type: log
fields:
source: 'APISERVERNAME'
fields_under_root: true
在 Logstash 中,您可以利用 conditionals or pipeline to pipeline communication 以根据事件数据应用不同的逻辑。
在最新的 link 上,您可以看到 distributor pattern 的示例,这正是您所追求的。