mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
commit
4dacf840ed
8 changed files with 63 additions and 63 deletions
2
etcd-2.0/.gitignore
vendored
Normal file
2
etcd-2.0/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.vagrant
|
||||
*.defaults
|
||||
|
|
@ -6,9 +6,9 @@ These files were created to allow users to use Vagrant ([http://www.vagrantup.co
|
|||
|
||||
* **etcd.conf**: This is an Upstart script (written for Ubuntu) to start etcd. No modifications to this file should be necessary. This file is installed by the provisioning script called in `Vagrantfile`.
|
||||
|
||||
* **etcd-01.override, etcd-02.override, etcd-03.override**: These are machine-specific Upstart override files for each node in the etcd cluster. The appropriate node-specific file is installed as `etcd.override` in the `/etc/init` directory on each node by the provisioning script called in `Vagrantfile`. If you make any changes to hostnames or IP addresses in `servers.yml`, these files must also be modified so that the hostnames and IP addresses match.
|
||||
* **etcd.defaults.erb**: A template used by Vagrant to create machine-specific service defaults files for each node in the etcd cluster. The appropriate node-specific file is installed as `etcd` in the `/etc/default` directory on each node by the provisioning script called in `Vagrantfile`.
|
||||
|
||||
* **provision.sh**: This provisioning script is called by the shell provisioner in `Vagrantfile`. It downloads the etcd 2.0.9 release from GitHub, expands it, creates necessary directories, and places files in the appropriate locations.
|
||||
* **provision.sh**: This provisioning script is called by the shell provisioner in `Vagrantfile`. It downloads the etcd 2.0.9 release from GitHub, expands it, creates necessary directories, and places files in the appropriate locations. Finally it starts etcd ( or restarts it if already running ).
|
||||
|
||||
* **README.md**: This file you're currently reading.
|
||||
|
||||
|
|
@ -26,17 +26,11 @@ These instructions assume you've already installed VMware Fusion, Vagrant, and t
|
|||
|
||||
3. Edit `servers.yml` to ensure that the box specified in that file matches the Ubuntu 14.04 x64 base box you just installed and will be using. _I recommend that you do not change any other values in this file unless you know it is necessary._
|
||||
|
||||
4. If you changed the hostnames or IP addresses provided in `servers.yml`, you **must** edit the Upstart override files (`etcd-01.override`, `etcd-02.override`, and `etcd-03.override`). The hostnames and IP addresses specified in these files are based on the values provided in `servers.yml`. If you changed the values in `servers.yml`, change the values in these files to match.
|
||||
4. From a terminal window, change into the directory where the files from this directory are stored and run `vagrant up` to bring up the VMs specified in `servers.yml` and `Vagrantfile`.
|
||||
|
||||
5. From a terminal window, change into the directory where the files from this directory are stored and run `vagrant up` to bring up the VMs specified in `servers.yml` and `Vagrantfile`.
|
||||
5. Once Vagrant has finished creating, booting, and provisioning each of the VMs and starting etcd, log into the first system ("etcd-01" by default) using `vagrant ssh etcd-01`.
|
||||
|
||||
6. Once Vagrant has finished creating, booting, and provisioning each of the VMs, log into the first system ("etcd-01" by default) using `vagrant ssh etcd-01`. Once you are logged into this VM, start etcd with this command:
|
||||
|
||||
sudo initctl start etcd
|
||||
|
||||
7. Repeat step 6 with the remaining 2 VMs ("etcd-02" and "etcd-03", by default).
|
||||
|
||||
8. Once etcd is running on all 3 VMs, you can test etcd with this command:
|
||||
6. You can test etcd with this command:
|
||||
|
||||
etcdctl member list
|
||||
|
||||
|
|
|
|||
19
etcd-2.0/Vagrantfile
vendored
19
etcd-2.0/Vagrantfile
vendored
|
|
@ -12,6 +12,23 @@ require 'yaml'
|
|||
# Be sure to edit servers.yml to provide correct IP addresses
|
||||
servers = YAML.load_file('servers.yml')
|
||||
|
||||
# Require 'erb' module
|
||||
require 'erb'
|
||||
|
||||
# Use config from YAML file to write out templates for etcd overrides
|
||||
template = File.join(File.dirname(__FILE__), 'etcd.defaults.erb')
|
||||
content = ERB.new File.new(template).read
|
||||
|
||||
etcd_initial_cluster = []
|
||||
servers.each do |servers|
|
||||
etcd_initial_cluster << "#{servers['name']}=http://#{servers['priv_ip']}:2380"
|
||||
end
|
||||
servers.each do |servers|
|
||||
ip = servers['priv_ip']
|
||||
target = File.join(File.dirname(__FILE__), "#{servers['name']}.defaults")
|
||||
File.open(target, 'w') { |f| f.write(content.result(binding)) }
|
||||
end
|
||||
|
||||
# Create and configure the VMs
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
|
|
@ -39,4 +56,4 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
# 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"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# 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"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# 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"
|
||||
12
etcd-2.0/etcd.defaults.erb
Normal file
12
etcd-2.0/etcd.defaults.erb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Override file for etcd Upstart script
|
||||
# Generated from etcd.override.erb by Vagrant
|
||||
# Environment variables
|
||||
export ETCD_INITIAL_CLUSTER="<%= etcd_initial_cluster.join(',') %>"
|
||||
export ETCD_INITIAL_CLUSTER_STATE="new"
|
||||
export ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
|
||||
export ETCD_INITIAL_ADVERTISE_PEER_URLS="http://<%= servers['priv_ip'] %>:2380"
|
||||
export ETCD_DATA_DIR="/var/etcd"
|
||||
export ETCD_LISTEN_PEER_URLS="http://<%= servers['priv_ip'] %>:2380"
|
||||
export ETCD_LISTEN_CLIENT_URLS="http://<%= servers['priv_ip'] %>:2379,http://0.0.0.0:4001"
|
||||
export ETCD_ADVERTISE_CLIENT_URLS="http://<%= servers['priv_ip'] %>:2379"
|
||||
export ETCD_NAME="<%= servers['name'] %>"
|
||||
|
|
@ -1,24 +1,35 @@
|
|||
#!/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
|
||||
# install curl if needed
|
||||
if [[ ! -e /usr/bin/curl ]]; then
|
||||
apt-get update
|
||||
apt-get -yqq install curl
|
||||
fi
|
||||
|
||||
# Expand the download
|
||||
tar xzvf etcd-v2.0.9-linux-amd64.tar.gz
|
||||
if [[ ! -e /usr/local/bin/etcd ]]; then
|
||||
# Get etcd download
|
||||
curl -sL 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
|
||||
|
||||
# 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 ..
|
||||
# Expand the download
|
||||
tar xzvf etcd-v2.0.9-linux-amd64.tar.gz
|
||||
|
||||
# Remove etcd download and directory
|
||||
rm etcd-v2.0.9-linux-amd64.tar.gz
|
||||
rm -rf etcd-v2.0.9-linux-amd64
|
||||
# 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 ..
|
||||
|
||||
# Create directories needed by etcd
|
||||
sudo mkdir /var/etcd
|
||||
# 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 -p /var/etcd
|
||||
fi
|
||||
|
||||
# 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
|
||||
sudo cp /vagrant/$HOSTNAME.defaults /etc/default/etcd
|
||||
|
||||
# restart if already running, otherwise start.
|
||||
initctl status etcd && initctl restart etcd || initctl start etcd
|
||||
|
|
|
|||
Loading…
Reference in a new issue