discovery-azure-classic.asciidoc 14 KB

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