discovery-azure-classic.asciidoc 14 KB

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