Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Last active January 13, 2019 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save carlessanagustin/668e85c9569bb061b405 to your computer and use it in GitHub Desktop.
Save carlessanagustin/668e85c9569bb061b405 to your computer and use it in GitHub Desktop.
Testing: Install Consul in Vagrant machines

forked from https://github.com/hashicorp/consul/tree/master/demo/vagrant-cluster

Vagrant Consul Demo

This demo provides a very simple Vagrantfile that creates 3 nodes, one at "172.20.20.10", "172.20.20.11" and "172.20.20.12". Both are running a standard Ubuntu distribution and the script will install Consul and Web UI in all of them.

To get started, you can start the cluster by just doing:

$ vagrant up

Once it is finished, you should be able to see the following:

$ vagrant status
Current machine states:
n1                        running (virtualbox)
n2                        running (virtualbox)
n3                        running (virtualbox)

At this point the two nodes are running and you can SSH in to play with them:

$ vagrant ssh n1
...
$ vagrant ssh n2
...
$ vagrant ssh n3
...

To learn more about starting Consul, joining nodes and interacting with the agent, checkout the getting started guide.

To destroy Vagrant machines

$ vagrant destroy -f
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
echo Updating linux
sudo apt-get update && sudo apt-get -y upgrade
echo Installing dependencies...
sudo apt-get install -y unzip curl
sudo apt-get -y autoremove
echo Fetching Consul...
cd /tmp/
wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip -O consul.zip
echo Installing Consul...
unzip consul.zip
sudo chmod +x consul
sudo mv consul /usr/bin/consul
echo Setup config folder...
sudo mkdir /etc/consul.d
sudo chmod a+w /etc/consul.d
echo Installing Consul Web UI
cd /tmp/
wget https://dl.bintray.com/mitchellh/consul/0.5.2_web_ui.zip -O web_ui.zip
unzip web_ui.zip
sudo mv dist /opt/
SCRIPT
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.boot_timeout = 60
config.vm.provision "shell", inline: $script
config.vm.define "n1" do |n1|
n1.vm.hostname = "n1"
n1.vm.network "private_network", ip: "172.20.20.10", virtualbox__intnet: true, auto_config: true
end
config.vm.define "n2" do |n2|
n2.vm.hostname = "n2"
n2.vm.network "private_network", ip: "172.20.20.11", virtualbox__intnet: true, auto_config: true
end
config.vm.define "n3" do |n3|
n3.vm.hostname = "n3"
n3.vm.network "private_network", ip: "172.20.20.12", virtualbox__intnet: true, auto_config: true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment