一、简介
:API (gRPC)
TLS
:10000
:Raft
etcdGoRaft
二、安装
1.方法1$curl -L https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz -o etcd-v3.3.2-linux-amd64.tar.gz #解压后是一些文档和两个二进制文件etcd和etcdctl。etcd是server端,etcdctl是客户端。 $tar zxf etcd-v3.3.2-linux-amd64.tar.gz #将解压后的etcd和etcdctl移动到$GOPATH/bin目录下,可以直接使用etcd和etcdctl命令 $mv etcd-v3.3.2-linux-amd64/etcd* /$GOPATH/bin
2.2$ mkdir -p $GOPATH/src/github.com/coreos $ cd !$ $ git clone https://github.com/coreos/etcd.git $ cd etcd $ ./build $ ./bin/etcd
三、启动$ ./etcd (或直接使用etcd)
etcd localhost:2379
etcdctl
# API3$ export ETCDCTL_API=3 $ ./etcdctl put foo bar OK $ ./etcdctl get foo bar
四、本地多成员集群
goreman
goremanhttps://segmentfault.com/a/1190000003778084$ go get github.com/mattn/goreman
Procfilehttps://github.com/coreos/etcd/blob/master/Procfile$ goreman -f Procfile start
注1goGo
注2ProcfileetcdgitubProcfile
bin/etcd etcd
# Use goreman to run `go get github.com/mattn/goreman` etcd1: etcd --name infra1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof etcd2: etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof etcd3: etcd --name infra3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof # in future, use proxy to listen on 2379 #proxy: bin/etcd --name infra-proxy1 --proxy=on --listen-client-urls http://127.0.0.1:2378 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --enable-pprof
$ export ETCDCTL_API=3 $ etcdctl --write-out=table --endpoints=localhost:2379 member list
$ etcdctl --endpoints=localhost:2379 put foo bar
可以从其他节点获取:$etcdctl --endpoints=localhost:22379 get foo
key$etcdctl --endpoints=localhost:22379 del foo
key value
$ goreman run stop etcd2
$ etcdctl --endpoints=localhost:2379 get foo foo bar
$ etcdctl --endpoints=localhost:22379 get foo
$ goreman run restart etcd2 $ etcdctl --endpoints=localhost:22379 get foo foo bar