From 85a9d5db2e5801d120182195b95381ceb2d2746a Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Wed, 15 Apr 2015 15:39:06 -0600 Subject: [PATCH] Initial commit Initial commit of files to use Vagrant for building etcd 2.0 cluster --- etcd-2.0/README.md | 17 ++++++++++++++++ etcd-2.0/Vagrantfile | 42 +++++++++++++++++++++++++++++++++++++++ etcd-2.0/etcd-01.override | 12 +++++++++++ etcd-2.0/etcd-02.override | 12 +++++++++++ etcd-2.0/etcd-03.override | 12 +++++++++++ etcd-2.0/etcd.conf | 19 ++++++++++++++++++ etcd-2.0/provision.sh | 24 ++++++++++++++++++++++ etcd-2.0/servers.yml | 16 +++++++++++++++ 8 files changed, 154 insertions(+) create mode 100644 etcd-2.0/README.md create mode 100644 etcd-2.0/Vagrantfile create mode 100644 etcd-2.0/etcd-01.override create mode 100644 etcd-2.0/etcd-02.override create mode 100644 etcd-2.0/etcd-03.override create mode 100644 etcd-2.0/etcd.conf create mode 100644 etcd-2.0/provision.sh create mode 100644 etcd-2.0/servers.yml diff --git a/etcd-2.0/README.md b/etcd-2.0/README.md new file mode 100644 index 0000000..11be0f6 --- /dev/null +++ b/etcd-2.0/README.md @@ -0,0 +1,17 @@ +# Running an etcd 2.0 Cluster + +These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to quickly and relatively easily spin up a cluster running etcd 2.0 (etcd 2.0.9 was the version specifically tested). The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin. + +## Contents + +* **README.md**: This file you're currently reading. + +* **servers.yml**: This YAML file contains a list of VM definitions. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. You will need to edit this file to provide appropriate IP addresses and other VM configuration data (see "Instructions" below). + +* **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file. + +## Instructions + +These instructions assume you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin. Please refer to the documentation for those products for more information on installation or configuration. + +**[NOT YET COMPLETE]** diff --git a/etcd-2.0/Vagrantfile b/etcd-2.0/Vagrantfile new file mode 100644 index 0000000..31ad978 --- /dev/null +++ b/etcd-2.0/Vagrantfile @@ -0,0 +1,42 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Specify Vagrant version and Vagrant API version +Vagrant.require_version ">= 1.6.0" +VAGRANTFILE_API_VERSION = "2" + +# Require 'yaml' module +require 'yaml' + +# Read YAML file with VM details (box, CPU, RAM, IP addresses) +# Be sure to edit servers.yml to provide correct IP addresses +servers = YAML.load_file('servers.yml') + +# Create and configure the VMs +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + # Always use Vagrant's default insecure key + config.ssh.insert_key = false + + # Iterate through entries in YAML file to create VMs + servers.each do |servers| + config.vm.define servers["name"] do |srv| + # Don't check for box updates + srv.vm.box_check_update = false + srv.vm.hostname = servers["name"] + srv.vm.box = servers["box"] + # Assign an additional static private network + srv.vm.network "private_network", ip: servers["priv_ip"] + # Specify default synced folder; requires VMware Tools + # Note shared folders are REQUIRED for the shell provisioning to work + srv.vm.synced_folder ".", "/vagrant" + # Provision etcd to the VMs + srv.vm.provision "shell", path: "provision.sh", privileged: true + # Configure VMs with RAM and CPUs per settings in servers.yml + srv.vm.provider :vmware_fusion do |vmw| + vmw.vmx["memsize"] = servers["ram"] + vmw.vmx["numvcpus"] = servers["vcpu"] + end + end + end +end \ No newline at end of file diff --git a/etcd-2.0/etcd-01.override b/etcd-2.0/etcd-01.override new file mode 100644 index 0000000..419e9be --- /dev/null +++ b/etcd-2.0/etcd-01.override @@ -0,0 +1,12 @@ +# Override file for etcd Upstart script + +# Environment variables +env ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.101.101:2380,etcd-02=http://192.168.101.102:2380,etcd-03=http://192.168.101.103:2380" +env ETCD_INITIAL_CLUSTER_STATE="new" +env ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01" +env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.101.101:2380" +env ETCD_DATA_DIR="/var/etcd" +env ETCD_LISTEN_PEER_URLS="http://192.168.101.101:2380" +env ETCD_LISTEN_CLIENT_URLS="http://192.168.101.101:2379" +env ETCD_ADVERTISE_CLIENT_URLS="http://192.168.101.101:2379" +env ETCD_NAME="etcd-01" diff --git a/etcd-2.0/etcd-02.override b/etcd-2.0/etcd-02.override new file mode 100644 index 0000000..b83f2f0 --- /dev/null +++ b/etcd-2.0/etcd-02.override @@ -0,0 +1,12 @@ +# Override file for etcd Upstart script + +# Environment variables +env ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.101.101:2380,etcd-02=http://192.168.101.102:2380,etcd-03=http://192.168.101.103:2380" +env ETCD_INITIAL_CLUSTER_STATE="new" +env ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01" +env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.101.102:2380" +env ETCD_DATA_DIR="/var/etcd" +env ETCD_LISTEN_PEER_URLS="http://192.168.101.102:2380" +env ETCD_LISTEN_CLIENT_URLS="http://192.168.101.102:2379" +env ETCD_ADVERTISE_CLIENT_URLS="http://192.168.101.102:2379" +env ETCD_NAME="etcd-02" diff --git a/etcd-2.0/etcd-03.override b/etcd-2.0/etcd-03.override new file mode 100644 index 0000000..d92dbc2 --- /dev/null +++ b/etcd-2.0/etcd-03.override @@ -0,0 +1,12 @@ +# Override file for etcd Upstart script + +# Environment variables +env ETCD_INITIAL_CLUSTER="etcd-01=http://192.168.101.101:2380,etcd-02=http://192.168.101.102:2380,etcd-03=http://192.168.101.103:2380" +env ETCD_INITIAL_CLUSTER_STATE="new" +env ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01" +env ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.101.103:2380" +env ETCD_DATA_DIR="/var/etcd" +env ETCD_LISTEN_PEER_URLS="http://192.168.101.103:2380" +env ETCD_LISTEN_CLIENT_URLS="http://192.168.101.103:2379" +env ETCD_ADVERTISE_CLIENT_URLS="http://192.168.101.103:2379" +env ETCD_NAME="etcd-03" diff --git a/etcd-2.0/etcd.conf b/etcd-2.0/etcd.conf new file mode 100644 index 0000000..c3cf582 --- /dev/null +++ b/etcd-2.0/etcd.conf @@ -0,0 +1,19 @@ +description "etcd 2.0 distributed key-value store" +author "Scott Lowe " + +start on (net-device-up + and local-filesystems + and runlevel [2345]) +stop on runlevel [016] + +respawn +respawn limit 10 5 + +script + if [ -f "/etc/default/etcd" ]; then + . /etc/default/etcd + fi + +chdir /var/etcd +exec /usr/local/bin/etcd >>/var/log/etcd.log 2>&1 +end script \ No newline at end of file diff --git a/etcd-2.0/provision.sh b/etcd-2.0/provision.sh new file mode 100644 index 0000000..1f6e029 --- /dev/null +++ b/etcd-2.0/provision.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Get etcd download +curl -L https://github.com/coreos/etcd/releases/download/v2.0.9/etcd-v2.0.9-linux-amd64.tar.gz -o etcd-v2.0.9-linux-amd64.tar.gz + +# Expand the download +tar xzvf etcd-v2.0.9-linux-amd64.tar.gz + +# Move etcd and etcdctl to /usr/local/bin +cd etcd-v2.0.9-linux-amd64 +sudo mv etcd /usr/local/bin/ +sudo mv etcdctl /usr/local/bin/ +cd .. + +# Remove etcd download and directory +rm etcd-v2.0.9-linux-amd64.tar.gz +rm -rf etcd-v2.0.9-linux-amd64 + +# Create directories needed by etcd +sudo mkdir /var/etcd + +# Copy files into the correct locations; requires shared folders +sudo cp /vagrant/etcd.conf /etc/init/etcd.conf +sudo cp /vagrant/$HOSTNAME.override /etc/init/etcd.override diff --git a/etcd-2.0/servers.yml b/etcd-2.0/servers.yml new file mode 100644 index 0000000..26b89e6 --- /dev/null +++ b/etcd-2.0/servers.yml @@ -0,0 +1,16 @@ +--- +- name: etcd-01 + box: slowe/ubuntu-trusty-x64 + ram: 512 + vcpu: 1 + priv_ip: 192.168.101.101 +- name: etcd-02 + box: slowe/ubuntu-trusty-x64 + ram: 512 + vcpu: 1 + priv_ip: 192.168.101.102 +- name: etcd-03 + box: slowe/ubuntu-trusty-x64 + ram: 512 + vcpu: 1 + priv_ip: 192.168.101.103