{"id":34213,"date":"2016-05-04T10:35:08","date_gmt":"2016-05-04T05:05:08","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=34213"},"modified":"2024-01-02T17:47:22","modified_gmt":"2024-01-02T12:17:22","slug":"elasticsearch-migration-found-to-aws-ec2","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/elasticsearch-migration-found-to-aws-ec2\/","title":{"rendered":"Elasticsearch Migration : Found to AWS EC2"},"content":{"rendered":"<p>Our <a title=\"devops team\" href=\"http:\/\/www.tothenew.com\/devops-automation-consulting\" target=\"_blank\" rel=\"noopener\">DevOps team<\/a> was using Found for one of our projects in the production environment. We have been facing a\u00a0problem with found where it\u2019s memory pressure frequently goes up and does not drop down so easily and until the time it remains up the Found was not able to serve\u00a0the requests. Then, we decided to move to self-hosted Elasticsearch cluster.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"https:\/\/camo.githubusercontent.com\/970d309f5d85621a6c0b9e6ce0e82d2eca049c23\/687474703a2f2f692e696d6775722e636f6d2f786c3178676a6d2e706e67\" alt=\"\" width=\"605\" height=\"188\" \/><\/p>\n<p><strong>Scenario<\/strong>: Migration of Elasticsearch cluster from Found to AWS EC2 server<\/p>\n<p><strong>Below is the step by step procedure to migrate Elasticsearch cluster from Found to AWS EC2:<\/strong><\/p>\n<ol>\n<li>Stop the indexing requests of the data on Found.<\/li>\n<li>Take the\u00a0dump of data from Found to AWS S3 using \u201c_snapshot\u201d API provided by Elasticsearch.\n<p>[js]#!bin\/bash<br \/>\ncurl -u : -XPUT &quot;:9200\/_snapshot\/backup&quot; -d&#8217;<br \/>\n{<br \/>\n&quot;type&quot;: &quot;s3&quot;,<br \/>\n&quot;settings&quot;: {<br \/>\n&quot;bucket&quot;: &quot;bucket-name&quot;,<br \/>\n&quot;region&quot;: &quot;ap-southeast-1&quot;,<br \/>\n&quot;access_key&quot;: &quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&quot;,<br \/>\n&quot;secret_key&quot;: &quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&quot;,<br \/>\n&quot;compress&quot;: true,<br \/>\n&quot;base_path&quot;: &quot;directory_name_inside_the_bucket&quot;<br \/>\n}<br \/>\n}&#8217;;<br \/>\ncurl -u : -XPUT &quot;:9200\/_snapshot\/backup\/snapshot_prod?wait_for_completion=true&quot;;[\/js]<\/p>\n<p>The first curl request would register the repository \u201cbackup\u201d on the Found where we are telling the Found that this repository would take backup on s3. We would have to provide s3 information in the curl request:<br \/>\nbucket :- Name of S3 bucket where we want to take backup.<br \/>\nregion :- Name of the region of the s3 bucket.<br \/>\naccess_key :- Access key of AWS account where the bucket is present.<br \/>\nsecret_key :- Secret key of AWS account where the bucket is present.<br \/>\ncompress :- Set to true if we want to take\u00a0backup in the\u00a0compressed format.<br \/>\nbase_path :- Name of the folder inside the s3 bucket where the backup is to be taken.<\/p>\n<p>The second curl request would start taking the backup on AWS S3. Ensure the repository name is same (in our case,it is \u201cbackup\u201d). \u201csnapshot_prod\u201d is the name of the snapshot which would be stored on S3. \u2018wait_for_completion=true\u201d would not allow the command to release terminal until the backup is complete.<\/li>\n<li>Once the data dump is complete, restore the data on Elasticsearch running on EC2 on AWS using \u201c_restore\u201d api provided by Elasticsearch.\n<p>[js]curl -XPUT &quot;http:\/\/:9200\/_snapshot\/myrepo&quot; -d'{<br \/>\n&quot;type&quot;: &quot;s3&quot;,<br \/>\n&quot;settings&quot;: {<br \/>\n&quot;bucket&quot;: &quot;bucket-name&quot;,<br \/>\n&quot;region&quot;: &quot;ap-southeast-1&quot;,<br \/>\n&quot;access_key&quot;: &quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&quot;,<br \/>\n&quot;secret_key&quot;: &quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&quot;,<br \/>\n&quot;compress&quot;: true,<br \/>\n&quot;base_path&quot;: &quot;directory_name_inside_the_bucket&quot;<br \/>\n}<br \/>\n}&#8217;;<br \/>\ncurl -XPOST &quot;http:\/\/:9200\/*\/_close&quot;;<br \/>\ncurl -XPOST &quot;http:\/\/:9200\/_snapshot\/myrepo\/snapshot_prod\/_restore?wait_for_completion=true&quot;;[\/js]<\/p>\n<p>The first curl request would register the repository on the Elasticsearch cluster running on AWS EC2. We need to provide the same details under AWS s3 bucket setting which we have provided in step 2 as the data backup is on that s3 bucket.<br \/>\nThe second curl request is to close all the existing indexes on Elasticsearch cluster running on AWS EC2. For our case, we have set up new Elasticsearch cluster on AWS EC2, we can optionally skip this step.<br \/>\nThe third curl request is \u201cPOST\u201d request which would restore the Elasticsearch data from S3 to the Elasticsearch cluster running on AWS EC2.<\/p>\n<p><strong>Note<\/strong>:<br \/>\n1. Ensure the repository name should be same which is \u201cmyrepo\u201d in our case.<br \/>\n2. Use the same repository name \u201csnapshot_prod\u201d which we have used in step 2.<\/li>\n<li>The completion step 3 will complete the Migration from Found to Elasticsearch hosted on AWS EC2.<\/li>\n<\/ol>\n<p>This migration required a downtime depending upon the network and the size of the Elasticsearch data. I was able to migrate from Found to AWS EC2 Elasticsearch in forty minutes with a database size of 5Gb.<\/p>\n<p><strong>It is recommended that before migrating to AWS EC2 Elasticsearch Cluster:<\/strong><\/p>\n<ol>\n<li>Ensure at least two nodes are up and running in the Elasticsearch cluster.<\/li>\n<li>Use ec2 discovery provided by &#8220;cloud-aws&#8221; plugin. The plugin should be installed on all the nodes.<\/li>\n<li>Disable swap space on EC2 in case it is enabled.<\/li>\n<li>Set heap size equal to the half of RAM available on EC2.<\/li>\n<li>Use \u201ci\u201d series EC2 instance as it is recommended by AWS for NoSql databases.<\/li>\n<\/ol>\n<p><strong>There are few things which need to be taken care after the migration is complete:<\/strong><\/p>\n<ol>\n<li>Ensure regular (hourly or daily) snapshots are configured. Elasticsearch supports deltas of the database to be backed up. The step 2 curl request could be used to configure it after a\u00a0little modification.<\/li>\n<li>Kopf is one plugin to take and restore the\u00a0backup.<\/li>\n<li>Put alerts on rejected queue of various modules.<\/li>\n<li>Use Shard filtering in case any non-customer facing application is fetching data from some specific indexes.<\/li>\n<li>For monitoring, Marvel can be used but be careful as it daily creates one index. Ensure that it has been properly taken care off.<\/li>\n<li>Implement Http-auth on Elasticsearch Cluster in case \u201chead\u201d plugin is being used.<\/li>\n<\/ol>\n<p>Hope this blog helped you migrate Elasticsearch cluster from Found to AWS EC2. I will share more such use cases with you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our DevOps team was using Found for one of our projects in the production environment. We have been facing a\u00a0problem with found where it\u2019s memory pressure frequently goes up and does not drop down so easily and until the time it remains up the Found was not able to serve\u00a0the requests. Then, we decided to [&hellip;]<\/p>\n","protected":false},"author":154,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":7},"categories":[1174,2348,1],"tags":[2661,1547,4843,2548,3294,1524,3293,1252],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/34213"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/154"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=34213"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/34213\/revisions"}],"predecessor-version":[{"id":59862,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/34213\/revisions\/59862"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=34213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=34213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=34213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}