discovery-azure-classic.asciidoc 15 KB

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