getting-started.asciidoc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[ccr-getting-started]]
  4. === Set up {ccr}
  5. You can manually create follower indices to replicate specific indices on a
  6. remote cluster, or configure auto-follow patterns to automatically create
  7. follower indices for new time series.
  8. After the follower index is created, the
  9. <<ccr-remote-recovery, remote recovery>> process copies all of the Lucene
  10. segment files from the remote cluster to the local cluster.
  11. To set up {ccr}:
  12. . <<ccr-getting-started-remote-cluster,Connect a local cluster to a remote cluster>>
  13. . <<ccr-getting-started-leader-index,Identify the index (or time series indices) you want to replicate on the remote cluster>>
  14. . <<ccr-enable-soft-deletes,Enable soft deletes on the leader index>>
  15. . Manually create a follower index or create an auto-follow pattern:
  16. * To replicate the leader index, <<ccr-getting-started-follower-index,manually create a follower index>>
  17. * To automatically follow time series indices, <<ccr-getting-started-auto-follow,create an auto-follow pattern>>
  18. [[ccr-getting-started-prerequisites]]
  19. ==== Prerequisites
  20. If the Elastic {security-features} are enabled in your local and remote
  21. clusters, you need a user with appropriate authority to complete the steps
  22. in this tutorial.
  23. By default, you can complete the following steps as the built-in
  24. `elastic` user. However, you must <<get-started-built-in-users,set a password>>
  25. for this user before proceeding.
  26. WARNING: If you are performing these steps in a production environment, do
  27. not use the `elastic` user.
  28. Alternatively, you can assign the appropriate privileges to a user ID of your
  29. choice. On the remote cluster that contains the leader index, a user must have
  30. the `read_ccr` cluster privilege and `monitor` and `read` privileges on the
  31. leader index.
  32. [source,yml]
  33. --------------------------------------------------
  34. ccr_user:
  35. cluster:
  36. - read_ccr
  37. indices:
  38. - names: [ 'leader-index' ]
  39. privileges:
  40. - monitor
  41. - read
  42. --------------------------------------------------
  43. On the local cluster that contains the follower index, the same user will need
  44. the `manage_ccr` cluster privilege and `monitor`, `read`, `write` and
  45. `manage_follow_index` privileges on the follower index.
  46. [source,yml]
  47. --------------------------------------------------
  48. ccr_user:
  49. cluster:
  50. - manage_ccr
  51. indices:
  52. - names: [ 'follower-index' ]
  53. privileges:
  54. - monitor
  55. - read
  56. - write
  57. - manage_follow_index
  58. --------------------------------------------------
  59. If you are managing
  60. <<ccr-getting-started-remote-cluster,connecting to the remote cluster>> using
  61. the cluster update settings API, you will also need a user with the `all`
  62. cluster privilege.
  63. [[ccr-getting-started-remote-cluster]]
  64. ==== Connect to a remote cluster
  65. Connect your local cluster to a
  66. <<modules-remote-clusters,remote cluster>> to begin using cross-cluster
  67. replication.
  68. To configure a {kibana-ref}/working-remote-clusters.html[remote cluster],
  69. access {kib} and go to
  70. *Management > Stack Management*. In the side navigation, select
  71. *Remote Clusters*.
  72. Add a remote cluster by specifying the IP address or host name, followed by the
  73. transport port of the remote cluster.
  74. [role="screenshot"]
  75. image::images/ccr-add-remote-cluster.png["The Add remote clusters page in {kib}"]
  76. [%collapsible]
  77. .API example
  78. ====
  79. Use the <<cluster-update-settings,cluster update settings API>> to add a remote cluster:
  80. [source,console]
  81. --------------------------------------------------
  82. PUT /_cluster/settings
  83. {
  84. "persistent" : {
  85. "cluster" : {
  86. "remote" : {
  87. "leader" : {
  88. "seeds" : [
  89. "127.0.0.1:9300" <1>
  90. ]
  91. }
  92. }
  93. }
  94. }
  95. }
  96. --------------------------------------------------
  97. // TEST[setup:host]
  98. // TEST[s/127.0.0.1:9300/\${transport_host}/]
  99. <1> Specifies the hostname and transport port of a seed node in the remote
  100. cluster.
  101. You can verify that the local cluster is successfully connected to the remote
  102. cluster.
  103. [source,console]
  104. --------------------------------------------------
  105. GET /_remote/info
  106. --------------------------------------------------
  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. "mode" : "sniff"
  123. }
  124. }
  125. --------------------------------------------------
  126. // TESTRESPONSE[s/127.0.0.1:9300/$body.leader.seeds.0/]
  127. // TEST[s/"connected" : true/"connected" : $body.leader.connected/]
  128. // TEST[s/"num_nodes_connected" : 1/"num_nodes_connected" : $body.leader.num_nodes_connected/]
  129. <1> This shows the local cluster is connected to the remote cluster with cluster
  130. alias `leader`
  131. <2> This shows the number of nodes in the remote cluster the local cluster is
  132. connected to.
  133. ====
  134. [[ccr-getting-started-leader-index]]
  135. ==== Create a leader index
  136. To create a leader index, access {kib} on your _remote_ cluster and go to
  137. *Management > Dev Tools*.
  138. Copy the following example into the Console to create a leader index named
  139. `server-metrics` in your remote cluster:
  140. [%collapsible]
  141. .Leader index example
  142. ====
  143. [source,console]
  144. --------------------------------------------------
  145. PUT /server-metrics
  146. {
  147. "settings" : {
  148. "index" : {
  149. "number_of_shards" : 1,
  150. "number_of_replicas" : 0
  151. }
  152. },
  153. "mappings" : {
  154. "properties" : {
  155. "@timestamp" : {
  156. "type" : "date"
  157. },
  158. "accept" : {
  159. "type" : "long"
  160. },
  161. "deny" : {
  162. "type" : "long"
  163. },
  164. "host" : {
  165. "type" : "keyword"
  166. },
  167. "response" : {
  168. "type" : "float"
  169. },
  170. "service" : {
  171. "type" : "keyword"
  172. },
  173. "total" : {
  174. "type" : "long"
  175. }
  176. }
  177. }
  178. }
  179. --------------------------------------------------
  180. // TEST[continued]
  181. ====
  182. [[ccr-enable-soft-deletes]]
  183. ==== Enable soft deletes on leader indices
  184. <<ccr-leader-requirements,Soft deletes>> must be enabled for indices that you want to
  185. use as leader indices. Soft deletes are enabled by default on new indices
  186. created on or after {es} 7.0.0, so
  187. *no further action is required if your cluster is running {es} 7.0.0 or later*.
  188. include::{es-ref-dir}/ccr/index.asciidoc[tag=ccr-existing-indices-tag]
  189. To enable soft deletes on indices created on versions of
  190. {es} between 6.5.0 and 7.0.0, set <<ccr-index-soft-deletes,`index.soft_deletes.enabled`>> to `true`.
  191. [[ccr-getting-started-follower-index]]
  192. ==== Create a follower index
  193. When you create a {kibana-ref}/managing-cross-cluster-replication.html#_create_specific_follower_indices[follower index], you
  194. must reference the
  195. <<ccr-getting-started-remote-cluster,remote cluster>> and the
  196. <<ccr-getting-started-leader-index,leader index>> that you created in the remote
  197. cluster.
  198. To create a follower index, access {kib} and go to
  199. *Management > Stack Management*. In the side navigation, select
  200. *Cross-Cluster Replication* and choose the *Follower Indices* tab.
  201. . Choose the remote cluster containing the index you want to replicate, which
  202. is `leader` if you are following the tutorial.
  203. . Enter the name of the leader index, which is `server-metrics` if you are
  204. following the tutorial.
  205. image::images/ccr-add-follower-index.png["Adding a follower index named server-metrics in {kib}"]
  206. The follower index is initialized using the
  207. <<ccr-remote-recovery, remote recovery>>
  208. process, which transfers the existing Lucene segment files from the leader
  209. index to the follower index. The index status changes to *Paused*. When the
  210. remote recovery process is complete, the index following begins and the status
  211. changes to *Active*.
  212. When you index documents into your leader index, the documents are replicated
  213. in the follower index.
  214. [role="screenshot"]
  215. image::images/ccr-follower-index.png["The Cross-Cluster Replication page in {kib}"]
  216. [%collapsible]
  217. .API example
  218. ====
  219. Use the <<ccr-put-follow,create follower API>> to create follower indices.
  220. When you create a follower index, you must reference the
  221. <<ccr-getting-started-remote-cluster,remote cluster>> and the
  222. <<ccr-getting-started-leader-index,leader index>> that you created in the
  223. remote cluster.
  224. When initiating the follower request, the response returns before the
  225. <<ccr-remote-recovery, remote recovery>> process completes. To wait for the process
  226. to complete, add the `wait_for_active_shards` parameter to your request.
  227. [source,console]
  228. --------------------------------------------------
  229. PUT /server-metrics-follower/_ccr/follow?wait_for_active_shards=1
  230. {
  231. "remote_cluster" : "leader",
  232. "leader_index" : "server-metrics"
  233. }
  234. --------------------------------------------------
  235. // TEST[continued]
  236. //////////////////////////
  237. [source,console-result]
  238. --------------------------------------------------
  239. {
  240. "follow_index_created" : true,
  241. "follow_index_shards_acked" : true,
  242. "index_following_started" : true
  243. }
  244. --------------------------------------------------
  245. //////////////////////////
  246. Use the
  247. <<ccr-get-follow-stats,get follower stats API>> to inspect the status of
  248. replication
  249. //////////////////////////
  250. [source,console]
  251. --------------------------------------------------
  252. POST /server-metrics-follower/_ccr/pause_follow
  253. POST /server-metrics-follower/_close
  254. POST /server-metrics-follower/_ccr/unfollow
  255. --------------------------------------------------
  256. // TEST[continued]
  257. //////////////////////////
  258. ====
  259. [[ccr-getting-started-auto-follow]]
  260. ==== Automatically create follower indices
  261. Create <<ccr-auto-follow,auto-follow patterns>> to automatically follow time
  262. series indices that are periodically created in a remote cluster (such as daily
  263. {beats} indices).
  264. With an auto-follow pattern, you reference the
  265. <<ccr-getting-started-remote-cluster,remote cluster>> connected to your
  266. local cluster. You must also specify a collection of patterns that match the
  267. indices you want to automatically follow.
  268. // tag::ccr-create-auto-follow-pattern-tag[]
  269. To create follower indices from an {kibana-ref}/managing-cross-cluster-replication.html#_create_follower_indices_from_an_auto_follow_pattern[auto-follow pattern],
  270. access {kib} on your remote cluster and go to
  271. *Management > Stack Management*. In the side navigation, select
  272. *Cross Cluster Replication* and choose the *Auto-follow patterns* tab.
  273. [role="screenshot"]
  274. image::images/auto-follow-patterns.png["The Auto-follow patterns page in {kib}"]
  275. * Enter a name for the auto-follow pattern. For this tutorial, enter `beats`
  276. as the name.
  277. * Choose the remote cluster containing the index you want to replicate, which
  278. is `leader` if you are following the tutorial.
  279. * Enter one or more index patterns that identify the indices you want to
  280. replicate from the remote cluster. For this tutorial, enter
  281. `metricbeat-*,packetbeat-*` as the index pattern.
  282. * Enter *copy-* as the prefix to apply to the names of the follower indices so
  283. you can more easily identify replicated indices.
  284. As new indices matching these patterns are
  285. created, they are replicated to the follower indices.
  286. // end::ccr-create-auto-follow-pattern-tag[]
  287. [%collapsible]
  288. .API example
  289. ====
  290. Use the <<ccr-put-auto-follow-pattern,create auto-follow pattern API>> to
  291. configure auto-follow patterns.
  292. [source,console]
  293. --------------------------------------------------
  294. PUT /_ccr/auto_follow/beats
  295. {
  296. "remote_cluster" : "leader",
  297. "leader_index_patterns" :
  298. [
  299. "metricbeat-*", <1>
  300. "packetbeat-*" <2>
  301. ],
  302. "follow_index_pattern" : "{{leader_index}}-copy" <3>
  303. }
  304. --------------------------------------------------
  305. // TEST[continued]
  306. <1> Automatically follow new {metricbeat} indices.
  307. <2> Automatically follow new {packetbeat} indices.
  308. <3> The name of the follower index is derived from the name of the leader index
  309. by adding the suffix `-copy` to the name of the leader index.
  310. //////////////////////////
  311. [source,console-result]
  312. --------------------------------------------------
  313. {
  314. "acknowledged" : true
  315. }
  316. --------------------------------------------------
  317. //////////////////////////
  318. //////////////////////////
  319. [source,console]
  320. --------------------------------------------------
  321. DELETE /_ccr/auto_follow/beats
  322. --------------------------------------------------
  323. // TEST[continued]
  324. //////////////////////////
  325. ====