getting-started.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. [role="xpack"]
  2. [[ccr-getting-started-tutorial]]
  3. === Tutorial: Set up {ccr}
  4. ++++
  5. <titleabbrev>Set up {ccr}</titleabbrev>
  6. ++++
  7. ////
  8. [source,console]
  9. ----
  10. PUT /server-metrics
  11. {
  12. "settings" : {
  13. "index" : {
  14. "number_of_shards" : 1,
  15. "number_of_replicas" : 0
  16. }
  17. },
  18. "mappings" : {
  19. "properties" : {
  20. "@timestamp" : {
  21. "type" : "date"
  22. },
  23. "accept" : {
  24. "type" : "long"
  25. },
  26. "deny" : {
  27. "type" : "long"
  28. },
  29. "host" : {
  30. "type" : "keyword"
  31. },
  32. "response" : {
  33. "type" : "float"
  34. },
  35. "service" : {
  36. "type" : "keyword"
  37. },
  38. "total" : {
  39. "type" : "long"
  40. }
  41. }
  42. }
  43. }
  44. ----
  45. // TESTSETUP
  46. ////
  47. Use this guide to set up {ccr} (CCR) between clusters in two
  48. datacenters. Replicating your data across datacenters provides several benefits:
  49. * Brings data closer to your users or application server to reduce latency and
  50. response time
  51. * Provides your mission-critical applications with the tolerance to withstand datacenter or region outages
  52. In this guide, you'll learn how to:
  53. * Configure a <<remote-clusters,remote cluster>> with a leader index
  54. * Create a follower index on a local cluster
  55. * Create an auto-follow pattern to automatically follow time series indices
  56. that are periodically created in a remote cluster
  57. You can manually create follower indices to replicate specific indices on a
  58. remote cluster, or configure auto-follow patterns to replicate rolling time series indices.
  59. TIP: If you want to replicate data across clusters in the cloud, you can
  60. link:{cloud}/ec-enable-ccs.html[configure remote clusters on {ess}]. Then, you
  61. can <<modules-cross-cluster-search,search across clusters>> and set up {ccr}.
  62. [[ccr-getting-started-prerequisites]]
  63. ==== Prerequisites
  64. To complete this tutorial, you need:
  65. * The `manage` cluster privilege on the local cluster.
  66. * A license on both clusters that includes {ccr}. {kibana-ref}/managing-licenses.html[Activate a free 30-day trial].
  67. * An index on the remote cluster that contains the data you want to replicate.
  68. This tutorial uses the sample eCommerce orders data set.
  69. {kibana-ref}/get-started.html#gs-get-data-into-kibana[Load sample data].
  70. * In the local cluster, all nodes with the `master` <<node-roles,node role>> must
  71. also have the <<remote-node,`remote_cluster_client`>> role. The local cluster
  72. must also have at least one node with both a data role and the
  73. <<remote-node,`remote_cluster_client`>> role. Individual tasks for coordinating
  74. replication scale based on the number of data nodes with the
  75. `remote_cluster_client` role in the local cluster.
  76. ==== Connect to a remote cluster
  77. 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.
  78. image::images/ccr-tutorial-clusters.png[ClusterA contains the leader index and ClusterB contains the follower index]
  79. To configure a remote cluster from Stack Management in {kib}:
  80. . Set up a <<add-remote-clusters,secure connection>> as needed.
  81. . Select *Remote Clusters* from the side navigation.
  82. . Specify the {es} endpoint URL, or the IP address or host name of the remote
  83. cluster (`ClusterA`) followed by the transport port (defaults to `9300`). For
  84. example, `cluster.es.eastus2.staging.azure.foundit.no:9400` or
  85. `192.168.1.1:9300`.
  86. [%collapsible%open]
  87. .API example
  88. ====
  89. You can also use the <<cluster-update-settings,cluster update settings API>> to
  90. 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 response indicates that the local cluster is connected to the remote
  120. cluster with cluster alias `leader`.
  121. [source,console-result]
  122. ----
  123. {
  124. "leader" : {
  125. "seeds" : [
  126. "127.0.0.1:9300"
  127. ],
  128. "connected" : true,
  129. "num_nodes_connected" : 1, <1>
  130. "max_connections_per_cluster" : 3,
  131. "initial_connect_timeout" : "30s",
  132. "skip_unavailable" : true,
  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> The number of nodes in the remote cluster the local cluster is
  141. connected to.
  142. ====
  143. include::{es-ref-dir}/security/authentication/remote-clusters-privileges-cert.asciidoc[tag=configure-ccr-privileges]
  144. [[ccr-getting-started-follower-index]]
  145. ==== Create a follower index to replicate a specific index
  146. When you create a follower index, you reference the remote cluster and the
  147. leader index in your remote cluster.
  148. To create a follower index from Stack Management in {kib}:
  149. . Select *Cross-Cluster Replication* in the side navigation and choose the
  150. *Follower Indices* tab.
  151. . Choose the cluster (ClusterA) containing the leader index you want to
  152. replicate.
  153. . Enter the name of the leader index, which is
  154. `kibana_sample_data_ecommerce` if you are following the tutorial.
  155. . Enter a name for your follower index, such as `follower-kibana-sample-data`.
  156. {es} initializes the follower using the
  157. <<ccr-remote-recovery, remote recovery>>
  158. process, which transfers the existing Lucene segment files from the leader
  159. index to the follower index. The index status changes to *Paused*. When the
  160. remote recovery process is complete, the index following begins and the status
  161. changes to *Active*.
  162. When you index documents into your leader index, {es} replicates the documents
  163. in the follower index.
  164. [role="screenshot"]
  165. image::images/ccr-follower-index.png["The Cross-Cluster Replication page in {kib}"]
  166. [%collapsible%open]
  167. .API example
  168. ====
  169. You can also use the <<ccr-put-follow,create follower API>> to create follower
  170. indices. When you create a follower index, you must reference the remote cluster
  171. and the leader index that you created in the remote cluster.
  172. When initiating the follower request, the response returns before the
  173. <<ccr-remote-recovery, remote recovery>> process completes. To wait for the process
  174. to complete, add the `wait_for_active_shards` parameter to your request.
  175. [source,console]
  176. ----
  177. PUT /server-metrics-follower/_ccr/follow?wait_for_active_shards=1
  178. {
  179. "remote_cluster" : "leader",
  180. "leader_index" : "server-metrics"
  181. }
  182. ----
  183. // TEST[continued]
  184. //////////////////////////
  185. [source,console-result]
  186. --------------------------------------------------
  187. {
  188. "follow_index_created" : true,
  189. "follow_index_shards_acked" : true,
  190. "index_following_started" : true
  191. }
  192. --------------------------------------------------
  193. //////////////////////////
  194. Use the
  195. <<ccr-get-follow-stats,get follower stats API>> to inspect the status of
  196. replication.
  197. //////////////////////////
  198. [source,console]
  199. --------------------------------------------------
  200. POST /server-metrics-follower/_ccr/pause_follow
  201. POST /server-metrics-follower/_close
  202. POST /server-metrics-follower/_ccr/unfollow
  203. --------------------------------------------------
  204. // TEST[continued]
  205. //////////////////////////
  206. ====
  207. [[ccr-getting-started-auto-follow]]
  208. ==== Create an auto-follow pattern to replicate time series indices
  209. You use <<ccr-auto-follow,auto-follow patterns>> to automatically create new
  210. followers for rolling time series indices. Whenever the name of a new index on
  211. the remote cluster matches the auto-follow pattern, a corresponding follower
  212. index is added to the local cluster. Note that only indices created on the
  213. remote cluster after the auto-follow pattern is created will be auto-followed:
  214. existing indices on the remote cluster are ignored even if they match the pattern.
  215. An auto-follow pattern specifies the remote cluster you want to replicate from,
  216. and one or more index patterns that specify the rolling time series indices you
  217. want to replicate.
  218. // tag::ccr-create-auto-follow-pattern-tag[]
  219. To create an auto-follow pattern from Stack Management in {kib}:
  220. . Select *Cross Cluster Replication* in the side navigation and choose the
  221. *Auto-follow patterns* tab.
  222. . Enter a name for the auto-follow pattern, such as `beats`.
  223. . Choose the remote cluster that contains the index you want to replicate,
  224. which in the example scenario is Cluster A.
  225. . Enter one or more index patterns that identify the indices you want to
  226. replicate from the remote cluster. For example, enter
  227. `metricbeat-* packetbeat-*` to automatically create followers for {metricbeat} and {packetbeat} indices.
  228. . Enter *follower-* as the prefix to apply to the names of the follower indices so
  229. you can more easily identify replicated indices.
  230. As new indices matching these patterns are
  231. created on the remote, {es} automatically replicates them to local follower indices.
  232. [role="screenshot"]
  233. image::images/auto-follow-patterns.png["The Auto-follow patterns page in {kib}"]
  234. // end::ccr-create-auto-follow-pattern-tag[]
  235. [%collapsible%open]
  236. .API example
  237. ====
  238. Use the <<ccr-put-auto-follow-pattern,create auto-follow pattern API>> to
  239. configure auto-follow patterns.
  240. [source,console]
  241. ----
  242. PUT /_ccr/auto_follow/beats
  243. {
  244. "remote_cluster" : "leader",
  245. "leader_index_patterns" :
  246. [
  247. "metricbeat-*", <1>
  248. "packetbeat-*" <2>
  249. ],
  250. "follow_index_pattern" : "{{leader_index}}-copy" <3>
  251. }
  252. ----
  253. // TEST[continued]
  254. <1> Automatically follow new {metricbeat} indices.
  255. <2> Automatically follow new {packetbeat} indices.
  256. <3> The name of the follower index is derived from the name of the leader index
  257. by adding the suffix `-copy` to the name of the leader index.
  258. //////////////////////////
  259. [source,console-result]
  260. --------------------------------------------------
  261. {
  262. "acknowledged" : true
  263. }
  264. --------------------------------------------------
  265. //////////////////////////
  266. //////////////////////////
  267. [source,console]
  268. --------------------------------------------------
  269. DELETE /_ccr/auto_follow/beats
  270. --------------------------------------------------
  271. // TEST[continued]
  272. //////////////////////////
  273. ====