在Ubuntu上运行多个Filebeat实例,您需要为每个实例创建单独的配置文件、数据目录和日志文件。以下是运行多个Filebeat实例的步骤:
安装Filebeat: 如果您还没有安装Filebeat,请按照官方文档中的说明进行安装:https://www.elastic.co/guide/en/beats/filebeat/current/install-filebeat.html
创建Filebeat实例目录结构:
对于每个实例,创建一个单独的目录,例如/etc/filebeat_instance1和/etc/filebeat_instance2。在此目录中,您将存储配置文件、数据目录和日志文件。
复制Filebeat安装目录到实例目录:
对于每个实例,复制Filebeat的安装目录到一个新的位置,例如/etc/filebeat_instance1和/etc/filebeat_instance2。这将使您能够为每个实例使用单独的配置文件。
创建实例配置文件:
在每个实例目录中,创建一个名为filebeat.yml的配置文件。根据需要修改配置文件,例如设置不同的输入、输出和处理器。确保为每个实例指定唯一的数据目录和日志文件。
示例filebeat_instance1.yml:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/instance1/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
setup.template.name: "filebeat_instance1"
setup.template.pattern: "filebeat_instance1-*"
示例filebeat_instance2.yml:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/instance2/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
setup.template.name: "filebeat_instance2"
setup.template.pattern: "filebeat_instance2-*"
创建数据目录和日志文件:
在每个实例目录中,创建一个数据目录(例如/var/lib/filebeat_instance1和/var/lib/filebeat_instance2)和一个日志文件(例如/var/log/filebeat_instance1/filebeat.log和/var/log/filebeat_instance2/filebeat.log)。
设置文件权限: 确保Filebeat进程有权访问每个实例的数据目录和日志文件。
运行Filebeat实例:
使用-c选项指定配置文件,并使用-e选项将日志输出到指定的日志文件。为每个实例运行以下命令:
sudo /etc/filebeat_instance1/filebeat -c /etc/filebeat_instance1/filebeat.yml -e /var/log/filebeat_instance1/filebeat.log
sudo /etc/filebeat_instance2/filebeat -c /etc/filebeat_instance2/filebeat.yml -e /var/log/filebeat_instance2/filebeat.log
现在,您已经成功运行了两个Filebeat实例。每个实例都将使用其自己的配置文件、数据目录和日志文件。如有需要,您可以按照相同的步骤添加更多实例。