getting-started.asciidoc 11 KB

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