discovery-azure-classic.asciidoc 14 KB

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