discovery-azure-classic.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. [[discovery-azure-classic]]
  2. === Azure Classic Discovery Plugin
  3. The Azure Classic Discovery plugin uses the Azure Classic API to identify the
  4. addresses of seed hosts.
  5. deprecated[5.0.0, This plugin will be removed in the future]
  6. :plugin_name: discovery-azure-classic
  7. include::install_remove.asciidoc[]
  8. [[discovery-azure-classic-usage]]
  9. ==== Azure Virtual Machine Discovery
  10. Azure VM discovery allows to use the Azure APIs to perform automatic discovery.
  11. Here is a simple sample configuration:
  12. [source,yaml]
  13. ----
  14. cloud:
  15. azure:
  16. management:
  17. subscription.id: XXX-XXX-XXX-XXX
  18. cloud.service.name: es-demo-app
  19. keystore:
  20. path: /path/to/azurekeystore.pkcs12
  21. password: WHATEVER
  22. type: pkcs12
  23. discovery:
  24. seed_providers: azure
  25. ----
  26. [IMPORTANT]
  27. .Binding the network host
  28. ==============================================
  29. The keystore file must be placed in a directory accessible by Elasticsearch like the `config` directory.
  30. It's important to define `network.host` as by default it's bound to `localhost`.
  31. You can use {ref}/modules-network.html[core network host settings]. For example `_en0_`.
  32. ==============================================
  33. [[discovery-azure-classic-short]]
  34. ===== How to start (short story)
  35. * Create Azure instances
  36. * Install Elasticsearch
  37. * Install Azure plugin
  38. * Modify `elasticsearch.yml` file
  39. * Start Elasticsearch
  40. [[discovery-azure-classic-settings]]
  41. ===== Azure credential API settings
  42. The following are a list of settings that can further control the credential API:
  43. [horizontal]
  44. `cloud.azure.management.keystore.path`::
  45. /path/to/keystore
  46. `cloud.azure.management.keystore.type`::
  47. `pkcs12`, `jceks` or `jks`. Defaults to `pkcs12`.
  48. `cloud.azure.management.keystore.password`::
  49. your_password for the keystore
  50. `cloud.azure.management.subscription.id`::
  51. your_azure_subscription_id
  52. `cloud.azure.management.cloud.service.name`::
  53. your_azure_cloud_service_name. This is the cloud service name/DNS but without the `cloudapp.net` part.
  54. So if the DNS name is `abc.cloudapp.net` then the `cloud.service.name` to use is just `abc`.
  55. [[discovery-azure-classic-settings-advanced]]
  56. ===== Advanced settings
  57. The following are a list of settings that can further control the discovery:
  58. `discovery.azure.host.type`::
  59. Either `public_ip` or `private_ip` (default). Azure discovery will use the
  60. one you set to ping other nodes.
  61. `discovery.azure.endpoint.name`::
  62. When using `public_ip` this setting is used to identify the endpoint name
  63. used to forward requests to Elasticsearch (aka transport port name).
  64. Defaults to `elasticsearch`. In Azure management console, you could define
  65. an endpoint `elasticsearch` forwarding for example requests on public IP
  66. on port 8100 to the virtual machine on port 9300.
  67. `discovery.azure.deployment.name`::
  68. Deployment name if any. Defaults to the value set with
  69. `cloud.azure.management.cloud.service.name`.
  70. `discovery.azure.deployment.slot`::
  71. Either `staging` or `production` (default).
  72. For example:
  73. [source,yaml]
  74. ----
  75. discovery:
  76. type: azure
  77. azure:
  78. host:
  79. type: private_ip
  80. endpoint:
  81. name: elasticsearch
  82. deployment:
  83. name: your_azure_cloud_service_name
  84. slot: production
  85. ----
  86. [[discovery-azure-classic-long]]
  87. ==== Setup process for Azure Discovery
  88. We will expose here one strategy which is to hide our Elasticsearch cluster from outside.
  89. With this strategy, only VMs behind the same virtual port can talk to each
  90. other. That means that with this mode, you can use Elasticsearch unicast
  91. discovery to build a cluster, using the Azure API to retrieve information
  92. about your nodes.
  93. [[discovery-azure-classic-long-prerequisites]]
  94. ===== Prerequisites
  95. Before starting, you need to have:
  96. * A https://azure.microsoft.com/en-us/[Windows Azure account]
  97. * OpenSSL that isn't from MacPorts, specifically `OpenSSL 1.0.1f 6 Jan
  98. 2014` doesn't seem to create a valid keypair for ssh. FWIW,
  99. `OpenSSL 1.0.1c 10 May 2012` on Ubuntu 14.04 LTS is known to work.
  100. * SSH keys and certificate
  101. +
  102. --
  103. You should follow http://azure.microsoft.com/en-us/documentation/articles/linux-use-ssh-key/[this guide] to learn
  104. how to create or use existing SSH keys. If you have already did it, you can skip the following.
  105. Here is a description on how to generate SSH keys using `openssl`:
  106. [source,sh]
  107. ----
  108. # You may want to use another dir than /tmp
  109. cd /tmp
  110. openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout azure-private.key -out azure-certificate.pem
  111. chmod 600 azure-private.key azure-certificate.pem
  112. openssl x509 -outform der -in azure-certificate.pem -out azure-certificate.cer
  113. ----
  114. Generate a keystore which will be used by the plugin to authenticate with a certificate
  115. all Azure API calls.
  116. [source,sh]
  117. ----
  118. # Generate a keystore (azurekeystore.pkcs12)
  119. # Transform private key to PEM format
  120. openssl pkcs8 -topk8 -nocrypt -in azure-private.key -inform PEM -out azure-pk.pem -outform PEM
  121. # Transform certificate to PEM format
  122. openssl x509 -inform der -in azure-certificate.cer -out azure-cert.pem
  123. cat azure-cert.pem azure-pk.pem > azure.pem.txt
  124. # You MUST enter a password!
  125. openssl pkcs12 -export -in azure.pem.txt -out azurekeystore.pkcs12 -name azure -noiter -nomaciter
  126. ----
  127. Upload the `azure-certificate.cer` file both in the Elasticsearch Cloud Service (under `Manage Certificates`),
  128. and under `Settings -> Manage Certificates`.
  129. IMPORTANT: When prompted for a password, you need to enter a non empty one.
  130. See this http://www.windowsazure.com/en-us/manage/linux/how-to-guides/ssh-into-linux/[guide] for
  131. more details about how to create keys for Azure.
  132. Once done, you need to upload your certificate in Azure:
  133. * Go to the https://account.windowsazure.com/[management console].
  134. * Sign in using your account.
  135. * Click on `Portal`.
  136. * Go to Settings (bottom of the left list)
  137. * On the bottom bar, click on `Upload` and upload your `azure-certificate.cer` file.
  138. You may want to use
  139. http://www.windowsazure.com/en-us/develop/nodejs/how-to-guides/command-line-tools/[Windows Azure Command-Line Tool]:
  140. --
  141. * Install https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager[NodeJS], for example using
  142. homebrew on MacOS X:
  143. +
  144. [source,sh]
  145. ----
  146. brew install node
  147. ----
  148. * Install Azure tools
  149. +
  150. [source,sh]
  151. ----
  152. sudo npm install azure-cli -g
  153. ----
  154. * Download and import your azure settings:
  155. +
  156. [source,sh]
  157. ----
  158. # This will open a browser and will download a .publishsettings file
  159. azure account download
  160. # Import this file (we have downloaded it to /tmp)
  161. # Note, it will create needed files in ~/.azure. You can remove azure.publishsettings when done.
  162. azure account import /tmp/azure.publishsettings
  163. ----
  164. [[discovery-azure-classic-long-instance]]
  165. ===== Creating your first instance
  166. You need to have a storage account available. Check http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/#create-account[Azure Blob Storage documentation]
  167. for more information.
  168. You will need to choose the operating system you want to run on. To get a list of official available images, run:
  169. [source,sh]
  170. ----
  171. azure vm image list
  172. ----
  173. Let's say we are going to deploy an Ubuntu image on an extra small instance in West Europe:
  174. [horizontal]
  175. Azure cluster name::
  176. `azure-elasticsearch-cluster`
  177. Image::
  178. `b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_10-amd64-server-20130808-alpha3-en-us-30GB`
  179. VM Name::
  180. `myesnode1`
  181. VM Size::
  182. `extrasmall`
  183. Location::
  184. `West Europe`
  185. Login::
  186. `elasticsearch`
  187. Password::
  188. `password1234!!`
  189. Using command line:
  190. [source,sh]
  191. ----
  192. azure vm create azure-elasticsearch-cluster \
  193. b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-13_10-amd64-server-20130808-alpha3-en-us-30GB \
  194. --vm-name myesnode1 \
  195. --location "West Europe" \
  196. --vm-size extrasmall \
  197. --ssh 22 \
  198. --ssh-cert /tmp/azure-certificate.pem \
  199. elasticsearch password1234\!\!
  200. ----
  201. You should see something like:
  202. [source,text]
  203. ----
  204. info: Executing command vm create
  205. + Looking up image
  206. + Looking up cloud service
  207. + Creating cloud service
  208. + Retrieving storage accounts
  209. + Configuring certificate
  210. + Creating VM
  211. info: vm create command OK
  212. ----
  213. Now, your first instance is started.
  214. [TIP]
  215. .Working with SSH
  216. ===============================================
  217. You need to give the private key and username each time you log on your instance:
  218. [source,sh]
  219. ----
  220. ssh -i ~/.ssh/azure-private.key elasticsearch@myescluster.cloudapp.net
  221. ----
  222. But you can also define it once in `~/.ssh/config` file:
  223. [source,text]
  224. ----
  225. Host *.cloudapp.net
  226. User elasticsearch
  227. StrictHostKeyChecking no
  228. UserKnownHostsFile=/dev/null
  229. IdentityFile ~/.ssh/azure-private.key
  230. ----
  231. ===============================================
  232. Next, you need to install Elasticsearch on your new instance. First, copy your
  233. keystore to the instance, then connect to the instance using SSH:
  234. [source,sh]
  235. ----
  236. scp /tmp/azurekeystore.pkcs12 azure-elasticsearch-cluster.cloudapp.net:/home/elasticsearch
  237. ssh azure-elasticsearch-cluster.cloudapp.net
  238. ----
  239. Once connected, {stack-gs}/get-started-elastic-stack.html#install-elasticsearch[install {es}]:
  240. Check that Elasticsearch is running:
  241. [source,console]
  242. ----
  243. GET /
  244. ----
  245. This command should give you a JSON result:
  246. ["source","js",subs="attributes,callouts"]
  247. --------------------------------------------
  248. {
  249. "name" : "Cp8oag6",
  250. "cluster_name" : "elasticsearch",
  251. "cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
  252. "version" : {
  253. "number" : "{version_qualified}",
  254. "build_flavor" : "{build_flavor}",
  255. "build_type" : "{build_type}",
  256. "build_hash" : "f27399d",
  257. "build_date" : "2016-03-30T09:51:41.449Z",
  258. "build_snapshot" : false,
  259. "lucene_version" : "{lucene_version}",
  260. "minimum_wire_compatibility_version" : "1.2.3",
  261. "minimum_index_compatibility_version" : "1.2.3"
  262. },
  263. "tagline" : "You Know, for Search"
  264. }
  265. --------------------------------------------
  266. // TESTRESPONSE[s/"name" : "Cp8oag6",/"name" : "$body.name",/]
  267. // TESTRESPONSE[s/"cluster_name" : "elasticsearch",/"cluster_name" : "$body.cluster_name",/]
  268. // TESTRESPONSE[s/"cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",/"cluster_uuid" : "$body.cluster_uuid",/]
  269. // TESTRESPONSE[s/"build_hash" : "f27399d",/"build_hash" : "$body.version.build_hash",/]
  270. // TESTRESPONSE[s/"build_date" : "2016-03-30T09:51:41.449Z",/"build_date" : $body.version.build_date,/]
  271. // TESTRESPONSE[s/"build_snapshot" : false,/"build_snapshot" : $body.version.build_snapshot,/]
  272. // TESTRESPONSE[s/"minimum_wire_compatibility_version" : "1.2.3"/"minimum_wire_compatibility_version" : $body.version.minimum_wire_compatibility_version/]
  273. // TESTRESPONSE[s/"minimum_index_compatibility_version" : "1.2.3"/"minimum_index_compatibility_version" : $body.version.minimum_index_compatibility_version/]
  274. // So much s/// but at least we test that the layout is close to matching....
  275. [[discovery-azure-classic-long-plugin]]
  276. ===== Install Elasticsearch cloud azure plugin
  277. [source,sh]
  278. ----
  279. # Stop Elasticsearch
  280. sudo service elasticsearch stop
  281. # Install the plugin
  282. sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install discovery-azure-classic
  283. # Configure it
  284. sudo vi /etc/elasticsearch/elasticsearch.yml
  285. ----
  286. And add the following lines:
  287. [source,yaml]
  288. ----
  289. # If you don't remember your account id, you may get it with `azure account list`
  290. cloud:
  291. azure:
  292. management:
  293. subscription.id: your_azure_subscription_id
  294. cloud.service.name: your_azure_cloud_service_name
  295. keystore:
  296. path: /home/elasticsearch/azurekeystore.pkcs12
  297. password: your_password_for_keystore
  298. discovery:
  299. type: azure
  300. # Recommended (warning: non durable disk)
  301. # path.data: /mnt/resource/elasticsearch/data
  302. ----
  303. Restart Elasticsearch:
  304. [source,sh]
  305. ----
  306. sudo service elasticsearch start
  307. ----
  308. If anything goes wrong, check your logs in `/var/log/elasticsearch`.
  309. [[discovery-azure-classic-scale]]
  310. ==== Scaling Out!
  311. You need first to create an image of your previous machine.
  312. Disconnect from your machine and run locally the following commands:
  313. [source,sh]
  314. ----
  315. # Shutdown the instance
  316. azure vm shutdown myesnode1
  317. # Create an image from this instance (it could take some minutes)
  318. azure vm capture myesnode1 esnode-image --delete
  319. # Note that the previous instance has been deleted (mandatory)
  320. # So you need to create it again and BTW create other instances.
  321. azure vm create azure-elasticsearch-cluster \
  322. esnode-image \
  323. --vm-name myesnode1 \
  324. --location "West Europe" \
  325. --vm-size extrasmall \
  326. --ssh 22 \
  327. --ssh-cert /tmp/azure-certificate.pem \
  328. elasticsearch password1234\!\!
  329. ----
  330. [TIP]
  331. =========================================
  332. It could happen that azure changes the endpoint public IP address.
  333. DNS propagation could take some minutes before you can connect again using
  334. name. You can get from azure the IP address if needed, using:
  335. [source,sh]
  336. ----
  337. # Look at Network `Endpoints 0 Vip`
  338. azure vm show myesnode1
  339. ----
  340. =========================================
  341. Let's start more instances!
  342. [source,sh]
  343. ----
  344. for x in $(seq 2 10)
  345. do
  346. echo "Launching azure instance #$x..."
  347. azure vm create azure-elasticsearch-cluster \
  348. esnode-image \
  349. --vm-name myesnode$x \
  350. --vm-size extrasmall \
  351. --ssh $((21 + $x)) \
  352. --ssh-cert /tmp/azure-certificate.pem \
  353. --connect \
  354. elasticsearch password1234\!\!
  355. done
  356. ----
  357. If you want to remove your running instances:
  358. [source,sh]
  359. ----
  360. azure vm delete myesnode1
  361. ----