文章目錄
- 🔍 原因分析
- ? 正確的訪問方式:使用 `curl -k https://...`
- 🔐 你需要知道 `elastic` 用戶的密碼
- 方法 1:查看首次生成的密碼(如果剛安裝)
- 方法 2:重置密碼
- ? 成功示例
- 🎉 總結:你現在成功了!
- 🛠? 下一步建議
驗證 Elasticsearch時在執行:
curl -X GET "localhost:9200"
出現了以下提示:
curl: (52) Empty reply from server
這個錯誤 不是失敗,而是說明:
? Elasticsearch 進程已經啟動了!
? 但你訪問的是 HTTP 端口,而你配置了 HTTPS(SSL/TLS)
🔍 原因分析
你配置了:
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: certs/http.p12
這意味著:
🔐 Elasticsearch 的 HTTP 接口 強制使用 HTTPS,不再響應普通 HTTP 請求。
所以當你運行:
curl -X GET "localhost:9200"
它嘗試用 HTTP 連接,但 Elasticsearch 只接受 HTTPS,于是直接斷開連接 → Empty reply from server
? 正確的訪問方式:使用 curl -k https://...
curl -k https://localhost:9200 -u elastic
解釋參數:
-k
:忽略證書驗證(因為是自簽名證書)https://
:使用 HTTPS 協議-u elastic
:使用elastic
用戶認證(會提示輸入密碼)
🔐 你需要知道 elastic
用戶的密碼
方法 1:查看首次生成的密碼(如果剛安裝)
# 查看日志中是否有臨時密碼
sudo grep "Password for the elastic" /var/log/elasticsearch/elk-cluster.log
輸出可能類似:
Password for the [elastic] user retrieved from the elastic store: abc123-def456-ghi789
方法 2:重置密碼
sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
它會提示你設置新密碼。
? 成功示例
運行:
curl -k https://localhost:9200 -u elastic
輸入密碼后,你應該看到:
{"name" : "elk-node-1","cluster_name" : "elk-cluster","cluster_uuid" : "abc123...","version" : {"number" : "8.19.3","build_flavor" : "default","build_type" : "rpm","build_hash" : "abc123","build_date" : "2025-06-25T12:00:00Z","build_snapshot" : false,"lucene_version" : "9.10.0","minimum_wire_compatibility_version" : "7.17.0","minimum_index_compatibility_version" : "7.0.0"},"tagline" : "You Know, for Search"
}
🎉 總結:你現在成功了!
狀態 | 說明 |
---|---|
? systemctl status elasticsearch 顯示 active (running) | 服務已啟動 |
? 日志中不再有 AccessDenied 或 initial_master_nodes 錯誤 | 配置已修復 |
? curl -k https://localhost:9200 -u elastic 能返回 JSON | 驗證成功 |
🛠? 下一步建議
- 配置 Kibana 連接 Elasticsearch
- 設置定期備份(快照)
- 配置防火墻(只允許必要端口)
- 考慮生產環境使用多節點集群
如果你現在運行:
curl -k https://localhost:9200 -u elastic
并輸入正確密碼,一定會成功!
你做到了!👏 如果需要配置 Kibana 或 Logstash,我也可以繼續幫你!