在 CentOS 上安装与配置 Filebeat
一 安装前准备
sudo yum update -y && sudo yum install -y yum-utils二 安装方式
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearchsudo tee /etc/yum.repos.d/elastic-beats.repo <<EOF [elastic-7.x] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md EOFsudo yum install -y filebeat && sudo systemctl enable --now filebeatwget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.x.x-linux-x86_64.tar.gzsudo tar -xzf filebeat-7.x.x-linux-x86_64.tar.gz -C /opt//opt/filebeat/filebeat -e -c /opt/filebeat/filebeat.yml三 配置要点
/etc/filebeat/filebeat.yml/opt/filebeat/filebeat.ymlfilebeat.inputs:
- type: log
enabled: truepaths: ["/var/log/*.log"]output.elasticsearch:
hosts: ["localhost:9200"]filebeat.modules.path: ${path.config}/modules.d/*.ymlsetup.template.name: "filebeat" 与 setup.template.pattern: "filebeat-*";索引可按版本与日期命名:filebeat-%{[agent.version]}-%{+yyyy.MM.dd}。四 启动与验证
sudo systemctl daemon-reload && sudo systemctl enable --now filebeatsudo systemctl status filebeatsudo journalctl -u filebeat -fcurl -X GET "localhost:9200/_cat/indices?v&pretty",应能看到以 filebeat- 开头的索引。五 安全与网络配置
output.elasticsearch:
hosts: ["https://your_es_host:9200"]username: "your_username"password: "your_password"sudo systemctl restart filebeatsudo firewall-cmd --permanent --add-port={9200,5601}/tcp && sudo firewall-cmd --reload