getting-started.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[ccr-getting-started]]
  4. === Tutorial: Set up {ccr}
  5. ++++
  6. <titleabbrev>Set up {ccr}</titleabbrev>
  7. ++++
  8. ////
  9. [source,console]
  10. ----
  11. PUT /server-metrics
  12. {
  13. "settings" : {
  14. "index" : {
  15. "number_of_shards" : 1,
  16. "number_of_replicas" : 0
  17. }
  18. },
  19. "mappings" : {
  20. "properties" : {
  21. "@timestamp" : {
  22. "type" : "date"
  23. },
  24. "accept" : {
  25. "type" : "long"
  26. },
  27. "deny" : {
  28. "type" : "long"
  29. },
  30. "host" : {
  31. "type" : "keyword"
  32. },
  33. "response" : {
  34. "type" : "float"
  35. },
  36. "service" : {
  37. "type" : "keyword"
  38. },
  39. "total" : {
  40. "type" : "long"
  41. }
  42. }
  43. }
  44. }
  45. ----
  46. // TESTSETUP
  47. ////
  48. Use this guide to set up {ccr} (CCR) between clusters in two
  49. datacenters. Replicating your data across datacenters provides several benefits:
  50. * Brings data closer to your users or application server to reduce latency and
  51. response time
  52. * Provides your mission-critical applications with the tolerance to withstand datacenter or region outages
  53. In this guide, you'll learn how to:
  54. * Configure a <<modules-remote-clusters,remote cluster>> with a leader index
  55. * Create a follower index on a local cluster
  56. * Create an auto-follow pattern to automatically follow time series indices
  57. that are periodically created in a remote cluster
  58. You can manually create follower indices to replicate specific indices on a
  59. remote cluster, or configure auto-follow patterns to replicate rolling time series indices.
  60. video::https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt994089f5e841ad69/5f6265de6f40ab4648b5cf9b/ccr-setup-video-edited.mp4[width=700, height=500, options="autoplay,loop"]
  61. [[ccr-getting-started-prerequisites]]
  62. ==== Prerequisites
  63. To complete this tutorial, you need:
  64. * A license on both clusters that includes {ccr}. {kibana-ref}/managing-licenses.html[Activate a free 30-day trial].
  65. * The `read_ccr` cluster privilege and `monitor` and `read` privileges
  66. for the leader index on the remote cluster. <<stack-management-ccr-remote,Configure remote cluster privileges>>.
  67. * The `manage_ccr` cluster privilege and `monitor`, `read`, `write` and
  68. `manage_follow_index` privileges to configure remote clusters and follower
  69. indices on the local cluster. <<stack-management-ccr-local,Configure local cluster privileges>>.
  70. * An index on the remote cluster that contains the data you want to replicate.
  71. This tutorial uses the sample eCommerce orders data set.
  72. {kibana-ref}/get-started.html#gs-get-data-into-kibana[Load sample data].
  73. [[ccr-getting-started-remote-cluster]]
  74. ==== Connect to a remote cluster
  75. To replicate an index on a remote cluster (Cluster A) to a local cluster (Cluster B), you configure Cluster A as a remote on Cluster B.
  76. image::images/ccr-tutorial-clusters.png[ClusterA contains the leader index and ClusterB contains the follower index]
  77. To configure a remote cluster from Stack Management in {kib}:
  78. . Select *Remote Clusters* from the side navigation.
  79. . Specify the IP address or host name of the remote cluster (ClusterB),
  80. followed by the transport port of the remote cluster (defaults to `9300`). For
  81. example, `192.168.1.1:9300`.
  82. [role="screenshot"]
  83. image::images/ccr-add-remote-cluster.png["The Add remote clusters page in {kib}"]
  84. [%collapsible]
  85. .API example
  86. ====
  87. Use the <<cluster-update-settings,cluster update settings API>> to add a remote cluster:
  88. [source,console]
  89. --------------------------------------------------
  90. PUT /_cluster/settings
  91. {
  92. "persistent" : {
  93. "cluster" : {
  94. "remote" : {
  95. "leader" : {
  96. "seeds" : [
  97. "127.0.0.1:9300" <1>
  98. ]
  99. }
  100. }
  101. }
  102. }
  103. }
  104. --------------------------------------------------
  105. // TEST[setup:host]
  106. // TEST[s/127.0.0.1:9300/\${transport_host}/]
  107. <1> Specifies the hostname and transport port of a seed node in the remote
  108. cluster.
  109. You can verify that the local cluster is successfully connected to the remote
  110. cluster.
  111. [source,console]
  112. --------------------------------------------------
  113. GET /_remote/info
  114. --------------------------------------------------
  115. // TEST[continued]
  116. The API will respond by showing that the local cluster is connected to the
  117. remote cluster.
  118. [source,console-result]
  119. --------------------------------------------------
  120. {
  121. "leader" : {
  122. "seeds" : [
  123. "127.0.0.1:9300"
  124. ],
  125. "connected" : true, <1>
  126. "num_nodes_connected" : 1, <2>
  127. "max_connections_per_cluster" : 3,
  128. "initial_connect_timeout" : "30s",
  129. "skip_unavailable" : false,
  130. "mode" : "sniff"
  131. }
  132. }
  133. --------------------------------------------------
  134. // TESTRESPONSE[s/127.0.0.1:9300/$body.leader.seeds.0/]
  135. // TEST[s/"connected" : true/"connected" : $body.leader.connected/]
  136. // TEST[s/"num_nodes_connected" : 1/"num_nodes_connected" : $body.leader.num_nodes_connected/]
  137. <1> This shows the local cluster is connected to the remote cluster with cluster
  138. alias `leader`
  139. <2> This shows the number of nodes in the remote cluster the local cluster is
  140. connected to.
  141. ====
  142. [[ccr-enable-soft-deletes]]
  143. ==== Enable soft deletes on leader indices
  144. To follow an index, it must have been created with
  145. <<ccr-leader-requirements,soft deletes>> enabled. If the index doesn’t have
  146. soft deletes enabled, you must reindex it and use the new index as the leader
  147. index. Soft deletes are enabled by default on new indices
  148. created with {es} 7.0.0 and later.
  149. [[ccr-getting-started-follower-index]]
  150. ==== Create a follower index to replicate a specific index
  151. When you create a follower index, you reference the remote cluster and the
  152. leader index in your remote cluster.
  153. To create a follower index from Stack Management in {kib}:
  154. . Select *Cross-Cluster Replication* in the side navigation and choose the
  155. *Follower Indices* tab.
  156. . Choose the cluster (ClusterA) containing the leader index you want to
  157. replicate.
  158. . Enter the name of the leader index, which is
  159. `kibana_sample_data_ecommerce` if you are following the tutorial.
  160. . Enter a name for your follower index, such as `follower-kibana-sample-data`.
  161. image::images/ccr-add-follower-index.png["Adding a follower index named server-metrics in {kib}"]
  162. {es} initializes the follower using the
  163. <<ccr-remote-recovery, remote recovery>>
  164. process, which transfers the existing Lucene segment files from the leader
  165. index to the follower index. The index status changes to *Paused*. When the
  166. remote recovery process is complete, the index following begins and the status
  167. changes to *Active*.
  168. When you index documents into your leader index, {es} replicates the documents
  169. in the follower index.
  170. [role="screenshot"]
  171. image::images/ccr-follower-index.png["The Cross-Cluster Replication page in {kib}"]
  172. [%collapsible]
  173. .API example
  174. ====
  175. Use the <<ccr-put-follow,create follower API>> to create follower indices.
  176. When you create a follower index, you must reference the remote cluster and the
  177. leader index that you created in the
  178. remote cluster.
  179. When initiating the follower request, the response returns before the
  180. <<ccr-remote-recovery, remote recovery>> process completes. To wait for the process
  181. to complete, add the `wait_for_active_shards` parameter to your request.
  182. [source,console]
  183. --------------------------------------------------
  184. PUT /server-metrics-follower/_ccr/follow?wait_for_active_shards=1
  185. {
  186. "remote_cluster" : "leader",
  187. "leader_index" : "server-metrics"
  188. }
  189. --------------------------------------------------
  190. // TEST[continued]
  191. //////////////////////////
  192. [source,console-result]
  193. --------------------------------------------------
  194. {
  195. "follow_index_created" : true,
  196. "follow_index_shards_acked" : true,
  197. "index_following_started" : true
  198. }
  199. --------------------------------------------------
  200. //////////////////////////
  201. Use the
  202. <<ccr-get-follow-stats,get follower stats API>> to inspect the status of
  203. replication
  204. //////////////////////////
  205. [source,console]
  206. --------------------------------------------------
  207. POST /server-metrics-follower/_ccr/pause_follow
  208. POST /server-metrics-follower/_close
  209. POST /server-metrics-follower/_ccr/unfollow
  210. --------------------------------------------------
  211. // TEST[continued]
  212. //////////////////////////
  213. ====
  214. [[ccr-getting-started-auto-follow]]
  215. ==== Create an auto-follow pattern to replicate time series indices
  216. You use <<ccr-auto-follow,auto-follow patterns>> to automatically create new
  217. followers for rolling time series indices. Whenever the name of a new index on
  218. the remote cluster matches the auto-follow pattern, a corresponding follower
  219. index is added to the local cluster.
  220. An auto-follow pattern specifies the remote cluster you want to replicate from,
  221. and one or more index patterns that specify the rolling time series indices you
  222. want to replicate.
  223. // tag::ccr-create-auto-follow-pattern-tag[]
  224. To create an auto-follow pattern from Stack Management in {kib}:
  225. . Select *Cross Cluster Replication* in the side navigation and choose the
  226. *Auto-follow patterns* tab.
  227. . Enter a name for the auto-follow pattern, such as `beats`.
  228. . Choose the remote cluster that contains the index you want to replicate,
  229. which in the example scenario is Cluster A.
  230. . Enter one or more index patterns that identify the indices you want to
  231. replicate from the remote cluster. For example, enter
  232. `metricbeat-* packetbeat-*` to automatically create followers for {metricbeat} and {packetbeat} indices.
  233. . Enter *follower-* as the prefix to apply to the names of the follower indices so
  234. you can more easily identify replicated indices.
  235. As new indices matching these patterns are
  236. created on the remote, {es} automatically replicates them to local follower indices.
  237. [role="screenshot"]
  238. image::images/auto-follow-patterns.png["The Auto-follow patterns page in {kib}"]
  239. // end::ccr-create-auto-follow-pattern-tag[]
  240. [%collapsible]
  241. .API example
  242. ====
  243. Use the <<ccr-put-auto-follow-pattern,create auto-follow pattern API>> to
  244. configure auto-follow patterns.
  245. [source,console]
  246. --------------------------------------------------
  247. PUT /_ccr/auto_follow/beats
  248. {
  249. "remote_cluster" : "leader",
  250. "leader_index_patterns" :
  251. [
  252. "metricbeat-*", <1>
  253. "packetbeat-*" <2>
  254. ],
  255. "follow_index_pattern" : "{{leader_index}}-copy" <3>
  256. }
  257. --------------------------------------------------
  258. // TEST[continued]
  259. <1> Automatically follow new {metricbeat} indices.
  260. <2> Automatically follow new {packetbeat} indices.
  261. <3> The name of the follower index is derived from the name of the leader index
  262. by adding the suffix `-copy` to the name of the leader index.
  263. //////////////////////////
  264. [source,console-result]
  265. --------------------------------------------------
  266. {
  267. "acknowledged" : true
  268. }
  269. --------------------------------------------------
  270. //////////////////////////
  271. //////////////////////////
  272. [source,console]
  273. --------------------------------------------------
  274. DELETE /_ccr/auto_follow/beats
  275. --------------------------------------------------
  276. // TEST[continued]
  277. //////////////////////////
  278. ====