From e34349e5498ccfaed1c509453551857a0c137513 Mon Sep 17 00:00:00 2001 From: Mateusz Korszun Date: Thu, 26 Mar 2015 19:15:49 +0100 Subject: [PATCH] Introduce vagrant env --- .gitignore | 4 ++++ README.md | 16 ++++++++++++++++ Vagrantfile | 28 ++++++++++++++++++++++++++++ setup.sh | 20 ++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 Vagrantfile create mode 100755 setup.sh diff --git a/.gitignore b/.gitignore index 094a9473..8e2f371b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ # Folders _obj _test +.vagrant + +# Logs +*.log # Temporary vim files *.swp diff --git a/README.md b/README.md index 707c7f97..29ed421f 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,22 @@ This starts a rqlite server listening on localhost, port 4001. This single node $GOPATH/bin/rqlite -h +Alternatively you can use [Vagrant](https://www.vagrantup.com/) environment. To do so, simply [install Vagrant](https://docs.vagrantup.com/v2/installation/index.html) on your machine and execute being inside rqlite repository: + +~~~bash +$ CLUSTER_SIZE=7 vagrant up rqlite +~~~ + +This will start Vagrant box and install rqlite with all required dependencies. After this is done, there will be formed a cluster with number of nodes specifed by `CLUSTER_SIZE` variable. + +To execute queries against started cluster you can either ssh directly to the Vagrant box via `vagrant ssh rqlite` or execute them from you local box accessing cluster at `192.168.200.10` IP and any port within a range `[4001, 4001 + CLUSTER_SIZE -1]`. + +To terminate Vagrant box simply execute: + +~~~bash +$ vagrant destroy rqlite +~~~ + ### Forming a Cluster While not strictly necessary to run rqlite, running multiple nodes means the SQLite database is replicated. diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..4bcf1247 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,28 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +VAGRANTFILE_API_VERSION = "2" + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = "ubuntu/trusty64" + + config.vm.define "rqlite" do |rqlite| + config.vm.network "private_network", ip: "192.168.200.10" + config.vm.provision :shell, :path => "setup.sh" + config.vm.provision :shell, :inline => "rqlite -logfile /vagrant/rqlite1.log ~/node.1 &" + + if not ENV['CLUSTER_SIZE'].nil? + port = 4001 + (2..ENV['CLUSTER_SIZE'].to_i).each do |i| + port = port + 1 + config.vm.provision :shell, :inline => "rqlite -join localhost:4001 -p #{port} -logfile /vagrant/rqlite#{i}.log ~/node.#{i} &" + end + end + + end + + config.vm.provider :virtualbox do |vb| + vb.customize ["modifyvm", :id, "--memory", "2048"] + end + +end diff --git a/setup.sh b/setup.sh new file mode 100755 index 00000000..76c24336 --- /dev/null +++ b/setup.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Dependencies +add-apt-repository ppa:git-core/ppa -y +echo "Updating..." +apt-get update +apt-get install -y curl git bison make mercurial sqlite3 + +# Golang +bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) +source ~/.gvm/scripts/gvm +gvm install go1.4 +gvm use go1.4 + +# Rqlite +mkdir -p rqlite +cd rqlite +export GOPATH=$PWD +go get github.com/otoolep/rqlite +ln -s $GOPATH/bin/rqlite /usr/local/bin/rqlite