etcd编译与简单使用

来源:互联网 发布:单片机在线编程 编辑:程序博客网 时间:2024/04/27 23:53

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 versiongo 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/etcdSet a key:$ ETCDCTL_API=3 ./bin/etcdctl put foo barOK

简单使用

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 barfoobar# in another terminal: ./bin/etcdctl put foo1 bar1foo1bar1$ ./bin/etcdctl compact 5compacted revision 5# any revisions before the compacted one are not accessible$ ./bin/etcdctl get --rev=4 fooError:  rpc error: code = 11 desc = etcdserver: mvcc: required revision has been compacted# grant a lease with 10 second TTL$ ./bin/etcdctl lease grant 10lease 32695410dcc0ca06 granted with TTL(10s)# attach key foo to lease 32695410dcc0ca06$ ./bin/etcdctl put --lease=32695410dcc0ca06 foo barOK$ ./bin/etcdctl lease grant 10lease 32695410dcc0ca06 granted with TTL(10s)$ ./bin/etcdctl put --lease=32695410dcc0ca06 foo barOK$ ./bin/etcdctl lease revoke 32695410dcc0ca06lease 32695410dcc0ca06 revoked$ ./bin/etcdctl get foo# empty response since foo is deleted due to lease revocation$ ./bin/etcdctl lease grant 10lease 32695410dcc0ca06 granted with TTL(10s)$ ./bin/etcdctl lease keep-alive 32695410dcc0ca0lease 32695410dcc0ca0 keepalived with TTL(100)lease 32695410dcc0ca0 keepalived with TTL(100)lease 32695410dcc0ca0 keepalived with TTL(100)
0 0
原创粉丝点击