-
-
Save dliappis/49c435e7bca8413654c5856e72a3f7f6 to your computer and use it in GitHub Desktop.
Vagrantfile to test ES cluster across VMs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
require "ipaddr" | |
boxname = "elastic/ubuntu-16.04-x86_64" | |
base_ip = "192.168.124.101" | |
domain_name = "example.com" | |
default_cpu = 2 | |
default_ram = 3096 | |
default_nodes = 2 | |
nodes = [] | |
for i in 1..default_nodes | |
nodes += [{ hostname: "m%02d" % [i], domain: domain_name, autostart: true }] | |
end | |
$install_docker_script = <<EOF | |
# Install and configure Docker | |
groups vagrant | grep -q docker >/dev/null 2>&1 || ( \ | |
apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* && \ | |
apt-get update && \ | |
apt-get install -y apt-transport-https ca-certificates curl software-properties-common && \ | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && \ | |
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \ | |
apt-get update && \ | |
apt-get install -y docker-ce && \ | |
usermod -aG docker vagrant \ | |
) | |
# Use overlay2 storage driver due to https://bugs.launchpad.net/ubuntu/+source/aufs-tools/+bug/1442892 | |
CURRENT_DOCKER_STORAGE_DRIVER=$( docker info -f "{{ json .Driver}}" | sed 's/\"//g' ) | |
if [[ $CURRENT_DOCKER_STORAGE_DRIVER == "aufs" ]]; then | |
systemctl stop docker | |
echo '{"storage-driver": "overlay2"}' >/etc/docker/daemon.json | |
systemctl start docker | |
fi | |
# Install Docker Compose | |
docker-compose --version >/dev/null 2>&1 || ( \ | |
apt-get install -y python-pip && \ | |
pip install --upgrade pip && \ | |
pip install docker-compose \ | |
) | |
# Tweak sysctl so ES will start. | |
grep -q '^vm.max_map_count=' /etc/sysctl.conf || ( \ | |
echo 'vm.max_map_count=262144' >> /etc/sysctl.conf && \ | |
sysctl --load | |
) | |
cat >elasticsearch.yml <<EOF2 | |
xpack.security.enabled: false | |
cluster.name: "docker-cluster" | |
network.host: 0.0.0.0 | |
discovery.zen.minimum_master_nodes: 1 | |
bootstrap.memory_lock: true | |
EOF2 | |
EOF | |
Vagrant.configure("2") do |config| | |
ip_address = IPAddr.new base_ip | |
config.vm.provision 'shell', inline: <<-EOF | |
apt-get clean | |
rm -rf /var/lib/apt/lists/* | |
EOF | |
nodes.each do |node| | |
fqdn = node[:hostname] + '.' + node[:domain] | |
config.vm.define node[:hostname], autostart: (node[:autostart] || false) do |node_config| | |
node_config.vm.box = node[:box] || boxname | |
node_config.vm.hostname = fqdn | |
node_config.ssh.forward_agent = true | |
node_config.vm.network :private_network, ip: ip_address.to_s | |
node_config.vm.provider :virtualbox do |virtualbox, override| | |
virtualbox.name = fqdn | |
virtualbox.memory = node[:memory] || default_ram | |
virtualbox.cpus = node[:cpu] || default_cpu | |
override.vm.synced_folder "./","/vagrant" | |
end | |
config.vm.provision "shell", inline: $install_docker_script | |
# Increment to ip_address+1 | |
ip_address = ip_address.succ | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment