getting-started.asciidoc 9.7 KB

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