cloud-gce.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. [[cloud-gce]]
  2. === GCE Cloud Plugin
  3. The Google Compute Engine Cloud plugin uses the GCE API for unicast discovery.
  4. [[cloud-gce-install]]
  5. [float]
  6. ==== Installation
  7. This plugin can be installed using the plugin manager:
  8. [source,sh]
  9. ----------------------------------------------------------------
  10. sudo bin/plugin install cloud-gce
  11. ----------------------------------------------------------------
  12. The plugin must be installed on every node in the cluster, and each node must
  13. be restarted after installation.
  14. [[cloud-gce-remove]]
  15. [float]
  16. ==== Removal
  17. The plugin can be removed with the following command:
  18. [source,sh]
  19. ----------------------------------------------------------------
  20. sudo bin/plugin remove cloud-gce
  21. ----------------------------------------------------------------
  22. The node must be stopped before removing the plugin.
  23. [[cloud-gce-usage-discovery]]
  24. ==== GCE Virtual Machine Discovery
  25. Google Compute Engine VM discovery allows to use the google APIs to perform automatic discovery (similar to multicast
  26. in non hostile multicast environments). Here is a simple sample configuration:
  27. [source,yaml]
  28. --------------------------------------------------
  29. cloud:
  30. gce:
  31. project_id: <your-google-project-id>
  32. zone: <your-zone>
  33. discovery:
  34. type: gce
  35. --------------------------------------------------
  36. [[cloud-gce-usage-discovery-short]]
  37. ===== How to start (short story)
  38. * Create Google Compute Engine instance (with compute rw permissions)
  39. * Install Elasticsearch
  40. * Install Google Compute Engine Cloud plugin
  41. * Modify `elasticsearch.yml` file
  42. * Start Elasticsearch
  43. [[cloud-gce-usage-discovery-long]]
  44. ==== Setting up GCE Discovery
  45. [[cloud-gce-usage-discovery-long-prerequisites]]
  46. ===== Prerequisites
  47. Before starting, you need:
  48. * Your project ID, e.g. `es-cloud`. Get it from https://code.google.com/apis/console/[Google API Console].
  49. * To install https://developers.google.com/cloud/sdk/[Google Cloud SDK]
  50. If you did not set it yet, you can define your default project you will work on:
  51. [source,sh]
  52. --------------------------------------------------
  53. gcloud config set project es-cloud
  54. --------------------------------------------------
  55. [[cloud-gce-usage-discovery-long-login]]
  56. If you haven't already, login to Google Cloud
  57. [source,sh]
  58. --------------------------------------------------
  59. gcloud auth login
  60. --------------------------------------------------
  61. This will open your browser. You will be asked to sign-in to a Google account and
  62. authorize access to the Google Cloud SDK.
  63. [[cloud-gce-usage-discovery-long-first-instance]]
  64. ===== Creating your first instance
  65. [source,sh]
  66. --------------------------------------------------
  67. gcloud compute instances create myesnode1 \
  68. --zone <your-zone> \
  69. --scopes compute-rw
  70. --------------------------------------------------
  71. When done, a report like this one should appears:
  72. [source,text]
  73. --------------------------------------------------
  74. Created [https://www.googleapis.com/compute/v1/projects/es-cloud-1070/zones/us-central1-f/instances/myesnode1].
  75. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
  76. myesnode1 us-central1-f n1-standard-1 10.240.133.54 104.197.94.25 RUNNING
  77. --------------------------------------------------
  78. You can now connect to your instance:
  79. [source,sh]
  80. --------------------------------------------------
  81. # Connect using google cloud SDK
  82. gcloud compute ssh myesnode1 --zone europe-west1-a
  83. # Or using SSH with external IP address
  84. ssh -i ~/.ssh/google_compute_engine 192.158.29.199
  85. --------------------------------------------------
  86. [IMPORTANT]
  87. .Service Account Permissions
  88. ==============================================
  89. It's important when creating an instance that the correct permissions are set. At a minimum, you must ensure you have:
  90. [source,text]
  91. --------------------------------------------------
  92. scopes=compute-rw
  93. --------------------------------------------------
  94. Failing to set this will result in unauthorized messages when starting Elasticsearch.
  95. See [Machine Permissions](#machine-permissions).
  96. ==============================================
  97. Once connected, install Elasticsearch:
  98. [source,sh]
  99. --------------------------------------------------
  100. sudo apt-get update
  101. # Download Elasticsearch
  102. wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-2.0.0.deb
  103. # Prepare Java installation
  104. sudo apt-get install java8-runtime-headless
  105. # Prepare Elasticsearch installation
  106. sudo dpkg -i elasticsearch-2.0.0.deb
  107. --------------------------------------------------
  108. [[cloud-gce-usage-discovery-long-install-plugin]]
  109. ===== Install elasticsearch cloud gce plugin
  110. Install the plugin:
  111. [source,sh]
  112. --------------------------------------------------
  113. # Use Plugin Manager to install it
  114. sudo bin/plugin install cloud-gce
  115. --------------------------------------------------
  116. Open the `elasticsearch.yml` file:
  117. [source,sh]
  118. --------------------------------------------------
  119. sudo vi /etc/elasticsearch/elasticsearch.yml
  120. --------------------------------------------------
  121. And add the following lines:
  122. [source,yaml]
  123. --------------------------------------------------
  124. cloud:
  125. gce:
  126. project_id: es-cloud
  127. zone: europe-west1-a
  128. discovery:
  129. type: gce
  130. --------------------------------------------------
  131. Start elasticsearch:
  132. [source,sh]
  133. --------------------------------------------------
  134. sudo /etc/init.d/elasticsearch start
  135. --------------------------------------------------
  136. If anything goes wrong, you should check logs:
  137. [source,sh]
  138. --------------------------------------------------
  139. tail -f /var/log/elasticsearch/elasticsearch.log
  140. --------------------------------------------------
  141. If needed, you can change log level to `TRACE` by opening `logging.yml`:
  142. [source,sh]
  143. --------------------------------------------------
  144. sudo vi /etc/elasticsearch/logging.yml
  145. --------------------------------------------------
  146. and adding the following line:
  147. [source,yaml]
  148. --------------------------------------------------
  149. # discovery
  150. discovery.gce: TRACE
  151. --------------------------------------------------
  152. [[cloud-gce-usage-discovery-cloning]]
  153. ==== Cloning your existing machine
  154. In order to build a cluster on many nodes, you can clone your configured instance to new nodes.
  155. You won't have to reinstall everything!
  156. First create an image of your running instance and upload it to Google Cloud Storage:
  157. [source,sh]
  158. --------------------------------------------------
  159. # Create an image of yur current instance
  160. sudo /usr/bin/gcimagebundle -d /dev/sda -o /tmp/
  161. # An image has been created in `/tmp` directory:
  162. ls /tmp
  163. e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz
  164. # Upload your image to Google Cloud Storage:
  165. # Create a bucket to hold your image, let's say `esimage`:
  166. gsutil mb gs://esimage
  167. # Copy your image to this bucket:
  168. gsutil cp /tmp/e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz gs://esimage
  169. # Then add your image to images collection:
  170. gcloud compute images create elasticsearch-2-0-0 --source-uri gs://esimage/e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz
  171. # If the previous command did not work for you, logout from your instance
  172. # and launch the same command from your local machine.
  173. --------------------------------------------------
  174. [[cloud-gce-usage-discovery-start-new-instances]]
  175. ===== Start new instances
  176. As you have now an image, you can create as many instances as you need:
  177. [source,sh]
  178. --------------------------------------------------
  179. # Just change node name (here myesnode2)
  180. gcloud compute instances create myesnode2 --image elasticsearch-2-0-0 --zone europe-west1-a
  181. # If you want to provide all details directly, you can use:
  182. gcloud compute instances create myesnode2 --image=elasticsearch-2-0-0 \
  183. --zone europe-west1-a --machine-type f1-micro --scopes=compute-rw
  184. --------------------------------------------------
  185. [[cloud-gce-usage-discovery-remove-instance]]
  186. ===== Remove an instance (aka shut it down)
  187. You can use https://cloud.google.com/console[Google Cloud Console] or CLI to manage your instances:
  188. [source,sh]
  189. --------------------------------------------------
  190. # Stopping and removing instances
  191. gcloud compute instances delete myesnode1 myesnode2 \
  192. --zone=europe-west1-a
  193. # Consider removing disk as well if you don't need them anymore
  194. gcloud compute disks deleted boot-myesnode1 boot-myesnode2 \
  195. --zone=europe-west1-a
  196. --------------------------------------------------
  197. [[cloud-gce-usage-discovery-zones]]
  198. ==== Using GCE zones
  199. `cloud.gce.zone` helps to retrieve instances running in a given zone. It should be one of the
  200. https://developers.google.com/compute/docs/zones#available[GCE supported zones].
  201. The GCE discovery can support multi zones although you need to be aware of network latency between zones.
  202. To enable discovery across more than one zone, just enter add your zone list to `cloud.gce.zone` setting:
  203. [source,yaml]
  204. --------------------------------------------------
  205. cloud:
  206. gce:
  207. project_id: <your-google-project-id>
  208. zone: ["<your-zone1>", "<your-zone2>"]
  209. discovery:
  210. type: gce
  211. --------------------------------------------------
  212. [[cloud-gce-usage-discovery-tags]]
  213. ==== Filtering by tags
  214. The GCE discovery can also filter machines to include in the cluster based on tags using `discovery.gce.tags` settings.
  215. For example, setting `discovery.gce.tags` to `dev` will only filter instances having a tag set to `dev`. Several tags
  216. set will require all of those tags to be set for the instance to be included.
  217. One practical use for tag filtering is when an GCE cluster contains many nodes that are not running
  218. elasticsearch. In this case (particularly with high ping_timeout values) there is a risk that a new node's discovery
  219. phase will end before it has found the cluster (which will result in it declaring itself master of a new cluster
  220. with the same name - highly undesirable). Adding tag on elasticsearch GCE nodes and then filtering by that
  221. tag will resolve this issue.
  222. Add your tag when building the new instance:
  223. [source,sh]
  224. --------------------------------------------------
  225. gcloud compute instances create myesnode1 --project=es-cloud \
  226. --scopes=compute-rw \
  227. --tags=elasticsearch,dev
  228. --------------------------------------------------
  229. Then, define it in `elasticsearch.yml`:
  230. [source,yaml]
  231. --------------------------------------------------
  232. cloud:
  233. gce:
  234. project_id: es-cloud
  235. zone: europe-west1-a
  236. discovery:
  237. type: gce
  238. gce:
  239. tags: elasticsearch, dev
  240. --------------------------------------------------
  241. [[cloud-gce-usage-discovery-port]]
  242. ==== Changing default transport port
  243. By default, elasticsearch GCE plugin assumes that you run elasticsearch on 9300 default port.
  244. But you can specify the port value elasticsearch is meant to use using google compute engine metadata `es_port`:
  245. [[cloud-gce-usage-discovery-port-create]]
  246. ===== When creating instance
  247. Add `--metadata es_port=9301` option:
  248. [source,sh]
  249. --------------------------------------------------
  250. # when creating first instance
  251. gcloud compute instances create myesnode1 \
  252. --scopes=compute-rw,storage-full \
  253. --metadata es_port=9301
  254. # when creating an instance from an image
  255. gcloud compute instances create myesnode2 --image=elasticsearch-1-0-0-RC1 \
  256. --zone europe-west1-a --machine-type f1-micro --scopes=compute-rw \
  257. --metadata es_port=9301
  258. --------------------------------------------------
  259. [[cloud-gce-usage-discovery-port-run]]
  260. ===== On a running instance
  261. [source,sh]
  262. --------------------------------------------------
  263. gcloud compute instances add-metadata myesnode1 \
  264. --zone europe-west1-a \
  265. --metadata es_port=9301
  266. --------------------------------------------------
  267. [[cloud-gce-usage-discovery-tips]]
  268. ==== GCE Tips
  269. [[cloud-gce-usage-discovery-tips-projectid]]
  270. ===== Store project id locally
  271. If you don't want to repeat the project id each time, you can save it in the local gcloud config
  272. [source,sh]
  273. --------------------------------------------------
  274. gcloud config set project es-cloud
  275. --------------------------------------------------
  276. [[cloud-gce-usage-discovery-tips-permissions]]
  277. ===== Machine Permissions
  278. If you have created a machine without the correct permissions, you will see `403 unauthorized` error messages. The only
  279. way to alter these permissions is to delete the instance (NOT THE DISK). Then create another with the correct permissions.
  280. Creating machines with gcloud::
  281. +
  282. --
  283. Ensure the following flags are set:
  284. [source,text]
  285. --------------------------------------------------
  286. --scopes=compute-rw
  287. --------------------------------------------------
  288. --
  289. Creating with console (web)::
  290. +
  291. --
  292. When creating an instance using the web portal, click _Show advanced options_.
  293. At the bottom of the page, under `PROJECT ACCESS`, choose `>> Compute >> Read Write`.
  294. --
  295. Creating with knife google::
  296. +
  297. --
  298. Set the service account scopes when creating the machine:
  299. [source,sh]
  300. --------------------------------------------------
  301. knife google server create www1 \
  302. -m n1-standard-1 \
  303. -I debian-8 \
  304. -Z us-central1-a \
  305. -i ~/.ssh/id_rsa \
  306. -x jdoe \
  307. --gce-service-account-scopes https://www.googleapis.com/auth/compute.full_control
  308. --------------------------------------------------
  309. Or, you may use the alias:
  310. [source,sh]
  311. --------------------------------------------------
  312. --gce-service-account-scopes compute-rw
  313. --------------------------------------------------
  314. --
  315. [[cloud-gce-usage-discovery-testing]]
  316. ==== Testing GCE
  317. Integrations tests in this plugin require working GCE configuration and
  318. therefore disabled by default. To enable tests prepare a config file
  319. elasticsearch.yml with the following content:
  320. [source,yaml]
  321. --------------------------------------------------
  322. cloud:
  323. gce:
  324. project_id: es-cloud
  325. zone: europe-west1-a
  326. discovery:
  327. type: gce
  328. --------------------------------------------------
  329. Replaces `project_id` and `zone` with your settings.
  330. To run test:
  331. [source,sh]
  332. --------------------------------------------------
  333. mvn -Dtests.gce=true -Dtests.config=/path/to/config/file/elasticsearch.yml clean test
  334. --------------------------------------------------