通過跨集群復(fù)制(Cross Cluster Replication - CCR),你可以跨集群將索引復(fù)制并實現(xiàn):
- 在數(shù)據(jù)中心中斷時繼續(xù)處理搜索請求
- 防止搜索量影響索引吞吐量
- 通過在距用戶較近的地理位置處理搜索請求來減少搜索延遲
跨集群復(fù)制采用主動 - 被動模型。 你索引到領(lǐng)導(dǎo)者(leader)索引,并將數(shù)據(jù)復(fù)制到一個或多個只讀跟隨者(follower)索引。 在將跟隨者索引添加到集群之前,必須配置包含領(lǐng)導(dǎo)者索引的遠程集群。
當(dāng)領(lǐng)導(dǎo)者索引接收寫入時,跟隨者索引會從遠程集群上的領(lǐng)導(dǎo)者索引中提取更改。 你可以手動創(chuàng)建跟隨者索引,也可以配置自動跟隨模式,為新的時間序列索引自動創(chuàng)建跟隨者索引。
你可以在單向或雙向設(shè)置中配置跨集群復(fù)制集群:
- 在單向配置中,一個集群僅包含領(lǐng)導(dǎo)者索引,另一個集群僅包含跟隨者索引。
- 在雙向配置中,每個集群都包含領(lǐng)導(dǎo)者索引和跟隨者索引。
在單向配置中,包含跟隨者索引的集群必須運行與遠程集群相同或更新版本的 Elasticsearch。 如果較新,版本也必須兼容,如下表所示。
多集群架構(gòu)
使用跨集群復(fù)制在 Elastic Stack 內(nèi)構(gòu)建多個多集群架構(gòu):
- 主集群故障時災(zāi)難恢復(fù),輔助集群作為熱備份
- 數(shù)據(jù)本地性,用于維護靠近應(yīng)用程序服務(wù)器(和用戶)的數(shù)據(jù)集的多個副本,并減少昂貴的延遲
- 集中式報告,可最大限度地減少查詢多個地理分布式 Elasticsearch 集群時的網(wǎng)絡(luò)流量和延遲,或通過將搜索卸載到輔助集群來防止搜索負載干擾索引編制
重要:在所有這些用例中,你必須在每個集群上獨立配置安全性。 配置跨集群復(fù)制以進行災(zāi)難恢復(fù)時,不會復(fù)制安全配置。 為了確保備份 Elasticsearch 安全功能狀態(tài),請定期拍攝快照。 然后,你可以從安全配置中恢復(fù)本機用戶、角色和 token。
災(zāi)難恢復(fù)和高可用性
災(zāi)難恢復(fù)為你的任務(wù)關(guān)鍵型應(yīng)用程序提供承受數(shù)據(jù)中心或區(qū)域中斷的能力。 此用例是跨集群復(fù)制的最常見部署。 你可以在不同架構(gòu)中配置集群以支持災(zāi)難恢復(fù)和高可用性。它可以分為四個部分:
- 單一災(zāi)難恢復(fù)數(shù)據(jù)中心
- 多個容災(zāi)數(shù)據(jù)中心
- 鏈式復(fù)制
- 雙向復(fù)制
單一災(zāi)難恢復(fù)數(shù)據(jù)中心
在此配置中,數(shù)據(jù)從生產(chǎn)數(shù)據(jù)中心復(fù)制到災(zāi)難恢復(fù)數(shù)據(jù)中心。 由于跟隨者索引復(fù)制領(lǐng)導(dǎo)者索引,因此如果生產(chǎn)數(shù)據(jù)中心不可用,你的應(yīng)用程序可以使用災(zāi)難恢復(fù)數(shù)據(jù)中心。
多個容災(zāi)數(shù)據(jù)中心
你可以將數(shù)據(jù)從一個數(shù)據(jù)中心復(fù)制到多個數(shù)據(jù)中心。 此配置提供災(zāi)難恢復(fù)和高可用性,確保在主數(shù)據(jù)中心發(fā)生故障或不可用時將數(shù)據(jù)復(fù)制到兩個數(shù)據(jù)中心。
在下圖中,數(shù)據(jù)中心 A 的數(shù)據(jù)被復(fù)制到數(shù)據(jù)中心 B 和數(shù)據(jù)中心 C,這兩個數(shù)據(jù)中心都擁有數(shù)據(jù)中心 A 的領(lǐng)導(dǎo)者索引的只讀副本。
鏈式復(fù)制
你可以跨多個數(shù)據(jù)中心復(fù)制數(shù)據(jù)以形成復(fù)制鏈。 在下圖中,數(shù)據(jù)中心 A 包含領(lǐng)導(dǎo)者索引。 數(shù)據(jù)中心 B 從數(shù)據(jù)中心 A 復(fù)制數(shù)據(jù),數(shù)據(jù)中心 C 從數(shù)據(jù)中心 B 中的跟隨者索引復(fù)制數(shù)據(jù)。這些數(shù)據(jù)中心之間的連接形成鏈式復(fù)制模式。
雙向復(fù)制
在雙向復(fù)制設(shè)置中,所有集群都有權(quán)查看所有數(shù)據(jù),并且所有集群都有一個可寫入的索引,而無需手動實施故障轉(zhuǎn)移。 應(yīng)用程序可以寫入每個數(shù)據(jù)中心內(nèi)的本地索引,并跨多個索引讀取所有信息的全局視圖。
當(dāng)集群或數(shù)據(jù)中心不可用時,此配置不需要手動干預(yù)。 在下圖中,如果數(shù)據(jù)中心 A 不可用,你可以繼續(xù)使用數(shù)據(jù)中心 B,而無需手動故障轉(zhuǎn)移。 當(dāng)數(shù)據(jù)中心 A 上線時,集群之間的復(fù)制將恢復(fù)。
此配置對于僅索引(index-only)工作負載特別有用,在這種情況下不會更新文檔值。 在此配置中,Elasticsearch 索引的文檔是不可變的。 客戶端位于 Elasticsearch 集群旁邊的每個數(shù)據(jù)中心,并且不與不同數(shù)據(jù)中心的集群進行通信。
數(shù)據(jù)局部性
讓數(shù)據(jù)更接近用戶或應(yīng)用程序服務(wù)器可以減少延遲和響應(yīng)時間。 在 Elasticsearch 中復(fù)制數(shù)據(jù)時也適用此方法。 例如,你可以將產(chǎn)品目錄或參考數(shù)據(jù)集復(fù)制到全球 20 個或更多數(shù)據(jù)中心,以最大限度地縮短數(shù)據(jù)與應(yīng)用程序服務(wù)器之間的距離。
在下圖中,數(shù)據(jù)從一個數(shù)據(jù)中心復(fù)制到另外三個數(shù)據(jù)中心,每個數(shù)據(jù)中心都位于自己的區(qū)域中。 中央數(shù)據(jù)中心包含領(lǐng)導(dǎo)者索引,其他數(shù)據(jù)中心包含復(fù)制該特定區(qū)域中的數(shù)據(jù)的跟隨者索引。 此配置使數(shù)據(jù)更接近訪問它的應(yīng)用程序。
集中報告
當(dāng)跨大型網(wǎng)絡(luò)查詢效率低下時,使用集中式報告集群非常有用。 在此配置中,你可以將數(shù)據(jù)從許多較小的集群復(fù)制到集中式報告集群。
例如,一家大型跨國銀行可能在全球擁有 100 個 Elasticsearch 集群,這些集群分布在每個銀行分行的不同區(qū)域。 使用跨集群復(fù)制,銀行可以將所有 100 家銀行的事件復(fù)制到中央集群,以便在本地分析和匯總事件以進行報告。 銀行可以使用跨集群復(fù)制來復(fù)制特定索引,而不是維護鏡像集群。
在下圖中,來自不同區(qū)域的三個數(shù)據(jù)中心的數(shù)據(jù)被復(fù)制到集中式報告集群。 此配置使你能夠?qū)?shù)據(jù)從區(qū)域中心復(fù)制到中央集群,你可以在其中本地運行所有報告。
復(fù)制機制
雖然你在索引級別設(shè)置跨集群復(fù)制,但 Elasticsearch 在分片級別實現(xiàn)復(fù)制。 創(chuàng)建跟隨者索引時,該索引中的每個分片都會從領(lǐng)導(dǎo)者索引中相應(yīng)的分片中提取更改,這意味著跟隨者索引與其領(lǐng)導(dǎo)者索引具有相同數(shù)量的分片。 Leader 上的所有操作都會被 follower 復(fù)制,例如創(chuàng)建、更新或刪除文檔的操作。 這些請求可以從領(lǐng)導(dǎo)分片的任何副本(主分片或副本分片)提供服務(wù)。
當(dāng)跟隨者分片發(fā)送讀取請求時,領(lǐng)導(dǎo)者分片會響應(yīng)任何新操作,并受到你在配置跟隨者索引時建立的讀取參數(shù)的限制。 如果沒有可用的新操作,則領(lǐng)導(dǎo)分片將等待新操作的配置超時時間。 如果超時時間過去,領(lǐng)導(dǎo)者分片會向跟隨者分片響應(yīng)沒有新操作。 跟隨者分片更新分片統(tǒng)計信息,并立即向領(lǐng)導(dǎo)者分片發(fā)送另一個讀取請求。 這種通信模型確保遠程集群和本地集群之間的網(wǎng)絡(luò)連接持續(xù)使用,避免被防火墻等外部源強行終止。
如果讀取請求失敗,則檢查失敗的原因。 如果故障原因被認為是可恢復(fù)的(例如網(wǎng)絡(luò)故障),則跟隨者分片將進入重試循環(huán)。 否則,跟隨者分片將暫停,直到你恢復(fù)為止。
處理更新
你無法手動修改跟隨者索引的映射或別名。 要進行更改,你必須更新領(lǐng)導(dǎo)者索引。 因為它們是只讀的,所以跟隨者索引拒絕所有配置中的寫入。
注意:盡管領(lǐng)導(dǎo)者索引上的別名更改會復(fù)制到跟隨者索引,但寫索引(write indices)會被忽略。 跟隨者索引不能接受直接寫入,因此如果任何領(lǐng)導(dǎo)者別名將 is_write_index 設(shè)置為 true,則該值將被強制設(shè)置為 false。
例如,你在數(shù)據(jù)中心 A 中為名為 doc_1 的文檔建立索引,該文檔將復(fù)制到數(shù)據(jù)中心 B。如果客戶端連接到數(shù)據(jù)中心 B 并嘗試更新 doc_1,則請求將失敗。 要更新 doc_1,客戶端必須連接到數(shù)據(jù)中心 A 并更新領(lǐng)導(dǎo)者索引中的文檔。
當(dāng)跟隨者分片從領(lǐng)導(dǎo)者分片接收操作時,它將這些操作放入寫入緩沖區(qū)中。 跟隨者分片使用寫入緩沖區(qū)中的操作提交批量寫入請求。 如果寫入緩沖區(qū)超出其配置的限制,則不會發(fā)送其他讀取請求。 此配置提供了針對讀取請求的背壓(back-pressure),允許跟隨者分片在寫入緩沖區(qū)不再滿時恢復(fù)發(fā)送讀取請求。
要管理如何從領(lǐng)導(dǎo)者索引復(fù)制操作,你可以在創(chuàng)建跟隨者索引時配置設(shè)置。
領(lǐng)導(dǎo)者索引上的索引映射的更改會盡快復(fù)制到跟隨者索引。 此行為也適用于索引設(shè)置,但領(lǐng)導(dǎo)者索引本地的某些設(shè)置除外。 例如,更改領(lǐng)導(dǎo)者索引上的副本數(shù)量不會被跟隨者索引復(fù)制,因此可能無法檢索該設(shè)置。
如果你對跟隨者索引所需的領(lǐng)導(dǎo)者索引應(yīng)用非動態(tài)設(shè)置更改,則跟隨者索引將自行關(guān)閉,應(yīng)用設(shè)置更新,然后重新打開自身。 在此周期內(nèi),跟隨者索引不可用于讀取,也無法復(fù)制寫入。
使用遠程恢復(fù)初始化跟隨者
當(dāng)你創(chuàng)建跟隨者索引時,在其完全初始化之前你無法使用它。 遠程恢復(fù)(remote recovery)過程通過從領(lǐng)導(dǎo)者集群中的主分片復(fù)制數(shù)據(jù)來在跟隨者節(jié)點上構(gòu)建分片的新副本。
Elasticsearch 使用此遠程恢復(fù)過程,使用領(lǐng)導(dǎo)者索引中的數(shù)據(jù)來引導(dǎo)跟隨者索引。 此過程為跟隨者提供了領(lǐng)導(dǎo)者索引當(dāng)前狀態(tài)的副本,即使由于 Lucene 段合并而無法在領(lǐng)導(dǎo)者上獲得完整的更改歷史記錄。
遠程恢復(fù)是一個網(wǎng)絡(luò)密集型過程,它將所有 Lucene 段文件從領(lǐng)導(dǎo)者集群傳輸?shù)礁S者集群。 跟隨者請求在領(lǐng)導(dǎo)者集群中的主分片上啟動恢復(fù)會話。 然后,跟隨者同時向領(lǐng)導(dǎo)者請求文件塊。 默認情況下,進程同時請求五個 1MB 文件塊。 此默認行為旨在支持領(lǐng)導(dǎo)者和跟隨者集群之間存在高網(wǎng)絡(luò)延遲。
提示:你可以修改動態(tài)遠程恢復(fù)設(shè)置以限制傳輸數(shù)據(jù)的速率并管理遠程恢復(fù)消耗的資源。
在包含跟隨者索引的集群上使用 recovery?API 來獲取有關(guān)正在進行的遠程恢復(fù)的信息。 由于 Elasticsearch 使用快照和恢復(fù)(snapshot 及 restore)基礎(chǔ)設(shè)施實現(xiàn)遠程恢復(fù),因此運行遠程恢復(fù)在 recovery?API 中被標記為 snapshot 類型。
復(fù)制領(lǐng)導(dǎo)者需要軟刪除(soft deletes)
跨集群復(fù)制的工作原理是重播在領(lǐng)導(dǎo)索引分片上執(zhí)行的各個寫入操作的歷史記錄。 Elasticsearch 需要在領(lǐng)導(dǎo)者分片上保留這些操作的歷史記錄,以便跟隨者分片任務(wù)可以拉動它們。 用于保留這些操作的底層機制是軟刪除。
每當(dāng)刪除或更新現(xiàn)有文檔時都會發(fā)生軟刪除。 通過將這些軟刪除保留到可配置的限制,操作歷史記錄可以保留在領(lǐng)導(dǎo)者分片上,并在跟隨者分片任務(wù)重播操作歷史記錄時可供其使用。
index.soft_deletes.retention_lease.period 設(shè)置定義分片歷史保留租約在被視為過期之前保留的最長時間。 此設(shè)置決定包含你的跟隨者索引的集群可以離線多長時間,默認情況下為 12 小時。 如果分片副本在其保留租約到期后恢復(fù),但丟失的操作在領(lǐng)導(dǎo)者索引上仍然可用,則 Elasticsearch 將建立新的租約并復(fù)制丟失的操作。 然而 Elasticsearch 不保證保留未釋放的操作,因此也有可能一些丟失的操作已被領(lǐng)導(dǎo)者丟棄,現(xiàn)在完全不可用。 如果發(fā)生這種情況,則跟隨者無法自動恢復(fù),因此你必須重新創(chuàng)建它。
必須為要用作領(lǐng)導(dǎo)索引的索引啟用軟刪除。 默認情況下,在 Elasticsearch 7.0.0 或之后創(chuàng)建的新索引上啟用軟刪除。
重要:跨集群復(fù)制不能用于使用 Elasticsearch 7.0.0 或更早版本創(chuàng)建的現(xiàn)有索引,其中禁用了軟刪除。 你必須將數(shù)據(jù)重新索引到啟用軟刪除的新索引中。
實操
安裝 Elasticsearch 及 Kibana
如果你還沒有安裝好自己的 Elasticsearch 及 Kibana,你可以參考如下下面的文章來進行安裝:
-
如何在 Linux,MacOS 及 Windows 上進行安裝 Elasticsearch
-
Kibana:如何在 Linux,MacOS 及 Windows 上安裝 Elastic 棧中的 Kibana
在安裝的時候,我們需要特別注意的是:我們按照 Elastic Stack 8.x 的指南來進行安裝。在今天的練習(xí)中,我將使用 Elastic Stack 8.8.1 來進行展示。我們將以如下的架構(gòu)來進行展示:
?在上面,我們分別在兩個機器上創(chuàng)建兩個不同的集群。在安裝的時候,我們需要對 config/elasticsearch.yml 做一些特殊的配置:
config/elasticsearch.yml - macOS
config/elasticsearch.yml - ubuntu
針對非 keystore 及 truststore 的安裝
我們首先參考之前的文章 “Elasticsearch:如何在不更新證書的情況下為集群之間建立互信”。你如果不是按照默認的方式來進行 安裝 Elasticsearch 集群的,比如針對非 keystore 及 trustore 的安裝,參照我之前的文章 “Security:如何安裝 Elastic SIEM 和 EDR” 來進行安裝,那么你可以直接把另外一個集群的證書添加到相應(yīng)的 config/elasticsearch.yml 的配置中去即可:
config/elasticsearch.yml
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.key: /etc/elasticsearch/certs/elasticsearch.key
xpack.security.transport.ssl.certificate: /etc/elasticsearch/certs/elasticsearch.crt
xpack.security.transport.ssl.certificate_authorities: [ "/etc/elasticsearch/certs/ca/ca.crt", "certificate_from_another_cluster.crt ]
有關(guān)使用自定義的證書安裝 Elasticsearch 集群,請參閱文章 “Elasticsearch:如何使用自定義的證書安裝 Elastic Stack 8.x”。
為集群之間建立互信
針對使用 keystore 及 truststore 安裝的兩個 Elasticsearch 集群,我們?yōu)榱四軌蚴顾鼈兘⒒バ?,我們需要針對它們的配置文件做一些配置。它們的證書存在于 Elasticsearch 的安裝目錄中:
macOS
$ pwd
/Users/liuxg/elastic/elasticsearch-8.8.1
$ ls config/certs/
http.p12 http_ca.crt transport.p12
Ubuntu OS
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ pwd
/home/parallels/elastic/elasticsearch-8.8.1
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ ls config/certs/
http_ca.crt http.p12 transport.p12
為了獲取在默認 Elasticsearch 安裝的證書信息,我們使用如下的步驟來進行獲得,以 macOS 為例:
$ pwd
/Users/liuxg/elastic/elasticsearch-8.8.1
$ ./bin/elasticsearch-keystore list
keystore.seed
xpack.security.http.ssl.keystore.secure_password
xpack.security.transport.ssl.keystore.secure_password
xpack.security.transport.ssl.truststore.secure_password
$ ./bin/elasticsearch-keystore show xpack.security.transport.ssl.truststore.secure_password
ABFwaZgkTaiE-WrMvXy9Tw
$ cd config/certs/
$ openssl pkcs12 -in transport.p12 -out macOS.crt -clcerts -nokeys
Enter Import Password:
$ ls
http.p12 http_ca.crt macOS.crt transport.p12
在上面提示輸入密碼的時候,請輸入在上面步驟中得到的密碼即可。這樣我們就得到了 macOS 上安裝的 Elasticsearch 的證書。
我們把這個 macOS.crt 證書拷貝到 Ubuntu OS 中的 Elasticsearch 安裝目錄中:
scp macOS.crt parallels@ubuntu2004:/home/parallels/elastic/elasticsearch-8.8.1/config/certs
我們可以在 Ubuntu OS 的機器上進行查看:
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ pwd
/home/parallels/elastic/elasticsearch-8.8.1/config/certs
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ ls
http_ca.crt http.p12 macOS.crt transport.p12
按照同樣的方法,我們可以得到 Ubuntu OS 上 Elasticsearch 安裝的證書 ubuntu.crt:
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ pwd
/home/parallels/elastic/elasticsearch-8.8.1
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ ls config/certs/
http_ca.crt http.p12 transport.p12
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ ./bin/elasticsearch-keystore list
keystore.seed
xpack.security.http.ssl.keystore.secure_password
xpack.security.transport.ssl.keystore.secure_password
xpack.security.transport.ssl.truststore.secure_password
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ ./bin/elasticsearch-keystore show xpack.security.transport.ssl.truststore.secure_password
Npb620rZQbuqyKvw1DT0xw
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ cd config/certs/
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ openssl pkcs12 -in transport.p12 -out ubuntu.crt -clcerts -nokeys
Enter Import Password:
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ ls
http_ca.crt http.p12 transport.p12 ubuntu.crt
從上面的輸出中,我們可以看到我們已經(jīng)得到了 Ubuntu OS 機器上的證書 ubuntu.crt。
我們把上面的 ubuntu.crt 證書拷貝到 macOS 的機器中的 Elasticsearch 安裝目錄中:
scp parallels@ubuntu2004:/home/parallels/elastic/elasticsearch-8.8.1/config/certs/ubuntu.crt .
$ pwd
/Users/liuxg/elastic/elasticsearch-8.8.1/config/certs
$ scp parallels@ubuntu2004:/home/parallels/elastic/elasticsearch-8.8.1/config/certs/ubuntu.crt .
ubuntu.crt 100% 2060 3.4MB/s 00:00
$ ls
http.p12 http_ca.crt macOS.crt transport.p12 ubuntu.crt
我們可以使用如下的命令來查看當(dāng)前 macOS 里 transport.p12 的證書信息:
$ pwd
/Users/liuxg/elastic/elasticsearch-8.8.1
$ ./bin/elasticsearch-keystore list
keystore.seed
xpack.security.http.ssl.keystore.secure_password
xpack.security.transport.ssl.keystore.secure_password
xpack.security.transport.ssl.truststore.secure_password
$ ./bin/elasticsearch-keystore show xpack.security.transport.ssl.truststore.secure_password
ABFwaZgkTaiE-WrMvXy9Tw
$ cd config/certs/
$ ls
http.p12 http_ca.crt macOS.crt transport.p12 ubuntu.crt
$ keytool -keystore transport.p12 -list
Enter keystore password:
Keystore type: PKCS12
Keystore provider: SUN
Your keystore contains 2 entries
transport, Jun 13, 2023, PrivateKeyEntry,
Certificate fingerprint (SHA-256): BB:F1:F4:71:A3:19:0B:48:7A:E8:23:1A:DB:F1:01:3A:02:61:B7:C7:08:E1:68:1B:1E:2A:55:D1:D6:66:39:E2
transport_ca, Jun 29, 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): E8:2B:C2:5F:B2:30:30:AC:AA:C9:DE:DE:E6:FB:C2:EC:47:E7:C7:D6:21:8F:4B:63:9D:58:C1:1C:75:CF:9C:04
從上面,我們可以看出來,它里面有兩個證書。現(xiàn)在我們使用如下的方法把 ubuntu.crt 這個證書添加到 transport.p12 這個 truststore 里去。
$ pwd
/Users/liuxg/elastic/elasticsearch-8.8.1
$ ./bin/elasticsearch-keystore list
keystore.seed
xpack.security.http.ssl.keystore.secure_password
xpack.security.transport.ssl.keystore.secure_password
xpack.security.transport.ssl.truststore.secure_password
$ ./bin/elasticsearch-keystore show xpack.security.transport.ssl.truststore.secure_password
ABFwaZgkTaiE-WrMvXy9Tw
$ cd config/certs/
$ ls
http.p12 http_ca.crt macOS.crt transport.p12 ubuntu.crt
$ keytool -keystore transport.p12 -list
Enter keystore password:
Keystore type: PKCS12
Keystore provider: SUN
Your keystore contains 2 entries
transport, Jun 13, 2023, PrivateKeyEntry,
Certificate fingerprint (SHA-256): BB:F1:F4:71:A3:19:0B:48:7A:E8:23:1A:DB:F1:01:3A:02:61:B7:C7:08:E1:68:1B:1E:2A:55:D1:D6:66:39:E2
transport_ca, Jun 29, 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): E8:2B:C2:5F:B2:30:30:AC:AA:C9:DE:DE:E6:FB:C2:EC:47:E7:C7:D6:21:8F:4B:63:9D:58:C1:1C:75:CF:9C:04
$ keytool -importcert -trustcacerts -noprompt -keystore transport.p12 -storepass ABFwaZgkTaiE-WrMvXy9Tw -alias ubuntu -file ubuntu.crt
Certificate was added to keystore
$ keytool -keystore transport.p12 -list
Enter keystore password:
Keystore type: PKCS12
Keystore provider: SUN
Your keystore contains 3 entries
transport, Jun 13, 2023, PrivateKeyEntry,
Certificate fingerprint (SHA-256): BB:F1:F4:71:A3:19:0B:48:7A:E8:23:1A:DB:F1:01:3A:02:61:B7:C7:08:E1:68:1B:1E:2A:55:D1:D6:66:39:E2
transport_ca, Jun 29, 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): E8:2B:C2:5F:B2:30:30:AC:AA:C9:DE:DE:E6:FB:C2:EC:47:E7:C7:D6:21:8F:4B:63:9D:58:C1:1C:75:CF:9C:04
ubuntu, Jun 29, 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): 1B:69:D9:26:F2:4A:3C:91:CD:01:9F:DC:70:9D:3E:BA:97:FE:B2:67:FC:E9:62:46:AD:8A:74:41:F5:BB:CF:D3
?
按照同樣的方法,我們在 Ubuntu OS 的機器上,添加 macOS.crt 證書:
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ pwd
/home/parallels/elastic/elasticsearch-8.8.1
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ ./bin/elasticsearch-keystore list
keystore.seed
xpack.security.http.ssl.keystore.secure_password
xpack.security.transport.ssl.keystore.secure_password
xpack.security.transport.ssl.truststore.secure_password
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ ./bin/elasticsearch-keystore show xpack.security.transport.ssl.truststore.secure_password
Npb620rZQbuqyKvw1DT0xw
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1$ cd config/certs/
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ ls
http_ca.crt http.p12 macOS.crt transport.p12 ubuntu.crt
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ keytool -keystore transport.p12 -list
Enter keystore password:
Keystore type: PKCS12
Keystore provider: SUN
Your keystore contains 2 entries
transport, Jun 27, 2023, PrivateKeyEntry,
Certificate fingerprint (SHA-256): 1B:69:D9:26:F2:4A:3C:91:CD:01:9F:DC:70:9D:3E:BA:97:FE:B2:67:FC:E9:62:46:AD:8A:74:41:F5:BB:CF:D3
transport_ca, Jun 29, 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): 53:ED:41:99:06:24:1D:86:37:07:0D:19:9B:7B:73:00:09:A8:D3:5D:E7:EF:DC:A4:CE:C7:26:6E:12:F2:A9:32
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ ls
http_ca.crt http.p12 macOS.crt transport.p12 ubuntu.crt
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ keytool -importcert -trustcacerts -noprompt -keystore transport.p12 -storepass Npb620rZQbuqyKvw1DT0xw -alias mac -file macOS.crt
Certificate was added to keystore
parallels@ubuntu2004:~/elastic/elasticsearch-8.8.1/config/certs$ keytool -keystore transport.p12 -list
Enter keystore password:
Keystore type: PKCS12
Keystore provider: SUN
Your keystore contains 3 entries
mac, Jun 29, 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): BB:F1:F4:71:A3:19:0B:48:7A:E8:23:1A:DB:F1:01:3A:02:61:B7:C7:08:E1:68:1B:1E:2A:55:D1:D6:66:39:E2
transport, Jun 27, 2023, PrivateKeyEntry,
Certificate fingerprint (SHA-256): 1B:69:D9:26:F2:4A:3C:91:CD:01:9F:DC:70:9D:3E:BA:97:FE:B2:67:FC:E9:62:46:AD:8A:74:41:F5:BB:CF:D3
transport_ca, Jun 29, 2023, trustedCertEntry,
Certificate fingerprint (SHA-256): 53:ED:41:99:06:24:1D:86:37:07:0D:19:9B:7B:73:00:09:A8:D3:5D:E7:EF:DC:A4:CE:C7:26:6E:12:F2:A9:32
我們需要重新啟動在兩個操作系統(tǒng)中的 Elasticsearch。
測試集群之間的互信
我們接下來通過 Kibana 來測試集群之間的互信。按照一下的步驟來進行操作:
上面顯示我們的連接是成功的。當(dāng)然,我們也可以在 Ubuntu 機器安裝的 Elasticsearch 來連接 macOS 上的安裝,它也應(yīng)該是成功的:
?
從上面的顯示中,我們可以看到在 Ubuntu OS 上的 Elasticsearch 集群也可以成功地連接到 macOS 的機器上。
測試 CCR?
接下來,我們來做一些簡單的測試來看看 CCR 是如何工作的。我們在 macOS 里的 Kibana 進行如下的操作。由于 CCR 是收費的功能,我們需要啟動白金版試用功能。這個操作需要在兩個集群里分別進行。
我們也可以通過如下的命令來啟動試用功能:
$ curl -k -u elastic -X POST "https://localhost:9200/_license/start_trial?acknowledge=true"
Enter host password for user 'elastic':
{"acknowledged":true,"trial_was_started":false,"error_message":"Operation failed: Trial was already activated."}
或者直接在 Dev Tools 里打入如下的命令:
POST _license/start_trial?acknowledge=true
我們在 macOS 的 Elasticsearch 集群里打入如下的命令:
PUT twitter/_doc/1
{
"content": "This is Xiaoguo from Elastic"
}
我們?nèi)?Ubuntu OS 的機器上,進行如下的操作:
經(jīng)過一會兒:
我們?nèi)?Ubuntu OS 的 Dev Tools 里進如下操作:
我們可以看到 twitter_follower 里的文檔已經(jīng)是和在 macOS 里的 twitter 索引是一模一樣的。我們可以去 macOS 的 Elasticsearch 集群里添加另外一個文檔:
PUT twitter/_doc/2
{
"content": "Xiaoguo is doing community work in Elastic"
}
我們再在 Ubuntu OS 的 Dev Tools 里進行查看:
很顯然,我們這次有兩個文檔了。文章來源:http://www.zghlxwxcb.cn/news/detail-508210.html
Hooray! 我們終于在兩個集群里進行了負責(zé)。當(dāng)然,你也可以嘗試雙向復(fù)制哦。在 macOS 里復(fù)制在 Ubuntu OS 里的索引。這個就留個開發(fā)者你們自己來嘗試了。文章來源地址http://www.zghlxwxcb.cn/news/detail-508210.html
到了這里,關(guān)于Elasticsearch:跨集群復(fù)制應(yīng)用場景及實操 - Cross Cluster Replication 為集群之間建立互信的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!