CentOS 上 Filebeat 的远程管理实践
一、管理目标与总体思路
二、远程下发与批量管控
---
- name: Install and configure Filebeat
hosts: target_servers
become: true
vars:
filebeat_version: "8.11.3"
es_host: "es.example.com"
es_port: 9200
tasks:
- name: Download Filebeat RPM
get_url:
url: "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-{{ filebeat_version }}-x86_64.rpm"
dest: "/tmp/filebeat-{{ filebeat_version }}-x86_64.rpm"
- name: Install Filebeat
yum:
name: "/tmp/filebeat-{{ filebeat_version }}-x86_64.rpm"
state: present
- name: Render and copy config
ansible.builtin.template:
src: filebeat.yml.j2
dest: /etc/filebeat/filebeat.yml
owner: root
group: root
mode: '0644'
- name: Start and enable service
systemd:
name: filebeat
state: started
enabled: yes
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["{{ es_host }}:{{ es_port }}"]
protocol: "https"
ssl.verification_mode: full
ssl.certificate_authorities: ["/etc/pki/CA/ca.crt"]
username: "elastic"
password: "{{ es_password }}"
logging.level: info
ansible-playbook -i inventory.ini filebeat.yml。该方式便于在多台 CentOS 主机上统一变更与回滚配置。三、远程查看状态与指标
http.enabled: true
http.host: 0.0.0.0 # 允许远程访问;生产环境建议配合防火墙/反向代理做访问控制
http.port: 5066
sudo systemctl reload filebeatcurl -s http://<agent_ip>:5066/?pretty
curl -s http://<agent_ip>:5066/stats?pretty
四、远程采集与转发的安全实践
output.logstash:
hosts: ["logstash.example.com:5044"]
output.elasticsearch:
hosts: ["es.example.com:9200"]
protocol: "https"
ssl.verification_mode: full
ssl.certificate_authorities: ["/etc/pki/CA/ca.crt"]
username: "elastic"
password: "your_password"
sudo filebeat keystore create
echo "your_password" | sudo filebeat keystore add ELASTICSEARCH_PASSWORD --stdin
sudo filebeat test config -e
sudo systemctl reload filebeat
sudo journalctl -u filebeat -f
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
fields:
type: "app_log"
以上做法覆盖远程传输、认证、加密与动态下发等关键点。