Docker | etcd

etcd

etcdCoreOS团队发起的一个管理配置信息和服务发现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项目包括基于gRPCGo client和命令行工具etcdctl,通过gRPCetcd集群通讯

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。