Elasticsearch How to Install OpenSearch on EC2 Using Terraform

Opster Team

Oct 30, 2022 | 2 min read

In addition to reading this guide, we recommend you run the Elasticsearch Health Check-Up. It will detect issues and improve your Elasticsearch performance by analyzing your shard sizes, threadpools, memory, snapshots, disk watermarks and more.

The Elasticsearch Check-Up is free and requires no installation.

To manage all aspects of your OpenSearch operation, you can use Opster’s Management Console (OMC). The OMC makes it easy to orchestrate and manage OpenSearch in any environment. Using the OMC you can deploy multiple clusters, configure node roles, scale cluster resources, manage certificates and more – all from a single interface, for free. Check it out here.

What you need for installing OpenSearch on EC2

The new Terraform module will deploy by default 5 EC2 instances, 3 EBS, and 5 route-53 records. The EC2 instances will host 3 data nodes, 1 master node and 1 OpenSearch dashboard.

You can choose whether to deploy the cluster in one of your existing VPCs or create a new VPC to deploy the cluster in. 

Note that in order for the module to succeed, you must have a route-53 resource that connects to your VPC. This is needed for the node discovery.

These are the variables you will need to set and update in order to deploy the cluster in the root folder on  main.tf file:

  cluster_name = "opensearch-cluster"
  key_name = <your .pem key for connection to the EC2’s>
  create_vpc = <true if you want to create a new vpc, false if you want to use your own>
  vpc_id = 
  subnet_id = <your security group ID>
  route53_zone = <your route53 zone ID>
  route53_domain = <domain name (dom.com)>
  Path_to_data = <path to your Opensearch data disk>

If you want you can also change more variables as you wish in modules/opensearch/variables but  we recommend keeping some of these variables at their default settings, including:

  • Ami = Centos7, should be kept that way because the installation script adjusted to this OS.
  • Instance_type = if you want to change it, please keep the ec2’s with at least 8 GB ram.

Here you can also change the architecture of your environment and add more nodes, just keep in mind that you will always need at least 1 data node, 1 master and 1 dashboard. If you choose to add more nodes, do not forget to add those hosts to the OpenSearch conf file on source/conf_setup (see more details on README.md file). 

The variables we recommend changing are:

  • Key_name
  • Create_vpc
  • Vpc_id
  • Subnet_id
  • Reoute53_zone
  • Route53_domain

How to deploy your new OpenSearch cluster

After setting all the variables, run the following 3 commands in the root main.tf directory to deploy the cluster:

   terraform init
   terraform plan
   terraform apply

Follow the execution output and wait a few minutes for the cluster to appear. This is the the message you’ll see confirming that the cluster has been created:

Apply complete! Resources: 10 added, 0 changed, 0 destroyed.

It will take more or less 10 minutes for the cluster to finish its initialization process & bootstrap checks and become available for use.

To check that the cluster is up, running, and available, you can run the following command and wait for a 200-ok response.

curl -XGET https://master-opensearch.domain.com:9200 -u 'admin:admin' --insecure

That’s it! Your cluster is up and running. In order to access OpenSearch Dashboards you can go in your browser to dashboard-opensearch.<yourdomain>.com:5601/ and connect with admin:admin.

If you have any questions, you can follow the Terraform module in the github repo – see here. Feel free to open a ticket or a Pull Request if you want to contribute, and stay tuned – the Opster team is working on some very cool and valuable OpenSearch additions, coming soon! 

Find and fix issues Elasticsearch issues, try AutoOps

Watch product tour

Try For Free
Skip to content