discovery-azure.asciidoc 13 KB

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