getting-started.asciidoc 9.2 KB

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