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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值