uni-directional-disaster-recovery.asciidoc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. [role="xpack"]
  2. [[ccr-disaster-recovery-uni-directional-tutorial]]
  3. === Tutorial: Disaster recovery based on uni-directional {ccr}
  4. ++++
  5. <titleabbrev>Uni-directional disaster recovery</titleabbrev>
  6. ++++
  7. ////
  8. [source,console]
  9. ----
  10. PUT kibana_sample_data_ecommerce
  11. ----
  12. // TESTSETUP
  13. [source,console]
  14. ----
  15. DELETE kibana_sample_data_ecommerce
  16. ----
  17. // TEARDOWN
  18. ////
  19. Learn how to failover and failback between two clusters based on uni-directional {ccr}. You can also visit <<ccr-disaster-recovery-bi-directional-tutorial>> to set up replicating data streams that automatically failover and failback without human intervention.
  20. * Setting up uni-directional {ccr} replicated from `clusterA`
  21. to `clusterB`.
  22. * Failover - If `clusterA` goes offline, `clusterB` needs to "promote" follower
  23. indices to regular indices to allow write operations. All ingestion will need to
  24. be redirected to `clusterB`, this is controlled by the clients ({ls}, {beats},
  25. {agents}, etc).
  26. * Failback - When `clusterA` is back online, it assumes the role of a follower
  27. and replicates the leader indices from `clusterB`.
  28. image::images/ccr-uni-directional-disaster-recovery.png[Uni-directional cross cluster replication failover and failback]
  29. NOTE: {ccr-cap} provides functionality to replicate user-generated indices only.
  30. {ccr-cap} isn't designed for replicating system-generated indices or snapshot
  31. settings, and can't replicate {ilm-init} or {slm-init} policies across clusters.
  32. Learn more in {ccr} <<ccr-limitations,limitations>>.
  33. ==== Prerequisites
  34. Before completing this tutorial,
  35. <<ccr-getting-started-tutorial,set up cross-cluster replication>> to connect two
  36. clusters and configure a follower index.
  37. In this tutorial, `kibana_sample_data_ecommerce` is replicated from `clusterA` to `clusterB`.
  38. [source,console]
  39. ----
  40. ### On clusterB ###
  41. PUT _cluster/settings
  42. {
  43. "persistent": {
  44. "cluster": {
  45. "remote": {
  46. "clusterA": {
  47. "mode": "proxy",
  48. "skip_unavailable": "true",
  49. "server_name": "clustera.es.region-a.gcp.elastic-cloud.com",
  50. "proxy_socket_connections": "18",
  51. "proxy_address": "clustera.es.region-a.gcp.elastic-cloud.com:9400"
  52. }
  53. }
  54. }
  55. }
  56. }
  57. ----
  58. // TEST[setup:host]
  59. // TEST[s/"server_name": "clustera.es.region-a.gcp.elastic-cloud.com",//]
  60. // TEST[s/"proxy_socket_connections": 18,//]
  61. // TEST[s/clustera.es.region-a.gcp.elastic-cloud.com:9400/\${transport_host}/]
  62. // TEST[s/clusterA/remote_cluster/]
  63. [source,console]
  64. ----
  65. ### On clusterB ###
  66. PUT /kibana_sample_data_ecommerce2/_ccr/follow?wait_for_active_shards=1
  67. {
  68. "remote_cluster": "clusterA",
  69. "leader_index": "kibana_sample_data_ecommerce"
  70. }
  71. ----
  72. // TEST[continued]
  73. // TEST[s/clusterA/remote_cluster/]
  74. IMPORTANT: Writes (such as ingestion or updates) should occur only on the leader
  75. index. Follower indices are read-only and will reject any writes.
  76. ==== Failover when `clusterA` is down
  77. . Promote the follower indices in `clusterB` into regular indices so
  78. that they accept writes. This can be achieved by:
  79. * First, pause indexing following for the follower index.
  80. * Next, close the follower index.
  81. * Unfollow the leader index.
  82. * Finally, open the follower index (which at this point is a regular index).
  83. +
  84. [source,console]
  85. ----
  86. ### On clusterB ###
  87. POST /kibana_sample_data_ecommerce2/_ccr/pause_follow
  88. POST /kibana_sample_data_ecommerce2/_close
  89. POST /kibana_sample_data_ecommerce2/_ccr/unfollow
  90. POST /kibana_sample_data_ecommerce2/_open
  91. ----
  92. // TEST[continued]
  93. . On the client side ({ls}, {beats}, {agent}), manually re-enable ingestion of
  94. `kibana_sample_data_ecommerce2` and redirect traffic to the `clusterB`. You should
  95. also redirect all search traffic to the `clusterB` cluster during
  96. this time. You can simulate this by ingesting documents into this index. You should
  97. notice this index is now writable.
  98. +
  99. [source,console]
  100. ----
  101. ### On clusterB ###
  102. POST kibana_sample_data_ecommerce2/_doc/
  103. {
  104. "user": "kimchy"
  105. }
  106. ----
  107. // TEST[continued]
  108. ==== Failback when `clusterA` comes back
  109. When `clusterA` comes back, `clusterB` becomes the new leader and `clusterA` becomes the follower.
  110. . Set up remote cluster `clusterB` on `clusterA`.
  111. +
  112. [source,console]
  113. ----
  114. ### On clusterA ###
  115. PUT _cluster/settings
  116. {
  117. "persistent": {
  118. "cluster": {
  119. "remote": {
  120. "clusterB": {
  121. "mode": "proxy",
  122. "skip_unavailable": "true",
  123. "server_name": "clusterb.es.region-b.gcp.elastic-cloud.com",
  124. "proxy_socket_connections": "18",
  125. "proxy_address": "clusterb.es.region-b.gcp.elastic-cloud.com:9400"
  126. }
  127. }
  128. }
  129. }
  130. }
  131. ----
  132. // TEST[setup:host]
  133. // TEST[s/"server_name": "clusterb.es.region-b.gcp.elastic-cloud.com",//]
  134. // TEST[s/"proxy_socket_connections": 18,//]
  135. // TEST[s/clusterb.es.region-b.gcp.elastic-cloud.com:9400/\${transport_host}/]
  136. // TEST[s/clusterB/remote_cluster/]
  137. . Existing data needs to be discarded before you can turn any index into a
  138. follower. Ensure the most up-to-date data is available on `clusterB` prior to
  139. deleting any indices on `clusterA`.
  140. +
  141. [source,console]
  142. ----
  143. ### On clusterA ###
  144. DELETE kibana_sample_data_ecommerce
  145. ----
  146. // TEST[skip:need dual cluster setup]
  147. . Create a follower index on `clusterA`, now following the leader index in
  148. `clusterB`.
  149. +
  150. [source,console]
  151. ----
  152. ### On clusterA ###
  153. PUT /kibana_sample_data_ecommerce/_ccr/follow?wait_for_active_shards=1
  154. {
  155. "remote_cluster": "clusterB",
  156. "leader_index": "kibana_sample_data_ecommerce2"
  157. }
  158. ----
  159. // TEST[continued]
  160. // TEST[s/clusterB/remote_cluster/]
  161. . The index on the follower cluster now contains the updated documents.
  162. +
  163. [source,console]
  164. ----
  165. ### On clusterA ###
  166. GET kibana_sample_data_ecommerce/_search?q=kimchy
  167. ----
  168. // TEST[continued]
  169. +
  170. TIP: If a soft delete is merged away before it can be replicated to a follower the following process will fail due to incomplete history on the leader, see <<ccr-index-soft-deletes-retention-period, index.soft_deletes.retention_lease.period>> for more details.