目录
介绍
背景
为(DB、API和WEB)服务器配置filebeat.yml
创建管道配置文件
dblogpipeline.conf
apilogpipeline.conf
weblogpipeline.conf
Pipeline.yml
介绍考虑您在不同的2台服务器上安装了多个filebeats,您希望为每个filebeat创建单独的管道,并希望在elasticsearch或任何文件上输出。
背景因此,让我们来看一个示例,其中有多个服务器,例如:
- 数据库服务器
- API服务器
- Webserver
- Elasticsearch服务器(此服务器将具有Elasticsearch,我将其视为接收器,用于日志\数据和logstash的可视表示的kibana)
现在,我们希望所有日志都在Elasticsearch中,但要进行一些过滤和数据处理——因此,让我们通过下图了解过程。
现在看上图,在三台服务器上安装了filebeats,它们收集日志数据,一旦配置完成,logdata将发送到elasticsearch。现在的问题是问题出在哪里?
让我们了解示例logstash输入的问题:
input {
beats {
p => 5044
}
}
因此,上面的代码表明我们可以有多个源,但是对于beats,我们只有一个,所以我们将如何划分管道?现在让我们考虑Beats。
在记事本中打开filebeats.yml文件,并将所有日志的服务器名称配置为logstash:
filebeat.inputs:
- type: log
fields:
source: 'DB Server Name'
fields_under_root: true
filebeat.inputs:
- type: log
fields:
source: 'API Server Name'
fields_under_root: true
filebeat.inputs:
- type: log
fields:
source: 'WEB Server Name'
fields_under_root: true
现在我们完成了filebeats更改,让我们继续创建logstash管道conf文件。
我们可以通过多种方式在Logstash中配置多个Piepline,一种方法是在Pipeline.yml文件中设置所有内容,然后运行Logstash,所有输入和输出配置都将在同一文件中,如以下代码所示,但这不是理想的:
pipeline.id: dblog-process
config.string: input { pipeline { address => dblog } }
第二种方法是为beat创建单独的conf,在创建文件之前,让我们在config文件夹内创建一个文件夹名称管道。
- dblogpipeline.conf
- apilogpipeline.conf
- weblogpipeline.conf
现在,让我们将代码放入conf文件中。
dblogpipeline.confinput {
pipeline {
address => dblog
}
}
output {
file {
path => ["C:/Logs/dblog_%{+yyyy_MM_dd}.log"]
}
}
apilogpipeline.conf
input {
pipeline {
address => apilog
}
}
output {
file {
path => ["C:/Logs/apilog_%{+yyyy_MM_dd}.log"]
}
}
weblogpipeline.conf
input {
pipeline {
address => weblog
}
}
output {
file {
path => ["C:/Logs/weblog_%{+yyyy_MM_dd}.log"]
}
}
现在我们的conf文件已经准备好,只剩下pipeline.yml文件配置了。
- pipeline.id: beats-server
config.string: |
input { beats { port => 5044 } }
output {
if [source] == 'dbservername' {
pipeline { send_to => dblog }
} else if [source] == 'apiservername' {
pipeline { send_to => apilog }
} else if [source] == 'webservername' {
pipeline { send_to => weblog }
}
}
- pipeline.id: dblog-processing
path.config: "/Logstash/config/pipelines/dblogpipeline.conf"
- pipeline.id: apilog-processing
path.config: "/Logstash/config/pipelines/apilogpipeline.conf"
- pipeline.id: weblog-processing
path.config: "/Logstash/config/pipelines/weblogpipeline.conf"
然后运行logstash。:)