-
Notifications
You must be signed in to change notification settings - Fork 37
/
Vagrantfile
117 lines (96 loc) · 3.58 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrant Cassandra Project
# https://github.com/bcantoni/vagrant-cassandra
# Brian Cantoni
# This template sets up one or more VMs with DataStax Enterprise (DSE) installed.
# Set these environment variables before running `vagrant up`:
# Optional:
# DEB_CACHE_HOST = Debian package cache, e.g. "http://192.168.1.100:8000" (default: no cache)
# Adjustable settings
CFG_MEMSIZE = "3000" # max memory for each VM
CFG_TZ = "US/Pacific" # timezone, like US/Pacific, US/Eastern, UTC, Europe/Warsaw, etc.
NETWORK = '10.10.10.' # base IP for DSE nodes
FIRST_IP = 10
# number of nodes to create
DSE_NODES = 3
# if local Debian proxy configured (DEB_CACHE_HOST), install and configure the proxy client
deb_cache_cmds = ""
if ENV['DEB_CACHE_HOST']
deb_cache_host = ENV['DEB_CACHE_HOST']
deb_cache_cmds = <<CACHE
apt-get install squid-deb-proxy-client -y
echo 'Acquire::http::Proxy "#{deb_cache_host}";' | sudo tee /etc/apt/apt.conf.d/30autoproxy
echo "Acquire::http::Proxy { debian.datastax.com DIRECT; };" | sudo tee -a /etc/apt/apt.conf.d/30autoproxy
echo "Acquire::http::Proxy { ppa.launchpad.net DIRECT; };" | sudo tee -a /etc/apt/apt.conf.d/30autoproxy
cat /etc/apt/apt.conf.d/30autoproxy
CACHE
end
# Provisioning script for DSE nodes (dse0, dse1, ...)
# todo: better dynamic generation of /etc/hosts list
node_script = <<SCRIPT
#!/bin/bash
cat > /etc/hosts <<EOF
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.10.10.10 dse0
10.10.10.11 dse1
10.10.10.12 dse2
10.10.10.13 dse3
10.10.10.14 dse4
10.10.10.15 dse5
EOF
# set timezone
echo "#{CFG_TZ}" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
#{deb_cache_cmds}
# configure repositories
add-apt-repository ppa:openjdk-r/ppa
echo "deb http://debian.datastax.com/enterprise stable main" | sudo tee -a /etc/apt/sources.list.d/datastax.sources.list
wget -q -O - http://debian.datastax.com/debian/repo_key | sudo apt-key add -
apt-get update
# install DSE, Java, and a few base packages
apt-get install vim curl zip unzip git python-pip openjdk-8-jdk dse-full -y
# configure DSE
echo "Configuring DataStax Enterprise"
sudo sed -i 's/- seeds:.*$/- seeds: dse0/' /etc/dse/cassandra/cassandra.yaml
sudo sed -i 's/listen_address:.*$/listen_address: %s/' /etc/dse/cassandra/cassandra.yaml
sudo sed -i 's/rpc_address:.*$/rpc_address: %s/' /etc/dse/cassandra/cassandra.yaml
# start DSE
echo "Starting DataStax Enterprise"
sudo service dse start
echo "Vagrant provisioning complete"
SCRIPT
# Configure VM servers
puts "Configured for #{DSE_NODES} DSE node(s)"
servers = []
(0..DSE_NODES-1).each do |i|
name = 'dse' + i.to_s
ip = NETWORK + (FIRST_IP + i).to_s
servers << {'name' => name, 'ip' => ip}
end
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/xenial64"
servers.each do |server|
config.vm.define server['name'] do |config2|
config2.vm.hostname = server['name']
server_ip = server['ip']
config2.vm.network :private_network, ip: server_ip
config2.vm.provision :shell, :inline => node_script % [server_ip, server_ip]
config2.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = CFG_MEMSIZE
end
config2.vm.provider :virtualbox do |v|
v.name = server['name']
v.customize ["modifyvm", :id, "--memory", CFG_MEMSIZE]
v.customize ["modifyvm", :id, "--cpus" , "2" ]
end
end
end
end