Update README, fix Consul datacenter

Remove reference to non-default data center name in Consul config
file. Update README.md with new instructions.
This commit is contained in:
Scott Lowe 2015-03-04 13:59:18 -07:00
parent 7ee558a730
commit 0937a73e12
2 changed files with 23 additions and 25 deletions

View file

@ -1,57 +1,55 @@
# Running a Consul Cluster in Vagrant
# Running a Consul-Backed Docker Swarm Cluster in Vagrant
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) quickly and relatively easily spin up a Consul ([http://www.consul.io](http://www.consul.io)) cluster. The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin.
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) quickly and relatively easily spin up a Docker Swarm (URL) cluster backed by Consul ([http://www.consul.io](http://www.consul.io)). The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin.
## Contents
* **boostrap.json**: This Consul configuration file contains configuration directives to bootstrap the Consul cluster. This file is copied to `/etc/consul.d/bootstrap/config.json` by the Vagrant file provisioner. You should not need to edit this file.
* **consul.conf**: This Upstart script is used to start the Consul agent and establish the Consul cluster. This file is copied to `/home/vagrant/consul.conf` by Vagrant's file provisioner, then moved to `/etc/init/consul.conf` by the `consul.sh` shell script called by Vagrant's shell provisioner.
* **consul.sh**: This shell script is executed by the Vagrant shell provisioner to provision the Ubuntu base box with the Consul binary. This shell script was written for an Ubuntu system; edits will likely be necessary for use with a different Linux distribution.
* **consul.sh**: This shell script is executed by the Vagrant shell provisioner to create a Consul user, create directories needed by Consul, and provision the Ubuntu base box with the Consul binary. This shell script was written for an Ubuntu system; edits will likely be necessary for use with a different Linux distribution.
* **README.md**: This file you're currently reading.
* **server.json**: This Consul configuration file contains configuration directives to run the Consul agent as a server. This file is copied to `/etc/consul.d/server/config.json` by the Vagrant file provisioner. The IP addresses specified in this file _must_ match the IP address specified in `servers.yml`.
* **server.json**: This Consul configuration file contains configuration directives to run the Consul agent as a server. This file is copied to `/home/vagrant/config.json` by Vagrant's file provisioner, then moved to `/etc/consul.d/server/config.json` by `consul.sh` when called by Vagrant's shell provisioner. The IP addresses specified on the `retry_join` line in this file _must_ match the IP address specified in `servers.yml`. If you change the IP addresses given to the VMs in `servers.yml`, you _must_ also edit this file to make sure the addresses match.
* **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). If you edit the IP addresses in this file, you _must_ also edit `server.json` to supply matching IP addresses there as well.
* **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.
* **user_data**: This file is used by the CoreOS cloud-init process to customize the CoreOS VMs upon instantiation. This file disables etcd and fleet, and configures Docker to listen on TCP port 2375.
## 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.
1. Use `vagrant box add` to install an Ubuntu 14.04 x64 box for the vmware_fusion provider. I have a base box you can use for this purpose; to use my Ubuntu 14.04 x64 base box, add the box with `vagrant box add slowe/ubuntu-trusty-x64`.
2. Place the files from the `consul` directory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository (using `git clone`) or just download the specific files from the the `consul` folder.
2. Use `vagrant box add` to install a CoreOS base box. The `Vagrantfile` assumes you are using the Stable release of CoreOS (the box named `coreos-stable`). If the box name is different, you'll need to edit the `Vagrantfile` accordingly.
3. Edit the `servers.yml` file to provide the specific details on the VMs that Vagrant should create. The `Vagrantfile` expects five values for each VM: `name` (the user-friendly name of the VM, which will also be used as the hostname for the guest OS inside the VM); `box` (the name of an Ubuntu 14.04 base box); `ram` (the amount of memory to be assigned to the VM); `vcpu` (the number of vCPUs that should be assigned to the VM); and `priv_ip` (an IP address to be statically assigned to the VM and is used for Consul cluster communications).
3. Place the files from the `docker-swarm` directory of this GitHub repository into a directory on your local system. You can clone the entire "learning-tools" repository (using `git clone`) or just download the specific files from the the `docker-swarm` folder.
4. Once you have edited `servers.yml` (and `server.json`, if you changed the IP addresses in `servers.yml`), use `vagrant up` to bring up the 3 systems that will serve as your Consul cluster.
4. Edit the `servers.yml` file to provide the specific details on the VMs that Vagrant should create. The `Vagrantfile` expects five values for each VM: `name` (the user-friendly name of the VM, which will also be used as the hostname for the guest OS inside the VM); `box` (the name of an Ubuntu 14.04 base box); `ram` (the amount of memory to be assigned to the VM); `vcpu` (the number of vCPUs that should be assigned to the VM); and `priv_ip` (an IP address to be statically assigned to the VM and is used for Consul cluster communications).
5. Once Vagrant has finished bringing up the VMs, simply use `vagrant ssh consul-01` (where `consul-01` is the value assigned to the first VM from `servers.yml`) to connect to the VM. No password should be required; it should use the default (insecure) SSH key. Once you are logged into the first VM, bootstrap the Consul cluster with this command:
5. Once you have edited `servers.yml` (and `server.json`, if you changed the IP addresses in `servers.yml`), use `vagrant up` to bring up the 6 systems. Three VMs will run the Consul cluster; the other 3 VMs will be running CoreOS and will make up the Docker Swarm cluster.
consul agent -config-dir /etc/consul.d/bootstrap -advertise 192.168.1.101 -client 0.0.0.0
6. Once Vagrant has finished bringing up the VMs, simply use `vagrant ssh consul-01` (where `consul-01` is the value assigned to the first VM from `servers.yml`) to connect to the VM. No password should be required; it should use the default (insecure) SSH key. Once you are logged into the first VM, verify that Consul is up and running with this command:
If you changed the IP address assigned to the first VM in `servers.yml`, then substitute the appropriate address for the `-advertise` parameter in the above command.
consul members
6. In a separate terminal window, connect to the second VM using `vagrant ssh consul-02`. (If you changed the name in `servers.yml`, specify the changed name here.) Launch the second member of the Consul cluster with this command:
Consul should report three members, using the IP addresses specified in `servers.yml`. If Consul does not report three members (a minimum to bootstrap the cluster) or if it reports an error, you'll need to resolve this before continuing.
consul agent -config-dir /etc/consul.d/server -advertise 192.168.1.102 -client 0.0.0.0
7. Use `vagrant ssh coreos-01` to log into the first CoreOS system (`coreos-01` is the default name supplied in `servers.yml`; if you've changed the default name, modify your command appropriately). On this system, launch a Consul client using the following command:
Change `192.168.1.102` in the command above if you changed the IP address specified for the second VM in `servers.yml`.
docker run -d -p 8300:8300 -p 8301:8301 -p 8301:8301/udp -p 8302:8302 -p 8302:8302/udp -p 8400:8400 -p 8500:8500 -p 8600:8600/udp --name consul-coreos-01 -h coreos-01 progrium/consul -rejoin -advertise 192.168.1.104 -join 192.168.1.101
7. In yet another terminal window, connect to the third VM using `vagrant ssh consul-03` (or the name provided in `servers.yml` for the third VM). Launch the third member of the Consul cluster with this command (change the IP address to match what is provided in `servers.yml`):
If you've changed the IP addresses in `servers.yml`, be sure to modify the command above with the correct IP addresses (`-advertise` needs to specify the IP address assigned to the first CoreOS node, and `-join` needs to provide the IP address of one of the Consul nodes).
consul agent -config-dir /etc/consul.d/server -advertise 192.168.1.103 -client 0.0.0.0
8. While still logged into the first CoreOS system, launch an instance of Registrator:
8. At this point, return to the first terminal window (where you are connected to the initial Consul instance launched to bootstrap the cluster) and press Ctrl+C to kill that instance. Launch it again as a "normal" Consul instance with this command:
docker run -d --name reg-coreos-01 -h coreos-01 -v /var/run/docker.sock:/tmp/docker.sock progrium/registrator consul://192.168.1.104:8500
consul agent -config-dir /etc/consul.d/server -advertise 192.168.1.101 -client 0.0.0.0 -rejoin
9. While still logged into the first CoreOS system, add it as the first node to a new Docker Swarm cluster using this command:
Consul should re-join the other two nodes in the cluster.
docker run -d swarm join --addr=192.168.1.104:2375 consul://192.168.1.104:8500/swarm
At this point, you have a functional Consul cluster running under Vagrant. If you are using VMware Fusion, you should have IP connectivity to the VMs, and can use the OS X `consul` binary to connect to the cluster and test it. For example, this command would work to demonstrate that Consul is working (you would need to change the IP address provided after `-rpc-addr`):
consul members -rpc-addr=192.168.1.101:8400
Enjoy!
10. Log out of the first CoreOS system and use `vagrant ssh` to log into the second and third CoreOS systems, repeating steps 7, 8, and 9 on each system. Be sure to change values for the `--name` and `-h` parameters on each system. Also be sure that the `-advertise` parameter for the Consul container maps to the IP address assigned to the host CoreOS VM (as provided in `servers.yml`). Make sure the `consul://` parameter for the Registrator container points to the CoreOS VM's IP address as provided in `servers.yml` as well.

View file

@ -1,7 +1,7 @@
{
"bootstrap_expect": 3,
"server": true,
"datacenter": "den1",
"datacenter": "dc1",
"data_dir": "/var/consul",
"log_level": "INFO",
"enable_syslog": false,