Skip to content

Instantly share code, notes, and snippets.

@zapman449
Created February 15, 2015 15:32
Show Gist options
  • Save zapman449/72f4040b6bed202b20e9 to your computer and use it in GitHub Desktop.
Save zapman449/72f4040b6bed202b20e9 to your computer and use it in GitHub Desktop.
How to get etcd working with a remote cluster. (bonus points: uses vagrant, and systemd)
[Unit]
Description=etcd service
After=network.target
[Service]
Type=simple
User=vagrant
WorkingDirectory=/home/vagrant/etcd-v2.0.2-linux-amd64
ExecStart=/home/vagrant/etcd-v2.0.2-linux-amd64/etcd -name master3 -initial-advertise-peer-urls http://10.0.3.23:2380 -listen-peer-urls http://10.0.3.23:2380 -initial-cluster-token etcd-vagrant-1 -initial-cluster master1=http://10.0.3.21:2380,master2=http://10.0.3.22:2380,master3=http://10.0.3.23:2380 -initial-cluster-state new -listen-client-urls http://10.0.3.23:4001 -advertise-client-urls http://10.0.3.21:4001,http://10.0.3.22:4001,http://10.0.3.23:4001
[Install]
WantedBy=multi-user.target
That execstart line is a little involved. Changes between each cluster node:
change '-name master3' to be the name of this host in the cluster, as specified by the following '-initial-cluster' statement.
change -listen-peer-urls to the IP of this host in the cluster.
change '-listen-client-urls' to reference the IP of this host in the cluster.
You also may need to change the WorkingDirectory, and the path to the etcd binary.
Other steps are as documented elsewhere. Per https://github.com/coreos/etcd/releases/ run this on all nodes to download:
curl -L https://github.com/coreos/etcd/releases/download/v2.0.2/etcd-v2.0.2-linux-amd64.tar.gz -o etcd-v2.0.2-linux-amd64.tar.gz
tar xzvf etcd-v2.0.2-linux-amd64.tar.gz
cd etcd-v2.0.2-linux-amd64
drop the etcd.service file in /etc/systemd/system on the three masters (modified for each master)
Then you can run:
./etcdctl --peers 10.0.3.21:4001,10.0.3.22:4001,10.0.3.23:4001 ls / -recursive
Now you can play with etcd.
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "master1" do |master1|
master1.vm.box = "matyunin/centos7"
master1.vm.network "private_network", ip: "10.0.3.21", virtualbox__intnet: true
end
config.vm.define "master2" do |master2|
master2.vm.box = "matyunin/centos7"
master2.vm.network "private_network", ip: "10.0.3.22", virtualbox__intnet: true
end
config.vm.define "master3" do |master3|
master3.vm.box = "matyunin/centos7"
master3.vm.network "private_network", ip: "10.0.3.23", virtualbox__intnet: true
end
config.vm.define "client1" do |client1|
client1.vm.box = "matyunin/centos7"
client1.vm.network "private_network", ip: "10.0.3.31", virtualbox__intnet: true
end
config.vm.provider "virtualbox" do |vb|
vb.gui = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment