getting-started.asciidoc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. [float]
  135. [[ccr-getting-started-leader-index]]
  136. === Creating a leader index
  137. Leader indices require special index settings to ensure that the operations that
  138. need to be replicated are available when the
  139. follower requests them from the leader. These settings are used to enable soft
  140. deletes on the leader index and to control how many soft deletes are retained. A
  141. _soft delete_ occurs whenever a document is deleted or updated. Soft deletes can
  142. be enabled only on new indices created on or after {es} 6.5.0.
  143. In the following example, we will create a leader index in the remote cluster:
  144. [source,js]
  145. --------------------------------------------------
  146. PUT /server-metrics
  147. {
  148. "settings" : {
  149. "index" : {
  150. "number_of_shards" : 1,
  151. "number_of_replicas" : 0,
  152. "soft_deletes" : {
  153. "enabled" : true, <1>
  154. "retention" : {
  155. "operations" : 1024 <2>
  156. }
  157. }
  158. }
  159. },
  160. "mappings" : {
  161. "metric" : {
  162. "properties" : {
  163. "@timestamp" : {
  164. "type" : "date"
  165. },
  166. "accept" : {
  167. "type" : "long"
  168. },
  169. "deny" : {
  170. "type" : "long"
  171. },
  172. "host" : {
  173. "type" : "keyword"
  174. },
  175. "response" : {
  176. "type" : "float"
  177. },
  178. "service" : {
  179. "type" : "keyword"
  180. },
  181. "total" : {
  182. "type" : "long"
  183. }
  184. }
  185. }
  186. }
  187. }
  188. --------------------------------------------------
  189. // CONSOLE
  190. // TEST[continued]
  191. <1> Enables soft deletes on the leader index.
  192. <2> Sets that up to 1024 soft deletes will be retained.
  193. [float]
  194. [[ccr-getting-started-follower-index]]
  195. === Creating a follower index
  196. Follower indices are created with the {ref}/ccr-put-follow.html[create follower
  197. API]. When you create a follower index, you must reference the
  198. <<ccr-getting-started-remote-cluster,remote cluster>> and the
  199. <<ccr-getting-started-leader-index,leader index>> that you created in the remote
  200. cluster.
  201. [source,js]
  202. --------------------------------------------------
  203. PUT /server-metrics-copy/_ccr/follow
  204. {
  205. "remote_cluster" : "leader",
  206. "leader_index" : "server-metrics"
  207. }
  208. --------------------------------------------------
  209. // CONSOLE
  210. // TEST[continued]
  211. //////////////////////////
  212. [source,js]
  213. --------------------------------------------------
  214. {
  215. "follow_index_created" : true,
  216. "follow_index_shards_acked" : true,
  217. "index_following_started" : true
  218. }
  219. --------------------------------------------------
  220. // TESTRESPONSE
  221. //////////////////////////
  222. Now when you index documents into your leader index, you will see these
  223. documents replicated in the follower index. You can
  224. inspect the status of replication using the
  225. {ref}/ccr-get-follow-stats.html[get follower stats API].
  226. //////////////////////////
  227. [source,js]
  228. --------------------------------------------------
  229. POST /server-metrics-copy/_ccr/pause_follow
  230. POST /server-metrics-copy/_close
  231. POST /server-metrics-copy/_ccr/unfollow
  232. --------------------------------------------------
  233. // CONSOLE
  234. // TEST[continued]
  235. //////////////////////////
  236. [float]
  237. [[ccr-getting-started-auto-follow]]
  238. === Automatically create follower indices
  239. The <<ccr-auto-follow,auto-follow>> feature in {ccr} helps for time series use
  240. cases where you want to follow new indices that are periodically created in the
  241. remote cluster (such as daily Beats indices). Auto-following is configured using
  242. the {ref}/ccr-put-auto-follow-pattern.html[create auto-follow pattern API]. With
  243. an auto-follow pattern, you reference the
  244. <<ccr-getting-started-remote-cluster,remote cluster>> that you connected your
  245. local cluster to. You must also specify a collection of patterns that match the
  246. indices you want to automatically follow.
  247. For example:
  248. [source,js]
  249. --------------------------------------------------
  250. PUT /_ccr/auto_follow/beats
  251. {
  252. "remote_cluster" : "leader",
  253. "leader_index_patterns" :
  254. [
  255. "metricbeat-*", <1>
  256. "packetbeat-*" <2>
  257. ],
  258. "follow_index_pattern" : "{{leader_index}}-copy" <3>
  259. }
  260. --------------------------------------------------
  261. // CONSOLE
  262. // TEST[continued]
  263. <1> Automatically follow new {metricbeat} indices.
  264. <2> Automatically follow new {packetbeat} indices.
  265. <3> The name of the follower index is derived from the name of the leader index
  266. by adding the suffix `-copy` to the name of the leader index.
  267. //////////////////////////
  268. [source,js]
  269. --------------------------------------------------
  270. {
  271. "acknowledged" : true
  272. }
  273. --------------------------------------------------
  274. // TESTRESPONSE
  275. //////////////////////////
  276. //////////////////////////
  277. [source,js]
  278. --------------------------------------------------
  279. DELETE /_ccr/auto_follow/beats
  280. --------------------------------------------------
  281. // CONSOLE
  282. // TEST[continued]
  283. //////////////////////////