discovery-azure.asciidoc 13 KB

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