什麼是 Metricbeat?
Metricbeat 是 Elastic Stack 中的一個輕量級數據收集器,專門用來收集系統與服務的指標數據,並將其發送到 Elasticsearch 或 Logstash 進行分析和可視化。
安裝前準備
支援平台
- Linux (Debian、Ubuntu、CentOS 等)
- macOS
- Windows
系統需求
- Elastic Stack 7.0 以上版本
- 已安裝並運行中的 Elasticsearch 與 Kibana
安裝 Metricbeat
線上安裝
Linux
Debian/Ubuntu:
curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-8.14.1-amd64.deb
sudo dpkg -i metricbeat-8.14.1-amd64.deb
CentOS/RHEL:
curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-8.14.1-x86_64.rpm
sudo rpm -vi metricbeat-8.14.1-x86_64.rpm
Windows 安裝
- 下載 Metricbeat for Windows
- 解壓縮 ZIP 檔案
- 使用 PowerShell 執行 Metricbeat
PS C:\metricbeat> .\install-service-metricbeat.ps1
離線安裝
從有網路的環境下載 Metricbeat 套件檔案(.deb 或 .rpm):
wget https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-8.14.1-amd64.deb
將檔案複製到目標機器:
scp metricbeat-8.14.1-amd64.deb user@target_ip:/path/to/destination
在目標機器上安裝:
Debian/Ubuntu
sudo dpkg -i metricbeat-8.14.1-amd64.deb
CentOS/RHEL
sudo rpm -vi metricbeat-8.14.1-x86_64.rpm
基本配置
編輯設定檔
設定檔位於 /etc/metricbeat/metricbeat.yml
(Linux)或 C:\Program Files\Metricbeat\metricbeat.yml
(Windows)。
設定輸出到 Logstash:
output.logstash:
hosts: ["localhost:5044"]
啟用系統模組
sudo metricbeat modules enable system
測試配置
sudo metricbeat test config
啟動服務
sudo systemctl enable metricbeat
sudo systemctl start metricbeat
故障排除
- 檢查 Metricbeat 日誌:
sudo journalctl -u metricbeat
- 驗證 Elasticsearch 連線:
curl -X GET "localhost:9200/_cat/indices?v"