Skip to content

Instantly share code, notes, and snippets.

@digital-wonderland
Last active January 7, 2016 03:15
Show Gist options
  • Save digital-wonderland/eaad2c2e76e0b898b606 to your computer and use it in GitHub Desktop.
Save digital-wonderland/eaad2c2e76e0b898b606 to your computer and use it in GitHub Desktop.
Vagrant & cloud-config files to reproduce coreos#1794
#cloud-config
coreos:
etcd:
# name: M4_ETCD_NAME
discovery: https://discovery.etcd.io/57ad4204c6bc25fadc67d49bf26a21aa
addr: $public_ipv4:4001
peer-addr: $private_ipv4:7001
# https://coreos.com/docs/cluster-management/debugging/etcd-tuning/
peer-heartbeat-interval: 100
peer-election-timeout: 500
fleet:
public-ip: $public_ipv4
metadata: "ID=1"
update:
reboot-strategy: best-effort
group: alpha
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both
[Install]
WantedBy=sockets.target
#include(`logstash.m4')
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Data Volume
After=docker.service
Requires=docker.service
Before=elasticsearch@%i.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "docker inspect %p-%i >/dev/null 2>&1 || docker run --name %p-%i -v /var/lib/elasticsearch busybox chmod -R 0777 /var/lib/elasticsearch"
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Discovery Service
After=etcd.service
Requires=etcd.service
Before=elasticsearch@%i.service
BindsTo=elasticsearch@%i.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c '\
while true; do \
etcdctl set /services/elasticsearch/${COREOS_PRIVATE_IPV4} \'{"http_port": 9200, "transport_port": 9300}\' --ttl 60; \
sleep 45; \
done'
ExecStop=/usr/bin/etcdctl rm /services/elasticsearch/${COREOS_PRIVATE_IPV4}
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Service
Documentation=http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index.html
After=docker.service
Requires=docker.service
After=elasticsearch-data@%i.service
Requires=elasticsearch-data@%i.service
After=elasticsearch-discovery@%i.service
Requires=elasticsearch-discovery@%i.service
[Service]
TimeoutSec=0
Restart=always
RestartSec=1m
EnvironmentFile=/etc/environment
SuccessExitStatus=255
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/usr/bin/docker pull digitalwonderland/elasticsearch
ExecStart=/bin/bash -c '\
curl -f ${COREOS_PRIVATE_IPV4}:4001/v2/keys/services/elasticsearch; \
if [ "$?" = "0" ]; then \
UNICAST_HOSTS=$(etcdctl ls --recursive /services/elasticsearch \
| sed "s/\/services\/elasticsearch\///g" \
| sed "s/$/:9300/" \
| paste -s -d","); \
else \
UNICAST_HOSTS=""; \
fi; \
/usr/bin/docker run \
--rm \
--name %p-%i \
--publish 9200:9200 \
--publish 9300:9300 \
--volumes-from elasticsearch-data-%i \
-e ELASTICSEARCH_CLUSTER_NAME=logstash \
digitalwonderland/elasticsearch \
-Des.node.name=%p-%i \
-Des.network.publish_host=${COREOS_PRIVATE_IPV4} \
-Des.discovery.zen.ping.multicast.enabled=false \
-Des.discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS'
ExecStop=/usr/bin/docker stop %p-%i
ExecStopPost=-/usr/bin/docker rm %p-%i
[Install]
WantedBy=multi-user.target
write_files:
- path: /etc/profile.d/alias.sh
content: |
alias l='ls -la'
alias ll='ls -lah'
alias d='docker'
alias ds='docker ps'
alias dsa='docker ps -a'
alias di='docker images'
alias dl='docker logs'
alias dlf='docker logs -f'
alias drm='docker rm -f'
alias drmi='docker rmi'
alias sd='sudo systemctl'
alias cci='sudo coreos-cloudinit --from-file'
alias j='journalctl'
function nsa { sudo nsenter -p -u -m -i -n -t $(docker inspect -f '{{ .State.Pid }}' $1) ; }
users:
- name: stephan
passwd: $6$wvQGfgBI$0BWYNvLZrjhPpCa3T9uBzYp8rIVy2h9AapSlmYMvXhB0aqqQb./RhYC7RQmEstLY5Tg12v6ZnynDpyBVwA/Hh0
groups:
- core
- docker
- portage
- sudo
- systemd-journal
ssh-authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5ft6HxKoLm6KtgMQrSLUYYz7iAYNnbBA9WWpOesIfz7zdzmUZMbKSKESDAVfCr9lmsAihPHYLis+tiMOPo8fP2b3fgU+zho/G9eLzV6RKbV488WYwnDcVNDi6DTsF4/yv11mKjxFEPYpigOU14nUG8IbDyRLm04pkLaxnKuiZcwFC1riT890FcohKVWnvH29VmmTjeAjHJMKEYjz/T0j2lDvj34fuS6fZhpg9WSXUbqpyg1Jxuhh7KJIwAxmMxWQnmnxk9KqnHcDhh/xD/ziNXrv8HFPQ0Tf+3oI53G86Xmb7wUFi0KF+vA0qBOJch1xjA4UFAoz/rxP4sExtqjYZ
#cloud-config
coreos:
etcd:
# name: M4_ETCD_NAME
discovery: https://discovery.etcd.io/57ad4204c6bc25fadc67d49bf26a21aa
addr: $public_ipv4:4001
peer-addr: $private_ipv4:7001
# https://coreos.com/docs/cluster-management/debugging/etcd-tuning/
peer-heartbeat-interval: 100
peer-election-timeout: 500
fleet:
public-ip: $public_ipv4
metadata: "ID=2"
update:
reboot-strategy: best-effort
group: alpha
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both
[Install]
WantedBy=sockets.target
#include(`logstash.m4')
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Data Volume
After=docker.service
Requires=docker.service
Before=elasticsearch@%i.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "docker inspect %p-%i >/dev/null 2>&1 || docker run --name %p-%i -v /var/lib/elasticsearch busybox chmod -R 0777 /var/lib/elasticsearch"
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Discovery Service
After=etcd.service
Requires=etcd.service
Before=elasticsearch@%i.service
BindsTo=elasticsearch@%i.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c '\
while true; do \
etcdctl set /services/elasticsearch/${COREOS_PRIVATE_IPV4} \'{"http_port": 9200, "transport_port": 9300}\' --ttl 60; \
sleep 45; \
done'
ExecStop=/usr/bin/etcdctl rm /services/elasticsearch/${COREOS_PRIVATE_IPV4}
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Service
Documentation=http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index.html
After=docker.service
Requires=docker.service
After=elasticsearch-data@%i.service
Requires=elasticsearch-data@%i.service
After=elasticsearch-discovery@%i.service
Requires=elasticsearch-discovery@%i.service
[Service]
TimeoutSec=0
Restart=always
RestartSec=1m
EnvironmentFile=/etc/environment
SuccessExitStatus=255
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/usr/bin/docker pull digitalwonderland/elasticsearch
ExecStart=/bin/bash -c '\
curl -f ${COREOS_PRIVATE_IPV4}:4001/v2/keys/services/elasticsearch; \
if [ "$?" = "0" ]; then \
UNICAST_HOSTS=$(etcdctl ls --recursive /services/elasticsearch \
| sed "s/\/services\/elasticsearch\///g" \
| sed "s/$/:9300/" \
| paste -s -d","); \
else \
UNICAST_HOSTS=""; \
fi; \
/usr/bin/docker run \
--rm \
--name %p-%i \
--publish 9200:9200 \
--publish 9300:9300 \
--volumes-from elasticsearch-data-%i \
-e ELASTICSEARCH_CLUSTER_NAME=logstash \
digitalwonderland/elasticsearch \
-Des.node.name=%p-%i \
-Des.network.publish_host=${COREOS_PRIVATE_IPV4} \
-Des.discovery.zen.ping.multicast.enabled=false \
-Des.discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS'
ExecStop=/usr/bin/docker stop %p-%i
ExecStopPost=-/usr/bin/docker rm %p-%i
[Install]
WantedBy=multi-user.target
write_files:
- path: /etc/profile.d/alias.sh
content: |
alias l='ls -la'
alias ll='ls -lah'
alias d='docker'
alias ds='docker ps'
alias dsa='docker ps -a'
alias di='docker images'
alias dl='docker logs'
alias dlf='docker logs -f'
alias drm='docker rm -f'
alias drmi='docker rmi'
alias sd='sudo systemctl'
alias cci='sudo coreos-cloudinit --from-file'
alias j='journalctl'
function nsa { sudo nsenter -p -u -m -i -n -t $(docker inspect -f '{{ .State.Pid }}' $1) ; }
users:
- name: stephan
passwd: $6$wvQGfgBI$0BWYNvLZrjhPpCa3T9uBzYp8rIVy2h9AapSlmYMvXhB0aqqQb./RhYC7RQmEstLY5Tg12v6ZnynDpyBVwA/Hh0
groups:
- core
- docker
- portage
- sudo
- systemd-journal
ssh-authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5ft6HxKoLm6KtgMQrSLUYYz7iAYNnbBA9WWpOesIfz7zdzmUZMbKSKESDAVfCr9lmsAihPHYLis+tiMOPo8fP2b3fgU+zho/G9eLzV6RKbV488WYwnDcVNDi6DTsF4/yv11mKjxFEPYpigOU14nUG8IbDyRLm04pkLaxnKuiZcwFC1riT890FcohKVWnvH29VmmTjeAjHJMKEYjz/T0j2lDvj34fuS6fZhpg9WSXUbqpyg1Jxuhh7KJIwAxmMxWQnmnxk9KqnHcDhh/xD/ziNXrv8HFPQ0Tf+3oI53G86Xmb7wUFi0KF+vA0qBOJch1xjA4UFAoz/rxP4sExtqjYZ
#cloud-config
coreos:
etcd:
# name: M4_ETCD_NAME
discovery: https://discovery.etcd.io/57ad4204c6bc25fadc67d49bf26a21aa
addr: $public_ipv4:4001
peer-addr: $private_ipv4:7001
# https://coreos.com/docs/cluster-management/debugging/etcd-tuning/
peer-heartbeat-interval: 100
peer-election-timeout: 500
fleet:
public-ip: $public_ipv4
metadata: "ID=3"
update:
reboot-strategy: best-effort
group: alpha
units:
- name: etcd.service
command: start
- name: fleet.service
command: start
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both
[Install]
WantedBy=sockets.target
#include(`logstash.m4')
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Data Volume
After=docker.service
Requires=docker.service
Before=elasticsearch@%i.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "docker inspect %p-%i >/dev/null 2>&1 || docker run --name %p-%i -v /var/lib/elasticsearch busybox chmod -R 0777 /var/lib/elasticsearch"
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Discovery Service
After=etcd.service
Requires=etcd.service
Before=elasticsearch@%i.service
BindsTo=elasticsearch@%i.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c '\
while true; do \
etcdctl set /services/elasticsearch/${COREOS_PRIVATE_IPV4} \'{"http_port": 9200, "transport_port": 9300}\' --ttl 60; \
sleep 45; \
done'
ExecStop=/usr/bin/etcdctl rm /services/elasticsearch/${COREOS_PRIVATE_IPV4}
- name: [email protected]
command: start
enable: true
content: |
[Unit]
Description=Elasticsearch Service
Documentation=http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index.html
After=docker.service
Requires=docker.service
After=elasticsearch-data@%i.service
Requires=elasticsearch-data@%i.service
After=elasticsearch-discovery@%i.service
Requires=elasticsearch-discovery@%i.service
[Service]
TimeoutSec=0
Restart=always
RestartSec=1m
EnvironmentFile=/etc/environment
SuccessExitStatus=255
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=/usr/bin/docker pull digitalwonderland/elasticsearch
ExecStart=/bin/bash -c '\
curl -f ${COREOS_PRIVATE_IPV4}:4001/v2/keys/services/elasticsearch; \
if [ "$?" = "0" ]; then \
UNICAST_HOSTS=$(etcdctl ls --recursive /services/elasticsearch \
| sed "s/\/services\/elasticsearch\///g" \
| sed "s/$/:9300/" \
| paste -s -d","); \
else \
UNICAST_HOSTS=""; \
fi; \
/usr/bin/docker run \
--rm \
--name %p-%i \
--publish 9200:9200 \
--publish 9300:9300 \
--volumes-from elasticsearch-data-%i \
-e ELASTICSEARCH_CLUSTER_NAME=logstash \
digitalwonderland/elasticsearch \
-Des.node.name=%p-%i \
-Des.network.publish_host=${COREOS_PRIVATE_IPV4} \
-Des.discovery.zen.ping.multicast.enabled=false \
-Des.discovery.zen.ping.unicast.hosts=$UNICAST_HOSTS'
ExecStop=/usr/bin/docker stop %p-%i
ExecStopPost=-/usr/bin/docker rm %p-%i
[Install]
WantedBy=multi-user.target
write_files:
- path: /etc/profile.d/alias.sh
content: |
alias l='ls -la'
alias ll='ls -lah'
alias d='docker'
alias ds='docker ps'
alias dsa='docker ps -a'
alias di='docker images'
alias dl='docker logs'
alias dlf='docker logs -f'
alias drm='docker rm -f'
alias drmi='docker rmi'
alias sd='sudo systemctl'
alias cci='sudo coreos-cloudinit --from-file'
alias j='journalctl'
function nsa { sudo nsenter -p -u -m -i -n -t $(docker inspect -f '{{ .State.Pid }}' $1) ; }
users:
- name: stephan
passwd: $6$wvQGfgBI$0BWYNvLZrjhPpCa3T9uBzYp8rIVy2h9AapSlmYMvXhB0aqqQb./RhYC7RQmEstLY5Tg12v6ZnynDpyBVwA/Hh0
groups:
- core
- docker
- portage
- sudo
- systemd-journal
ssh-authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5ft6HxKoLm6KtgMQrSLUYYz7iAYNnbBA9WWpOesIfz7zdzmUZMbKSKESDAVfCr9lmsAihPHYLis+tiMOPo8fP2b3fgU+zho/G9eLzV6RKbV488WYwnDcVNDi6DTsF4/yv11mKjxFEPYpigOU14nUG8IbDyRLm04pkLaxnKuiZcwFC1riT890FcohKVWnvH29VmmTjeAjHJMKEYjz/T0j2lDvj34fuS6fZhpg9WSXUbqpyg1Jxuhh7KJIwAxmMxWQnmnxk9KqnHcDhh/xD/ziNXrv8HFPQ0Tf+3oI53G86Xmb7wUFi0KF+vA0qBOJch1xjA4UFAoz/rxP4sExtqjYZ
# coreos-vagrant is configured through a series of configuration
# options (global ruby variables) which are detailed below. To modify
# these options, first copy this file to "config.rb". Then simply
# uncomment the necessary lines, leaving the $, and replace everything
# after the equals sign..
# Size of the CoreOS cluster created by Vagrant
$num_instances=3
# Official CoreOS channel from which updates should be downloaded
#$update_channel='alpha'
# Log the serial consoles of CoreOS VMs to log/
# Enable by setting value to true, disable with false
# WARNING: Serial logging is known to result in extremely high CPU usage with
# VirtualBox, so should only be used in debugging situations
#$enable_serial_logging=false
# Enable port forwarding of Docker TCP socket
# Set to the TCP port you want exposed on the *host* machine, default is 2375
# If 2375 is used, Vagrant will auto-increment (e.g. in the case of $num_instances > 1)
# You can then use the docker tool locally by setting the following env var:
# export DOCKER_HOST='tcp://127.0.0.1:2375'
$expose_docker_tcp=2375
# Setting for VirtualBox VMs
#$vb_gui = false
$vb_memory = 2048
$vb_cpus = 2
# -*- mode: ruby -*-
# # vi: set ft=ruby :
require 'fileutils'
Vagrant.require_version ">= 1.6.0"
CONFIG = File.join(File.dirname(__FILE__), "config.rb")
# Defaults for config options defined in CONFIG
$num_instances = 1
$update_channel = "alpha"
$enable_serial_logging = false
$vb_gui = false
$vb_memory = 1024
$vb_cpus = 1
# Attempt to apply the deprecated environment variable NUM_INSTANCES to
# $num_instances while allowing config.rb to override it
if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"]
$num_instances = ENV["NUM_INSTANCES"].to_i
end
if File.exist?(CONFIG)
require CONFIG
end
Vagrant.configure("2") do |config|
config.vm.box = "coreos-%s" % $update_channel
config.vm.box_version = ">= 308.0.1"
config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $update_channel
config.vm.provider :vmware_fusion do |vb, override|
override.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant_vmware_fusion.json" % $update_channel
end
config.vm.provider :virtualbox do |v|
# On VirtualBox, we don't have guest additions or a functional vboxsf
# in CoreOS, so tell Vagrant that so it can be smarter.
v.check_guest_additions = false
v.functional_vboxsf = false
end
# plugin conflict
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
(1..$num_instances).each do |i|
config.vm.define vm_name = "core-%02d" % i do |config|
config.vm.hostname = vm_name
if $enable_serial_logging
logdir = File.join(File.dirname(__FILE__), "log")
FileUtils.mkdir_p(logdir)
serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
FileUtils.touch(serialFile)
config.vm.provider :vmware_fusion do |v, override|
v.vmx["serial0.present"] = "TRUE"
v.vmx["serial0.fileType"] = "file"
v.vmx["serial0.fileName"] = serialFile
v.vmx["serial0.tryNoRxLoss"] = "FALSE"
end
config.vm.provider :virtualbox do |vb, override|
vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
vb.customize ["modifyvm", :id, "--uartmode1", serialFile]
end
end
if $expose_docker_tcp
config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
end
config.vm.network "forwarded_port", guest: 4001, host: (4001 + i - 1), auto_correct: true
config.vm.network "forwarded_port", guest: 8080, host: (8080 + i - 1), auto_correct: true
config.vm.network "forwarded_port", guest: 9200, host: (9200 + i - 1), auto_correct: true
config.vm.provider :vmware_fusion do |vb|
vb.gui = $vb_gui
end
config.vm.provider :virtualbox do |vb|
vb.gui = $vb_gui
vb.memory = $vb_memory
vb.cpus = $vb_cpus
end
ip = "172.17.8.#{i+100}"
config.vm.network :private_network, ip: ip
# Uncomment below to enable NFS for sharing the host machine into the coreos-vagrant VM.
config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "cloud-config-%d.yaml" % i)
if File.exist?(CLOUD_CONFIG_PATH)
config.vm.provision :file, :source => "#{CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data"
config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment