搭建本地集群
本地独立集群
$ ./etcd
...# 使用 API 版本 3
$ export ETCDCTL_API=3
$ ./etcdctl put foo bar
OK
$ ./etcdctl get foo
bar本地多成员集群
Last updated
$ ./etcd
...# 使用 API 版本 3
$ export ETCDCTL_API=3
$ ./etcdctl put foo bar
OK
$ ./etcdctl get foo
barLast updated
# 安装 goreman 程序来控制基于 Profile 的应用程序.
$ go get github.com/mattn/goreman
$ goreman -f Procfile start
...# 使用 API 版本 3
$ export ETCDCTL_API=3
$ etcdctl --write-out=table --endpoints=localhost:12379 member list
+------------------+---------+--------+------------------------+------------------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS |
+------------------+---------+--------+------------------------+------------------------+
| 8211f1d0f64f3269 | started | infra1 | http://127.0.0.1:12380 | http://127.0.0.1:12379 |
| 91bc3c398fb3c146 | started | infra2 | http://127.0.0.1:22380 | http://127.0.0.1:22379 |
| fd422379fda50e48 | started | infra3 | http://127.0.0.1:32380 | http://127.0.0.1:32379 |
+------------------+---------+--------+------------------------+------------------------+
$ etcdctl --endpoints=localhost:12379 put foo bar
OK# 杀掉 etcd2
$ goreman run stop etcd2
# 注:实测这个命令无法停止etcd,最后还是用ps命令找出pid,然后kill
# ps -ef | grep etcd | grep 127.0.0.1:22379
# kill ****
$ etcdctl --endpoints=localhost:12379 put key hello
OK
$ etcdctl --endpoints=localhost:12379 get key
hello
# 试图从被杀掉的成员获取key
$ etcdctl --endpoints=localhost:22379 get key
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"
Error: grpc: timed out trying to connect
# 重启被杀掉的成员
# 注:实测这个restart命令可用
$ goreman run restart etcd2
# 从重启的成员获取key
$ etcdctl --endpoints=localhost:22379 get key
hello