getting-started.asciidoc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. {stack-ov}/license-management.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 manage remote clusters on the
  130. *Management / Elasticsearch / Remote Clusters* page in {kib}:
  131. [role="screenshot"]
  132. image::images/remote-clusters.jpg["The Remote Clusters page in {kib}"]
  133. [[ccr-getting-started-leader-index]]
  134. ==== Creating a leader index
  135. In the following example, we will create a leader index in the remote cluster:
  136. [source,console]
  137. --------------------------------------------------
  138. PUT /server-metrics
  139. {
  140. "settings" : {
  141. "index" : {
  142. "number_of_shards" : 1,
  143. "number_of_replicas" : 0
  144. }
  145. },
  146. "mappings" : {
  147. "properties" : {
  148. "@timestamp" : {
  149. "type" : "date"
  150. },
  151. "accept" : {
  152. "type" : "long"
  153. },
  154. "deny" : {
  155. "type" : "long"
  156. },
  157. "host" : {
  158. "type" : "keyword"
  159. },
  160. "response" : {
  161. "type" : "float"
  162. },
  163. "service" : {
  164. "type" : "keyword"
  165. },
  166. "total" : {
  167. "type" : "long"
  168. }
  169. }
  170. }
  171. }
  172. --------------------------------------------------
  173. // TEST[continued]
  174. [[ccr-getting-started-follower-index]]
  175. ==== Creating a follower index
  176. Follower indices are created with the {ref}/ccr-put-follow.html[create follower
  177. API]. When you create a follower index, you must reference the
  178. <<ccr-getting-started-remote-cluster,remote cluster>> and the
  179. <<ccr-getting-started-leader-index,leader index>> that you created in the remote
  180. cluster.
  181. [source,console]
  182. --------------------------------------------------
  183. PUT /server-metrics-copy/_ccr/follow?wait_for_active_shards=1
  184. {
  185. "remote_cluster" : "leader",
  186. "leader_index" : "server-metrics"
  187. }
  188. --------------------------------------------------
  189. // TEST[continued]
  190. //////////////////////////
  191. [source,console-result]
  192. --------------------------------------------------
  193. {
  194. "follow_index_created" : true,
  195. "follow_index_shards_acked" : true,
  196. "index_following_started" : true
  197. }
  198. --------------------------------------------------
  199. //////////////////////////
  200. The follower index is initialized using the <<remote-recovery, remote recovery>>
  201. process. The remote recovery process transfers the existing Lucene segment files
  202. from the leader to the follower. When the remote recovery process is complete,
  203. the index following begins.
  204. Now when you index documents into your leader index, you will see these
  205. documents replicated in the follower index. You can
  206. inspect the status of replication using the
  207. {ref}/ccr-get-follow-stats.html[get follower stats API].
  208. //////////////////////////
  209. [source,console]
  210. --------------------------------------------------
  211. POST /server-metrics-copy/_ccr/pause_follow
  212. POST /server-metrics-copy/_close
  213. POST /server-metrics-copy/_ccr/unfollow
  214. --------------------------------------------------
  215. // TEST[continued]
  216. //////////////////////////
  217. [[ccr-getting-started-auto-follow]]
  218. ==== Automatically create follower indices
  219. The <<ccr-auto-follow,auto-follow>> feature in {ccr} helps for time series use
  220. cases where you want to follow new indices that are periodically created in the
  221. remote cluster (such as daily Beats indices). Auto-following is configured using
  222. the {ref}/ccr-put-auto-follow-pattern.html[create auto-follow pattern API]. With
  223. an auto-follow pattern, you reference the
  224. <<ccr-getting-started-remote-cluster,remote cluster>> that you connected your
  225. local cluster to. You must also specify a collection of patterns that match the
  226. indices you want to automatically follow.
  227. For example:
  228. [source,console]
  229. --------------------------------------------------
  230. PUT /_ccr/auto_follow/beats
  231. {
  232. "remote_cluster" : "leader",
  233. "leader_index_patterns" :
  234. [
  235. "metricbeat-*", <1>
  236. "packetbeat-*" <2>
  237. ],
  238. "follow_index_pattern" : "{{leader_index}}-copy" <3>
  239. }
  240. --------------------------------------------------
  241. // TEST[continued]
  242. <1> Automatically follow new {metricbeat} indices.
  243. <2> Automatically follow new {packetbeat} indices.
  244. <3> The name of the follower index is derived from the name of the leader index
  245. by adding the suffix `-copy` to the name of the leader index.
  246. //////////////////////////
  247. [source,console-result]
  248. --------------------------------------------------
  249. {
  250. "acknowledged" : true
  251. }
  252. --------------------------------------------------
  253. //////////////////////////
  254. //////////////////////////
  255. [source,console]
  256. --------------------------------------------------
  257. DELETE /_ccr/auto_follow/beats
  258. --------------------------------------------------
  259. // TEST[continued]
  260. //////////////////////////
  261. Alternatively, you can manage auto-follow patterns on the
  262. *Management / Elasticsearch / Cross Cluster Replication* page in {kib}:
  263. [role="screenshot"]
  264. image::images/auto-follow-patterns.jpg["The Auto-follow patterns page in {kib}"]