排查CentOS上FileBeat的故障可以按照以下步驟進行:
systemctl
命令檢查FileBeat服務的狀態:sudo systemctl status filebeat
如果FileBeat未運行,可以使用以下命令啟動它:sudo systemctl start filebeat
要確保FileBeat在系統啟動時自動運行,可以使用以下命令:sudo systemctl enable filebeat
/etc/filebeat/filebeat.yml
是否正確配置。特別注意以下部分:
filebeat.inputs
:確保日志路徑和輸出配置正確。output.elasticsearch
:確認Elasticsearch的地址和端口配置正確。/var/log/filebeat/filebeat
目錄下。檢查這些日志文件可以獲取詳細的運行狀態和錯誤信息。sudo tail -f /var/log/filebeat/filebeat
curl
命令查詢Elasticsearch的健康狀態:curl -X GET "localhost:9200/_cluster/health?pretty"
/var/log/elasticsearch/
目錄下,查找任何可能的錯誤信息。import requests
import json
def check_filebeat_status():
response = requests.get('http://localhost:5066')
if response.status_code == 200:
print("Filebeat is running")
else:
print("Filebeat is not running")
def query_elasticsearch():
es_url = 'http://localhost:9200/_search'
query = {
"query": {
"match_all": {}
},
"size": 10
}
response = requests.post(f"{es_url}/_search", json=query)
results = json.loads(response.text)
for hit in results['hits']['hits']:
print(hit['_source'])
check_filebeat_status()
query_elasticsearch()
通過以上步驟,可以系統地排查和解決CentOS上FileBeat的故障。如果問題依然存在,建議參考FileBeat的官方文檔或聯系技術支持獲取進一步幫助。