For testing and development deployments, the quickest and easiest way is to set up a local cluster. For a production deployment, refer to the clustering section.

Local standalone cluster

Deploying an etcd cluster as a standalone cluster is straightforward. Start it with just one command:

  1. $ ./etcd
  2. ...

The started etcd member listens on localhost:2379 for client requests.

To interact with the started cluster by using etcdctl:

  1. # use API version 3
  2. $ export ETCDCTL_API=3
  3. $ ./etcdctl put foo bar
  4. OK
  5. $ ./etcdctl get foo
  6. bar

Local multi-member cluster

A Procfile at the base of this git repo is provided to easily set up a local multi-member cluster. To start a multi-member cluster go to the root of an etcd source tree and run:

  1. # install goreman program to control Profile-based applications.
  2. $ go get github.com/mattn/goreman
  3. $ goreman -f Procfile start
  4. ...

The started members listen on localhost:2379, localhost:22379, and localhost:32379 for client requests respectively.

To interact with the started cluster by using etcdctl:

  1. # use API version 3
  2. $ export ETCDCTL_API=3
  3. $ etcdctl --write-out=table --endpoints=localhost:2379 member list
  4. +------------------+---------+--------+------------------------+------------------------+
  5. | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS |
  6. +------------------+---------+--------+------------------------+------------------------+
  7. | 8211f1d0f64f3269 | started | infra1 | http://127.0.0.1:2380 | http://127.0.0.1:2379 |
  8. | 91bc3c398fb3c146 | started | infra2 | http://127.0.0.1:22380 | http://127.0.0.1:22379 |
  9. | fd422379fda50e48 | started | infra3 | http://127.0.0.1:32380 | http://127.0.0.1:32379 |
  10. +------------------+---------+--------+------------------------+------------------------+
  11. $ etcdctl put foo bar
  12. OK

To exercise etcd’s fault tolerance, kill a member:

  1. # kill etcd2
  2. $ goreman run stop etcd2
  3. $ etcdctl put key hello
  4. OK
  5. $ etcdctl get key
  6. hello
  7. # try to get key from the killed member
  8. $ etcdctl --endpoints=localhost:22379 get key
  9. 2016/04/18 23:07:35 grpc: Conn.resetTransport failed to create client transport: connection error: desc = "transport: dial tcp 127.0.0.1:22379: getsockopt: connection refused"; Reconnecting to "localhost:22379"
  10. Error: grpc: timed out trying to connect
  11. # restart the killed member
  12. $ goreman run restart etcd2
  13. # get the key from restarted member
  14. $ etcdctl --endpoints=localhost:22379 get key
  15. hello

To learn more about interacting with etcd, read interacting with etcd section.