etcd
etcd
是CoreOS
团队发起的一个管理配置信息和服务发现service discovery
的项目
Distributed reliable key-value store for the most critical data of a distributed system
ETCD_VER=v3.1.0-rc.1
DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download
curl \
-L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz \
-o /opt/etcd-${ETCD_VER}-linux-amd64.tar.gz
mkdir -p /opt/test-etcd && \
tar xzvf /opt/etcd-${ETCD_VER}-linux-amd64.tar.gz \
-C /opt/test-etcd --strip-components=1
单机部署
echo "export ETCDCTL_API=3" >> /etc/profile ; source /etc/profile
./etcdctl version
./etcdctl put foo bar
./etcdctl get foo
本地多成员集群
echo $(GOPATH)
mkdir src ; mkdir pkg ; mkdir bin
go get github.com/mattn/goreman
cd /opt/etcd/
wget -c https://raw.githubusercontent.com/coreos/etcd/master/Procfile
mkdir bin ; cp etcd ./bin ; cp etcdctl ./bin
goreman -f Procfile start >> etcd.logs 2>&1
tail -f etcd.logs
etcdctl --write-out=table --endpoints=localhost:2379 member list
etcdctl --endpoints=localhost:2379 put foo bar
etcdctl --endpoints=localhost:2379 get foo
容错测试
kill `ps aux | grep etcd | grep 127.0.0.1:22379 | awk '{print $2}'`
etcdctl --endpoints=localhost:2379 put key hello
etcdctl --endpoints=localhost:2379 get key
etcdctl --endpoints=localhost:22379 get key
goreman run restart etcd2
etcdctl --endpoints=localhost:22379 get key
etcd 交互
etcdctl --endpoints=localhost:2379 put foo bar
etcdctl --endpoints=localhost:2379 get foo
etcdctl --endpoints=localhost:2379 get foo foo9
etcdctl --endpoints=localhost:2379 --rev=4 get foo foo9
etcdctl --endpoints=localhost:2379 --rev=3 get foo foo9
etcdctl --endpoints=localhost:2379 del foo
etcdctl --endpoints=localhost:2379 del foo foo9
etcdctl --endpoints=localhost:2379 watch foo
etcdctl --endpoints=localhost:2379 watch foo foo9
etcdctl --endpoints=localhost:2379 --rev=2 watch foo
etcdctl --endpoints=localhost:2379 compact 5
etcdctl --endpoints=localhost:2379 lease grant 10
etcdctl --endpoints=localhost:2379 put --lease=32695410dcc0ca06 foo bar
etcdctl --endpoints=localhost:2379 lease revoke 32695410dcc0ca06
etcdctl --endpoints=localhost:2379 lease keep-alive 32695410dcc0ca0
gRPC 网关
etcd v3
使用gRPC
作为它的消息协议,etcd
项目包括基于gRPC
的Go client
和命令行工具etcdctl
,通过gRPC
和etcd
集群通讯