getting-started.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[ccr-getting-started]]
  4. === Getting started with {ccr}
  5. This getting-started guide for {ccr} shows you how to:
  6. * <<ccr-getting-started-remote-cluster,Connect a local cluster to a remote
  7. cluster>>
  8. * <<ccr-getting-started-leader-index,Create a leader index>> in a remote cluster
  9. * <<ccr-getting-started-follower-index,Create a follower index>> that replicates
  10. a leader index
  11. * <<ccr-getting-started-auto-follow,Automatically create follower indices>>
  12. [[ccr-getting-started-before-you-begin]]
  13. ==== Before you begin
  14. . {stack-gs}/get-started-elastic-stack.html#install-elasticsearch[Install {es}]
  15. on your local and remote clusters.
  16. . Obtain a license that includes the {ccr} features. See
  17. https://www.elastic.co/subscriptions[subscriptions] and
  18. {kibana-ref}/managing-licenses.html[License management].
  19. . If the Elastic {security-features} are enabled in your local and remote
  20. clusters, you need a user that has appropriate authority to perform the steps
  21. in this tutorial.
  22. +
  23. --
  24. [[ccr-getting-started-security]]
  25. The {ccr} features use cluster privileges and built-in roles to make it easier
  26. to control which users have authority to manage {ccr}.
  27. By default, you can perform all of the steps in this tutorial by
  28. using the built-in `elastic` user. However, a password must be set for this user
  29. before the user can do anything. For information about how to set that password,
  30. see <<security-getting-started>>.
  31. If you are performing these steps in a production environment, take extra care
  32. because the `elastic` user has the `superuser` role and you could inadvertently
  33. make significant changes.
  34. Alternatively, you can assign the appropriate privileges to a user ID of your
  35. choice. On the remote cluster that contains the leader index, a user will need
  36. the `read_ccr` cluster privilege and `monitor` and `read` privileges on the
  37. leader index.
  38. [source,yml]
  39. --------------------------------------------------
  40. ccr_user:
  41. cluster:
  42. - read_ccr
  43. indices:
  44. - names: [ 'leader-index' ]
  45. privileges:
  46. - monitor
  47. - read
  48. --------------------------------------------------
  49. On the local cluster that contains the follower index, the same user will need
  50. the `manage_ccr` cluster privilege and `monitor`, `read`, `write` and
  51. `manage_follow_index` privileges on the follower index.
  52. [source,yml]
  53. --------------------------------------------------
  54. ccr_user:
  55. cluster:
  56. - manage_ccr
  57. indices:
  58. - names: [ 'follower-index' ]
  59. privileges:
  60. - monitor
  61. - read
  62. - write
  63. - manage_follow_index
  64. --------------------------------------------------
  65. If you are managing
  66. <<ccr-getting-started-remote-cluster,connecting to the remote cluster>> via the
  67. cluster update settings API, you will also need a user with the `all` cluster
  68. privilege.
  69. --
  70. [[ccr-getting-started-remote-cluster]]
  71. ==== Connecting to a remote cluster
  72. The {ccr} features require that you
  73. {ref}/modules-remote-clusters.html[connect your local cluster to a remote
  74. cluster]. In this tutorial, we will connect our local cluster to a remote
  75. cluster with the cluster alias `leader`.
  76. [source,console]
  77. --------------------------------------------------
  78. PUT /_cluster/settings
  79. {
  80. "persistent" : {
  81. "cluster" : {
  82. "remote" : {
  83. "leader" : {
  84. "seeds" : [
  85. "127.0.0.1:9300" <1>
  86. ]
  87. }
  88. }
  89. }
  90. }
  91. }
  92. --------------------------------------------------
  93. // TEST[setup:host]
  94. // TEST[s/127.0.0.1:9300/\${transport_host}/]
  95. <1> Specifies the hostname and transport port of a seed node in the remote
  96. cluster.
  97. You can verify that the local cluster is successfully connected to the remote
  98. cluster.
  99. [source,console]
  100. --------------------------------------------------
  101. GET /_remote/info
  102. --------------------------------------------------
  103. // TEST[continued]
  104. The API will respond by showing that the local cluster is connected to the
  105. remote cluster.
  106. [source,console-result]
  107. --------------------------------------------------
  108. {
  109. "leader" : {
  110. "seeds" : [
  111. "127.0.0.1:9300"
  112. ],
  113. "connected" : true, <1>
  114. "num_nodes_connected" : 1, <2>
  115. "max_connections_per_cluster" : 3,
  116. "initial_connect_timeout" : "30s",
  117. "skip_unavailable" : false,
  118. "mode" : "sniff"
  119. }
  120. }
  121. --------------------------------------------------
  122. // TESTRESPONSE[s/127.0.0.1:9300/$body.leader.seeds.0/]
  123. // TEST[s/"connected" : true/"connected" : $body.leader.connected/]
  124. // TEST[s/"num_nodes_connected" : 1/"num_nodes_connected" : $body.leader.num_nodes_connected/]
  125. <1> This shows the local cluster is connected to the remote cluster with cluster
  126. alias `leader`
  127. <2> This shows the number of nodes in the remote cluster the local cluster is
  128. connected to.
  129. Alternatively, you can {kibana-ref}/working-remote-clusters.html[manage remote clusters] from {kib}:
  130. . From the {kib} menu, select *Management -> Stack Management*.
  131. . Under *Data*, select *Remote Clusters* to access the Remote Clusters
  132. page.
  133. [role="screenshot"]
  134. image::images/remote-clusters.png["The Remote Clusters page in {kib}"]
  135. [[ccr-getting-started-leader-index]]
  136. ==== Creating a leader index
  137. In the following example, we will create a leader index in the remote cluster:
  138. [source,console]
  139. --------------------------------------------------
  140. PUT /server-metrics
  141. {
  142. "settings" : {
  143. "index" : {
  144. "number_of_shards" : 1,
  145. "number_of_replicas" : 0
  146. }
  147. },
  148. "mappings" : {
  149. "properties" : {
  150. "@timestamp" : {
  151. "type" : "date"
  152. },
  153. "accept" : {
  154. "type" : "long"
  155. },
  156. "deny" : {
  157. "type" : "long"
  158. },
  159. "host" : {
  160. "type" : "keyword"
  161. },
  162. "response" : {
  163. "type" : "float"
  164. },
  165. "service" : {
  166. "type" : "keyword"
  167. },
  168. "total" : {
  169. "type" : "long"
  170. }
  171. }
  172. }
  173. }
  174. --------------------------------------------------
  175. // TEST[continued]
  176. [[ccr-getting-started-follower-index]]
  177. ==== Creating a follower index
  178. Follower indices are created with the {ref}/ccr-put-follow.html[create follower
  179. API]. When you create a follower index, you must reference the
  180. <<ccr-getting-started-remote-cluster,remote cluster>> and the
  181. <<ccr-getting-started-leader-index,leader index>> that you created in the remote
  182. cluster.
  183. [source,console]
  184. --------------------------------------------------
  185. PUT /server-metrics-copy/_ccr/follow?wait_for_active_shards=1
  186. {
  187. "remote_cluster" : "leader",
  188. "leader_index" : "server-metrics"
  189. }
  190. --------------------------------------------------
  191. // TEST[continued]
  192. //////////////////////////
  193. [source,console-result]
  194. --------------------------------------------------
  195. {
  196. "follow_index_created" : true,
  197. "follow_index_shards_acked" : true,
  198. "index_following_started" : true
  199. }
  200. --------------------------------------------------
  201. //////////////////////////
  202. The follower index is initialized using the <<remote-recovery, remote recovery>>
  203. process. The remote recovery process transfers the existing Lucene segment files
  204. from the leader to the follower. When the remote recovery process is complete,
  205. the index following begins.
  206. Now when you index documents into your leader index, you will see these
  207. documents replicated in the follower index. You can
  208. inspect the status of replication using the
  209. {ref}/ccr-get-follow-stats.html[get follower stats API].
  210. Alternatively, you can {kibana-ref}/managing-cross-cluster-replication.html#_create_specific_follower_indices[manage follower indices] using {kib}:
  211. . From the {kib} menu, click *Management -> Stack Management*.
  212. . Under *Data*, select *Cross Cluster Replication*.
  213. . Choose the *Follower indices* tab.
  214. [role="screenshot"]
  215. image::images/ccr-follower-index.png["The Cross-Cluster Replication page in {kib}"]
  216. //////////////////////////
  217. [source,console]
  218. --------------------------------------------------
  219. POST /server-metrics-copy/_ccr/pause_follow
  220. POST /server-metrics-copy/_close
  221. POST /server-metrics-copy/_ccr/unfollow
  222. --------------------------------------------------
  223. // TEST[continued]
  224. //////////////////////////
  225. [[ccr-getting-started-auto-follow]]
  226. ==== Automatically create follower indices
  227. The <<ccr-auto-follow,auto-follow>> feature in {ccr} helps for time series use
  228. cases where you want to follow new indices that are periodically created in the
  229. remote cluster (such as daily Beats indices). Auto-following is configured using
  230. the {ref}/ccr-put-auto-follow-pattern.html[create auto-follow pattern API]. With
  231. an auto-follow pattern, you reference the
  232. <<ccr-getting-started-remote-cluster,remote cluster>> that you connected your
  233. local cluster to. You must also specify a collection of patterns that match the
  234. indices you want to automatically follow.
  235. For example:
  236. [source,console]
  237. --------------------------------------------------
  238. PUT /_ccr/auto_follow/beats
  239. {
  240. "remote_cluster" : "leader",
  241. "leader_index_patterns" :
  242. [
  243. "metricbeat-*", <1>
  244. "packetbeat-*" <2>
  245. ],
  246. "follow_index_pattern" : "{{leader_index}}-copy" <3>
  247. }
  248. --------------------------------------------------
  249. // TEST[continued]
  250. <1> Automatically follow new {metricbeat} indices.
  251. <2> Automatically follow new {packetbeat} indices.
  252. <3> The name of the follower index is derived from the name of the leader index
  253. by adding the suffix `-copy` to the name of the leader index.
  254. //////////////////////////
  255. [source,console-result]
  256. --------------------------------------------------
  257. {
  258. "acknowledged" : true
  259. }
  260. --------------------------------------------------
  261. //////////////////////////
  262. //////////////////////////
  263. [source,console]
  264. --------------------------------------------------
  265. DELETE /_ccr/auto_follow/beats
  266. --------------------------------------------------
  267. // TEST[continued]
  268. //////////////////////////
  269. Alternatively, you can manage auto-follow patterns from {kib}:
  270. . From the {kib} menu, click *Management -> Stack Management*.
  271. . Under *Data*, select *Cross Cluster Replication*.
  272. . Choose the *Auto-follow patterns* tab.
  273. [role="screenshot"]
  274. image::images/auto-follow-patterns.png["The Auto-follow patterns page in {kib}"]
  275. See {kibana-ref}/managing-cross-cluster-replication.html#_create_follower_indices_from_an_auto_follow_pattern[Create follower indices from an auto-follow pattern] for more information.