ruby 做網(wǎng)站谷歌推廣公司哪家好
要將數(shù)據(jù)從 Elastic Agent 安全地發(fā)送到 Logstash,你需要配置傳輸層安全性 (TLS)。 使用 TLS 可確保你的 Elastic Agent 將加密數(shù)據(jù)發(fā)送到受信任的 Logstash 服務(wù)器,并且你的 Logstash 服務(wù)器從受信任的 Elastic Agent 客戶端接收數(shù)據(jù)。
先決條件
- 確保你的訂閱級別支持輸出到 Logstash。
- 在 Windows 上,將隊列服務(wù)器的端口 8220 和 Logstash 的端口 5044 添加到 Windows 高級防火墻的入站端口規(guī)則。
- 如果你要連接到自托管的 Elasticsearch 集群,則需要用于簽署 Elasticsearch 集群 HTTP 層證書的 CA 證書。 有關(guān)更多信息,請參閱 Elasticsearch 安全文檔。
生成自定義證書和私鑰
你可以使用通常使用的任何過程來生成 PEM 格式的證書。 此處顯示的示例使用 Elasticsearch 提供的 certutil 工具。
提示:certutil 工具在 Elastic Cloud 上不可用,但你仍然可以使用它為 Elastic Agent 到 Logstash 連接生成證書。 只需下載 Elasticsearch 包,將其解壓到本地目錄,然后運行 elasticsearch-certutil 命令。 無需啟動 Elasticsearch!
1. 生成證書頒發(fā)機構(gòu) (CA)。 如果你想使用現(xiàn)有的 CA,請?zhí)^此步驟。
./bin/elasticsearch-certutil ca --pem
此命令創(chuàng)建一個 zip 文件,其中包含 CA 證書和用于簽署證書的密鑰。 解壓 zip 文件:
2. 生成由你的 CA 簽名的客戶端 SSL 證書。 例如:
./bin/elasticsearch-certutil cert \--name client \--ca-cert /path/to/ca/ca.crt \--ca-key /path/to/ca/ca.key \--pem
解壓 zip 文件:
3. 生成由你的 CA 簽名的 Logstash SSL 證書。 例如:
./bin/elasticsearch-certutil cert \--name logstash \--ca-cert /path/to/ca/ca.crt \--ca-key /path/to/ca/ca.key \--dns your.host.name.here \--ip 192.0.2.1 \--pem
解壓 zip 文件:
4. 將 Logstash 密鑰轉(zhuǎn)換為 pkcs8。 例如,在 Linux 上運行:
openssl pkcs8 -inform PEM -in logstash.key -topk8 -nocrypt -outform PEM -out logstash.pkcs8.key
將這些文件存儲在安全的位置。
配置 Logstash 管道
提示:如果你已經(jīng)創(chuàng)建了 Logstash elastic-agent-pipeline.conf 管道并將其添加到 pipelines.yml,請?zhí)绞纠渲貌⒏鶕?jù)需要修改管道配置。
在 Logstash 配置目錄中,打開 pipelines.yml 文件并添加以下配置。 替換你的文件的路徑。
- pipeline.id: elastic-agent-pipelinepath.config: "/etc/path/to/elastic-agent-pipeline.conf"
在 elastic-agent-pipeline.conf 文件中,添加管道配置。 請注意,Elastic Cloud 上的 Elasticsearch 服務(wù)所需的配置與自管理 Elasticsearch 集群不同。 如果你復(fù)制了 Fleet 中顯示的配置,請根據(jù)需要進行調(diào)整。
Elasticsearch 服務(wù)示例:
elastic-agent-pipeline.conf
input {elastic_agent {port => 5044ssl => truessl_certificate_authorities => ["/path/to/ca.crt"]ssl_certificate => "/path/to/logstash.crt"ssl_key => "/path/to/logstash.pkcs8.key"ssl_verify_mode => "force_peer"}
}output {elasticsearch {cloud_id => "xxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx=" api_key => "xxxx:xxxx" data_stream => truessl => true }
}
- 使用 Elastic Cloud 中的部署頁面上顯示的 cloud_id。
- 在 Fleet 中,你可以在添加 Logstash 輸出時生成此 API 密鑰。
- Elasticsearch Service 使用標準的公共信任證書,因此無需在此處指定其他 SSL 設(shè)置。
自托管的 Elasticsearch 集群示例:
elastic-agent-pipeline.conf
input {elastic_agent {port => 5044ssl => truessl_certificate_authorities => ["/path/to/ca.crt"]ssl_certificate => "/path/to/logstash.crt"ssl_key => "/path/to/logstash.pkcs8.key"ssl_verify_mode => "force_peer"}
}output {elasticsearch {hosts => "https://xxxx:9200"api_key => "xxxx:xxxx"data_stream => truessl => truecacert => "/path/to/http_ca.crt" }
}
- 使用為 Elasticsearch 生成的證書。
要了解有關(guān) Logstash 配置的更多信息,請參閱:
- Elastic Agent 輸入插件
- Elasticsearch 輸出插件
- 保護你與 Elasticsearch 的連接
完成管道配置后,重新啟動 Logstash:
bin/logstash
將 Logstash 輸出添加到 Fleet
本節(jié)介紹如何在 Fleet 中添加 Logstash 輸出并配置 SSL 設(shè)置。 如果你獨立運行 Elastic Agent,請參閱 Logstash 輸出配置文檔。你也可以閱讀文章 “Observability:如何把 Elastic Agent 采集的數(shù)據(jù)輸入到 Logstash 并最終寫入到 Elasticsearch”。
- 在 Kibana 中,轉(zhuǎn)到 Fleet?> Settings。
- 在 Output 下,單擊 Add output。 如果你一直在 Fleet 中執(zhí)行 Logstash 步驟,那么你可能已經(jīng)位于此頁面上。
- 指定輸出的名稱。
- 對于?Type,選擇 Logstash。
- 在 Logstash 主機下,指定代理將用于連接 Logstash 的主機和端口。 使用格式 host:port。格式有點類似?
mylogstashhost:5044。參考鏈接
- 在??Server SSL certificate authorities?字段中,粘貼你之前生成的 ca.crt 文件的全部內(nèi)容。
- 在?Client SSL certificate?字段中,粘貼你之前生成的 client.crt 文件的全部內(nèi)容。
- 在?Client SSL certificate key?字段中,粘貼你之前生成的 client.key 文件的全部內(nèi)容。
完成后,保存并應(yīng)用設(shè)置。
在代理策略中選擇 Logstash 輸出
Logstash 現(xiàn)在正在偵聽來自 Elastic Agent 的事件,但事件尚未流入 Elasticsearch。 你需要在代理策略中選擇 Logstash 輸出。 你可以編輯現(xiàn)有策略或創(chuàng)建新策略:
1)在 Kibana 中,轉(zhuǎn)到 Fleet > Agent policies,然后創(chuàng)建新的代理策略或單擊現(xiàn)有策略進行編輯:
- 要更改新策略中的輸出設(shè)置,請單擊?Create agent policy?并展開?Advanced options。
- 要更改現(xiàn)有策略中的輸出設(shè)置,請單擊該策略進行編輯,然后單擊?Settings。
2)設(shè)置?Output for integrations? 及(可選)Output for agent monitoring?以使用你之前創(chuàng)建的 Logstash 輸出。 你可能需要向下滾動才能看到這些選項:
3)保存你的更改。
任何在 agent policy 中注冊的 Elastic Agent 都將開始通過 Logstash 向 Elasticsearch 發(fā)送數(shù)據(jù)。 如果你沒有在 agent policy 中注冊任何已安裝的 Elastic Agent,請立即執(zhí)行此操作。
Elastic Agent 更新到新策略并通過安全連接連接到 Logstash 時可能會出現(xiàn)輕微延遲。
測試連接
要確保 Logstash 正在發(fā)送數(shù)據(jù),請從運行 Logstash 的主機運行以下命令:
curl -XGET localhost:9600/_node/stats/events
該請求應(yīng)返回有關(guān)輸入和輸出事件數(shù)量的統(tǒng)計信息。 如果這些值為 0,請檢查 Elastic Agent 日志是否存在問題。
當數(shù)據(jù)流式傳輸?shù)?Elasticsearch 時,轉(zhuǎn)到?Observability?并單擊指標以查看有關(guān)系統(tǒng)的?Metrics。
更多閱讀:Observability:如何把 Elastic Agent 采集的數(shù)據(jù)輸入到 Logstash 并最終寫入到 Elasticsearch