cloud-gce.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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-first-instance]]
  56. ===== Creating your first instance
  57. [source,sh]
  58. --------------------------------------------------
  59. gcutil addinstance myesnode1 \
  60. --service_account_scope=compute-rw,storage-full \
  61. --persistent_boot_disk
  62. --------------------------------------------------
  63. Then follow these steps:
  64. * You will be asked to open a link in your browser. Login and allow access to listed services.
  65. * You will get back a verification code. Copy and paste it in your terminal.
  66. * You should see an `Authentication successful.` message.
  67. * Choose your zone, e.g. `europe-west1-a`.
  68. * Choose your compute instance size, e.g. `f1-micro`.
  69. * Choose your OS, e.g. `projects/debian-cloud/global/images/debian-7-wheezy-v20140606`.
  70. * You may be asked to create a ssh key. Follow the instructions to create one.
  71. When done, a report like this one should appears:
  72. [source,text]
  73. --------------------------------------------------
  74. Table of resources:
  75. +-----------+--------------+-------+---------+--------------+----------------+----------------+----------------+---------+----------------+
  76. | name | machine-type | image | network | network-ip | external-ip | disks | zone | status | status-message |
  77. +-----------+--------------+-------+---------+--------------+----------------+----------------+----------------+---------+----------------+
  78. | myesnode1 | f1-micro | | default | 10.240.20.57 | 192.158.29.199 | boot-myesnode1 | europe-west1-a | RUNNING | |
  79. +-----------+--------------+-------+---------+--------------+----------------+----------------+----------------+---------+----------------+
  80. --------------------------------------------------
  81. You can now connect to your instance:
  82. [source,sh]
  83. --------------------------------------------------
  84. # Connect using google cloud SDK
  85. gcloud compute ssh myesnode1 --zone europe-west1-a
  86. # Or using SSH with external IP address
  87. ssh -i ~/.ssh/google_compute_engine 192.158.29.199
  88. --------------------------------------------------
  89. [IMPORTANT]
  90. .Service Account Permissions
  91. ==============================================
  92. It's important when creating an instance that the correct permissions are set. At a minimum, you must ensure you have:
  93. [source,text]
  94. --------------------------------------------------
  95. service_account_scope=compute-rw
  96. --------------------------------------------------
  97. Failing to set this will result in unauthorized messages when starting Elasticsearch.
  98. See [Machine Permissions](#machine-permissions).
  99. ==============================================
  100. Once connected, install Elasticsearch:
  101. [source,sh]
  102. --------------------------------------------------
  103. sudo apt-get update
  104. # Download Elasticsearch
  105. wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-2.0.0.deb
  106. # Prepare Java installation
  107. sudo apt-get install java7-runtime-headless
  108. # Prepare Elasticsearch installation
  109. sudo dpkg -i elasticsearch-2.0.0.deb
  110. --------------------------------------------------
  111. [[cloud-gce-usage-discovery-long-install-plugin]]
  112. ===== Install elasticsearch cloud gce plugin
  113. Install the plugin:
  114. [source,sh]
  115. --------------------------------------------------
  116. # Use Plugin Manager to install it
  117. sudo bin/plugin install cloud-gce
  118. --------------------------------------------------
  119. Open the `elasticsearch.yml` file:
  120. [source,sh]
  121. --------------------------------------------------
  122. sudo vi /etc/elasticsearch/elasticsearch.yml
  123. --------------------------------------------------
  124. And add the following lines:
  125. [source,yaml]
  126. --------------------------------------------------
  127. cloud:
  128. gce:
  129. project_id: es-cloud
  130. zone: europe-west1-a
  131. discovery:
  132. type: gce
  133. --------------------------------------------------
  134. Start elasticsearch:
  135. [source,sh]
  136. --------------------------------------------------
  137. sudo /etc/init.d/elasticsearch start
  138. --------------------------------------------------
  139. If anything goes wrong, you should check logs:
  140. [source,sh]
  141. --------------------------------------------------
  142. tail -f /var/log/elasticsearch/elasticsearch.log
  143. --------------------------------------------------
  144. If needed, you can change log level to `TRACE` by opening `logging.yml`:
  145. [source,sh]
  146. --------------------------------------------------
  147. sudo vi /etc/elasticsearch/logging.yml
  148. --------------------------------------------------
  149. and adding the following line:
  150. [source,yaml]
  151. --------------------------------------------------
  152. # discovery
  153. discovery.gce: TRACE
  154. --------------------------------------------------
  155. [[cloud-gce-usage-discovery-cloning]]
  156. ==== Cloning your existing machine
  157. In order to build a cluster on many nodes, you can clone your configured instance to new nodes.
  158. You won't have to reinstall everything!
  159. First create an image of your running instance and upload it to Google Cloud Storage:
  160. [source,sh]
  161. --------------------------------------------------
  162. # Create an image of yur current instance
  163. sudo /usr/bin/gcimagebundle -d /dev/sda -o /tmp/
  164. # An image has been created in `/tmp` directory:
  165. ls /tmp
  166. e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz
  167. # Upload your image to Google Cloud Storage:
  168. # Create a bucket to hold your image, let's say `esimage`:
  169. gsutil mb gs://esimage
  170. # Copy your image to this bucket:
  171. gsutil cp /tmp/e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz gs://esimage
  172. # Then add your image to images collection:
  173. gcutil addimage elasticsearch-1-2-1 gs://esimage/e4686d7f5bf904a924ae0cfeb58d0827c6d5b966.image.tar.gz
  174. # If the previous command did not work for you, logout from your instance
  175. # and launch the same command from your local machine.
  176. --------------------------------------------------
  177. [[cloud-gce-usage-discovery-start-new-instances]]
  178. ===== Start new instances
  179. As you have now an image, you can create as many instances as you need:
  180. [source,sh]
  181. --------------------------------------------------
  182. # Just change node name (here myesnode2)
  183. gcutil addinstance --image=elasticsearch-1-2-1 myesnode2
  184. # If you want to provide all details directly, you can use:
  185. gcutil addinstance --image=elasticsearch-1-2-1 \
  186. --kernel=projects/google/global/kernels/gce-v20130603 myesnode2 \
  187. --zone europe-west1-a --machine_type f1-micro --service_account_scope=compute-rw \
  188. --persistent_boot_disk
  189. --------------------------------------------------
  190. [[cloud-gce-usage-discovery-remove-instance]]
  191. ===== Remove an instance (aka shut it down)
  192. You can use https://cloud.google.com/console[Google Cloud Console] or CLI to manage your instances:
  193. [source,sh]
  194. --------------------------------------------------
  195. # Stopping and removing instances
  196. gcutil deleteinstance myesnode1 myesnode2 \
  197. --zone=europe-west1-a
  198. # Consider removing disk as well if you don't need them anymore
  199. gcutil deletedisk boot-myesnode1 boot-myesnode2 \
  200. --zone=europe-west1-a
  201. --------------------------------------------------
  202. [[cloud-gce-usage-discovery-zones]]
  203. ==== Using GCE zones
  204. `cloud.gce.zone` helps to retrieve instances running in a given zone. It should be one of the
  205. https://developers.google.com/compute/docs/zones#available[GCE supported zones].
  206. The GCE discovery can support multi zones although you need to be aware of network latency between zones.
  207. To enable discovery across more than one zone, just enter add your zone list to `cloud.gce.zone` setting:
  208. [source,yaml]
  209. --------------------------------------------------
  210. cloud:
  211. gce:
  212. project_id: <your-google-project-id>
  213. zone: ["<your-zone1>", "<your-zone2>"]
  214. discovery:
  215. type: gce
  216. --------------------------------------------------
  217. [[cloud-gce-usage-discovery-tags]]
  218. ==== Filtering by tags
  219. The GCE discovery can also filter machines to include in the cluster based on tags using `discovery.gce.tags` settings.
  220. For example, setting `discovery.gce.tags` to `dev` will only filter instances having a tag set to `dev`. Several tags
  221. set will require all of those tags to be set for the instance to be included.
  222. One practical use for tag filtering is when an GCE cluster contains many nodes that are not running
  223. elasticsearch. In this case (particularly with high ping_timeout values) there is a risk that a new node's discovery
  224. phase will end before it has found the cluster (which will result in it declaring itself master of a new cluster
  225. with the same name - highly undesirable). Adding tag on elasticsearch GCE nodes and then filtering by that
  226. tag will resolve this issue.
  227. Add your tag when building the new instance:
  228. [source,sh]
  229. --------------------------------------------------
  230. gcutil --project=es-cloud addinstance myesnode1 \
  231. --service_account_scope=compute-rw \
  232. --persistent_boot_disk \
  233. --tags=elasticsearch,dev
  234. --------------------------------------------------
  235. Then, define it in `elasticsearch.yml`:
  236. [source,yaml]
  237. --------------------------------------------------
  238. cloud:
  239. gce:
  240. project_id: es-cloud
  241. zone: europe-west1-a
  242. discovery:
  243. type: gce
  244. gce:
  245. tags: elasticsearch, dev
  246. --------------------------------------------------
  247. [[cloud-gce-usage-discovery-port]]
  248. ==== Changing default transport port
  249. By default, elasticsearch GCE plugin assumes that you run elasticsearch on 9300 default port.
  250. But you can specify the port value elasticsearch is meant to use using google compute engine metadata `es_port`:
  251. [[cloud-gce-usage-discovery-port-create]]
  252. ===== When creating instance
  253. Add `--metadata=es_port:9301` option:
  254. [source,sh]
  255. --------------------------------------------------
  256. # when creating first instance
  257. gcutil addinstance myesnode1 \
  258. --service_account_scope=compute-rw,storage-full \
  259. --persistent_boot_disk \
  260. --metadata=es_port:9301
  261. # when creating an instance from an image
  262. gcutil addinstance --image=elasticsearch-1-0-0-RC1 \
  263. --kernel=projects/google/global/kernels/gce-v20130603 myesnode2 \
  264. --zone europe-west1-a --machine_type f1-micro --service_account_scope=compute-rw \
  265. --persistent_boot_disk --metadata=es_port:9301
  266. --------------------------------------------------
  267. [[cloud-gce-usage-discovery-port-run]]
  268. ===== On a running instance
  269. [source,sh]
  270. --------------------------------------------------
  271. # Get metadata fingerprint
  272. gcutil getinstance myesnode1 --zone=europe-west1-a
  273. +------------------------+---------------------+
  274. | property | value |
  275. +------------------------+---------------------+
  276. | metadata | |
  277. | fingerprint | 42WmSpB8rSM= |
  278. +------------------------+---------------------+
  279. # Use that fingerprint
  280. gcutil setinstancemetadata myesnode1 \
  281. --zone=europe-west1-a \
  282. --metadata=es_port:9301 \
  283. --fingerprint=42WmSpB8rSM=
  284. --------------------------------------------------
  285. [[cloud-gce-usage-discovery-tips]]
  286. ==== GCE Tips
  287. [[cloud-gce-usage-discovery-tips-projectid]]
  288. ===== Store project id locally
  289. If you don't want to repeat the project id each time, you can save it in `~/.gcutil.flags` file using:
  290. [source,sh]
  291. --------------------------------------------------
  292. gcutil getproject --project=es-cloud --cache_flag_values
  293. --------------------------------------------------
  294. `~/.gcutil.flags` file now contains:
  295. [source,text]
  296. --------------------------------------------------
  297. --project=es-cloud
  298. --------------------------------------------------
  299. [[cloud-gce-usage-discovery-tips-permissions]]
  300. ===== Machine Permissions
  301. If you have created a machine without the correct permissions, you will see `403 unauthorized` error messages. The only
  302. way to alter these permissions is to delete the instance (NOT THE DISK). Then create another with the correct permissions.
  303. Creating machines with gcutil::
  304. +
  305. --
  306. Ensure the following flags are set:
  307. [source,text]
  308. --------------------------------------------------
  309. --service_account_scope=compute-rw
  310. --------------------------------------------------
  311. --
  312. Creating with console (web)::
  313. +
  314. --
  315. When creating an instance using the web portal, click _Show advanced options_.
  316. At the bottom of the page, under `PROJECT ACCESS`, choose `>> Compute >> Read Write`.
  317. --
  318. Creating with knife google::
  319. +
  320. --
  321. Set the service account scopes when creating the machine:
  322. [source,sh]
  323. --------------------------------------------------
  324. knife google server create www1 \
  325. -m n1-standard-1 \
  326. -I debian-7-wheezy-v20131120 \
  327. -Z us-central1-a \
  328. -i ~/.ssh/id_rsa \
  329. -x jdoe \
  330. --gce-service-account-scopes https://www.googleapis.com/auth/compute.full_control
  331. --------------------------------------------------
  332. Or, you may use the alias:
  333. [source,sh]
  334. --------------------------------------------------
  335. --gce-service-account-scopes compute-rw
  336. --------------------------------------------------
  337. --
  338. [[cloud-gce-usage-discovery-testing]]
  339. ==== Testing GCE
  340. Integrations tests in this plugin require working GCE configuration and
  341. therefore disabled by default. To enable tests prepare a config file
  342. elasticsearch.yml with the following content:
  343. [source,yaml]
  344. --------------------------------------------------
  345. cloud:
  346. gce:
  347. project_id: es-cloud
  348. zone: europe-west1-a
  349. discovery:
  350. type: gce
  351. --------------------------------------------------
  352. Replaces `project_id` and `zone` with your settings.
  353. To run test:
  354. [source,sh]
  355. --------------------------------------------------
  356. mvn -Dtests.gce=true -Dtests.config=/path/to/config/file/elasticsearch.yml clean test
  357. --------------------------------------------------