在CentOS系統上使用Filebeat實現實時日志監控,可以按照以下步驟進行配置和操作:
下載Filebeat:
從Elastic官方網站下載適合CentOS的Filebeat版本。例如,下載Filebeat 7.14.0版本:
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.14.0-linux-x86_64.tar.gz
解壓文件:
tar -zxvf filebeat-7.14.0-linux-x86_64.tar.gz
重命名解壓后的文件夾:
mv filebeat-7.14.0-linux-x86_64 filebeat
進入Filebeat目錄:
cd filebeat
編輯配置文件:
配置文件通常位于 /etc/filebeat/filebeat.yml
。以下是一個基本的配置示例,展示了如何配置Filebeat從指定目錄收集日志并發送到Elasticsearch:
filebeat.inputs:
- type: log
enabled: true
paths:
- /path/to/your/application/logs/*.log
output.elasticsearch:
hosts:
- your_elasticsearch_host:9200
確保將 /path/to/your/application/logs/*.log
替換為你要監控的日志文件的實際路徑,將 your_elasticsearch_host
替換為你的Elasticsearch實例的地址和端口。
啟動Filebeat:
配置完成后,啟動Filebeat并將其設置為系統啟動時自動啟動:
nohup ./filebeat -e -c /etc/filebeat/filebeat.yml &
設置Filebeat開機自啟動:
systemctl enable filebeat
systemctl start filebeat
查看Filebeat狀態:
使用以下命令來查看Filebeat的運行狀態:
systemctl status filebeat
查看Filebeat日志:
使用以下命令查看Filebeat的日志文件,以確保沒有錯誤:
journalctl -u filebeat
如果你想監控Filebeat自身的性能指標,可以使用Metricbeat。以下是安裝和配置Metricbeat的步驟:
下載Metricbeat:
wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.14.0-linux-x86_64.tar.gz
解壓文件:
tar -zxvf metricbeat-7.14.0-linux-x86_64.tar.gz
重命名解壓后的文件夾:
mv metricbeat-7.14.0-linux-x86_64 metricbeat
進入Metricbeat目錄:
cd metricbeat
編輯配置文件:
在 metricbeat.yml
文件中,確保將 output.elasticsearch.hosts
設置為你的Elasticsearch實例的地址和端口:
output.elasticsearch:
hosts:
- your_elasticsearch_host:9200
啟動Metricbeat:
啟動Metricbeat并將其設置為系統啟動時自動啟動:
nohup ./metricbeat -e -c /etc/metricbeat/metricbeat.yml &
設置Metricbeat開機自啟動:
systemctl enable metricbeat
systemctl start metricbeat
通過以上步驟,你就可以利用Filebeat實時監控CentOS系統上的應用日志,并將日志數據發送到Elasticsearch進行分析和可視化展示。