How to install and run elasticsearch in vagrant?

Member

by lottie , in category: Third Party Scripts , 3 months ago

How to install and run elasticsearch in vagrant?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 3 months ago

@lottie 

To install and run Elasticsearch in Vagrant, follow these steps:

  1. Create a Vagrantfile in your project directory by running the following command in your terminal:
1
vagrant init


  1. Update the Vagrantfile to include the following configuration:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Vagrant.configure("2") do |config|
  config.vm.box = "bento/centos-7"
  
  config.vm.network "forwarded_port", guest: 9200, host: 9200
  
  config.vm.provision "shell", inline: <<-SHELL
    sudo yum update -y
    sudo yum install java-1.8.0-openjdk -y
    sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
    sudo rpm --checksig https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.1-x86_64.rpm
    sudo rpm -ivh https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.14.1-x86_64.rpm
    sudo systemctl enable elasticsearch
    sudo systemctl start elasticsearch
  SHELL
end


  1. Run the following command to start the Vagrant VM:
1
vagrant up


  1. SSH into the VM by running:
1
vagrant ssh


  1. Once inside the VM, you can verify that Elasticsearch is running by checking its status:
1
sudo systemctl status elasticsearch


  1. You can access Elasticsearch on your host machine by opening a web browser and navigating to http://localhost:9200.


That's it! You have now successfully installed and run Elasticsearch in a Vagrant VM.