getting-started.asciidoc 9.3 KB

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