etcd编译与简单使用

etcd是用go语言编写的
首先安装与配置go语言的环境
ubuntu1404安装go开发环境参考
http://xhrwang.me/2014/12/22/go-dev-env.html
http://go.ctolib.com/topics/3888.html
http://www.cnblogs.com/jytx/p/5447394.html

下载ectd源码构建

# go is required
$ go version
go version go1.6 darwin/amd64
# GOPATH should be set correctly
$ echo $GOPATH
/Users/example/go

$ mkdir -p $GOPATH/src/github.com/coreos
$ cd $GOPATH/src/github.com/coreos
$ git clone https://github.com/coreos/etcd.git
$ cd etcd
$ ./build
$ ./bin/etcd

测试安装

$ ./bin/etcd
Set a key:

$ ETCDCTL_API=3 ./bin/etcdctl put foo bar
OK

简单使用

export ETCDCTL_API=3

$ ./bin/etcdctl put foo bar
$ ./bin/etcdctl get foo
$ ./bin/etcdctl get foo foo9

$ ./bin/etcdctl del foo

$ ./bin/etcdctl watch foo foo9
# in another terminal: ./bin/etcdctl put foo bar
foo
bar
# in another terminal: ./bin/etcdctl put foo1 bar1
foo1
bar1

$ ./bin/etcdctl compact 5
compacted revision 5
# any revisions before the compacted one are not accessible
$ ./bin/etcdctl get --rev=4 foo
Error:  rpc error: code = 11 desc = etcdserver: mvcc: required revision has been compacted

# grant a lease with 10 second TTL
$ ./bin/etcdctl lease grant 10
lease 32695410dcc0ca06 granted with TTL(10s)
# attach key foo to lease 32695410dcc0ca06
$ ./bin/etcdctl put --lease=32695410dcc0ca06 foo bar
OK

$ ./bin/etcdctl lease grant 10
lease 32695410dcc0ca06 granted with TTL(10s)
$ ./bin/etcdctl put --lease=32695410dcc0ca06 foo bar
OK
$ ./bin/etcdctl lease revoke 32695410dcc0ca06
lease 32695410dcc0ca06 revoked
$ ./bin/etcdctl get foo
# empty response since foo is deleted due to lease revocation

$ ./bin/etcdctl lease grant 10
lease 32695410dcc0ca06 granted with TTL(10s)
$ ./bin/etcdctl lease keep-alive 32695410dcc0ca0
lease 32695410dcc0ca0 keepalived with TTL(100)
lease 32695410dcc0ca0 keepalived with TTL(100)
lease 32695410dcc0ca0 keepalived with TTL(100)

你可能感兴趣的:(docker)