博客
关于我
如何使用Etcdctl与Etcd——CoreOS的分布式键-值存储
阅读量:234 次
发布时间:2019-03-01

本文共 2960 字,大约阅读时间需要 9 分钟。

Etcd集群发现模式与操作指南

作为CoreOS生态系统的核心组件,Etcd提供了一套分布式键-值存储解决方案,可通过多个节点构建集群并实现全局数据访问。本文将深入探讨Etcd的集群发现模式、操作命令以及相关配置方法。


Etcd集群发现模式

Etcd通过云发现服务(Cloud discovery service)实现多节点设备的自动发现。CoreOS在引导节点时会检查cloud-config文件中的发现地址,获取集群成员的信息。例如,以下是示例发现地址:

https://discovery.etcd.io/dcadc5d4d42328488ecdcd7afae5f57c

此地址返回JSON数据,描述已知的设备信息。集群引导完成后,设备会通过此地址获取其他节点的信息,并将自身信息提交至集群。以下是初始和集群完成后的示例数据:

{"action":"get","node":{"key":"/_etcd/registry/dcadc5d4d42328488ecdcd7afae5f57c","dir":true,"modifiedIndex":102511104,"createdIndex":102511104}}
{"action":"get","node":{"key":"/_etcd/registry/1edee33e6b03e75d9428eacf0ff94fda","dir":true,"nodes":[{"key":"/_etcd/registry/1edee33e6b03e75d9428eacf0ff94fda/2ddbdb7c872b4bc59dd1969ac166501e","value":"http://10.132.252.38:7001","expiration":"2014-09-19T13:41:26.912303668Z","ttl":598881,"modifiedIndex":102453704,"createdIndex":102453704},{"key":"/_etcd/registry/1edee33e6b03e75d9428eacf0ff94fda/921a7241c31a499a97d43f785108b17c","value":"http://10.132.248.118:7001","expiration":"2014-09-19T13:41:29.602508981Z","ttl":598884,"modifiedIndex":102453736,"createdIndex":102453736},{"key":"/_etcd/registry/1edee33e6b03e75d9428eacf0ff94fda/27987f5eaac243f88ca6823b47012c5b","value":"http://10.132.248.121:7001","expiration":"2014-09-19T13:41:41.817958205Z","ttl":598896,"modifiedIndex":102453860,"createdIndex":102453860}],"modifiedIndex":101632353,"createdIndex":101632353}}

Etcdctl使用

Etcdctl是Etcd的命令行工具,支持创建、读取、更新和删除操作。以下是常用命令示例:

查看键与目录

etcdctl ls /coreos.com
etcdctl get /coreos.com/coreos.com: is a directory
etcdctl ls / --recursive/coreos.com/coreos.com/updateengine/coreos.com/updateengine/rebootlock/coreos.com/updateengine/rebootlock/semaphore
etcdctl get /coreos.com/updateengine/rebootlock/semaphore{"semaphore":1,"max":1,"holders":null}

设定键与创建节点

etcdctl mkdir /example
etcdctl mk /example/key datadata
etcdctl get /example/keydata
etcdctl update /example/key turtlesturtles
etcdctl mkdir /here/you/go --ttl 120
etcdctl updatedir /here/you/go --ttl 500
etcdctl set /example/key newnew
etcdctl set /a/b/c herehere
etcdctl setdir /x/y/z

移除条目

etcdctl rm /a/b/c
etcdctl rm /a --recursive
etcdctl rmdir /x/y/z

观察变化

etcdctl watch /example/hello
etcdctl watch --recursive /example
whiletrue; do etcdctl watch --recursive /example; done
etcdctl exec-watch --recursive /example -- echo"hello"

Etcd HTTP/JSON API使用方法

通过HTTP/JSON API可以对Etcd进行远程控制。以下是一些常用操作示例:

获取顶级键

curl -L http://127.0.0.1:4001/v2/keys/

递归列出全部键

curl -L http://127.0.0.1:4001/v2/keys/?recursive=true

查看集群状态

curl -L http://127.0.0.1:4001/v2/stats/leader

查看操作状态

curl -L http://127.0.0.1:4001/v2/stats/store

Etcd配置

Etcd的配置可以通过多种方式实现,包括:

云配置文件

coreos:  etcd:    discovery: https://discovery.etcd.io/dcadc5d4d42328488ecdcd7afae5f57c    addr: $private_ipv4:4001    peer-addr: $private_ipv4:7001

API配置

curl -L http://127.0.0.1:7001/v2/admin/config
curl -L http://127.0.0.1:7001/v2/admin/machines

总结

通过以上方法,我们可以利用Etcd实现集群节点的自动发现、键值存储的管理以及集群状态的监控。Etcd的设计理念使其成为分布式系统的理想选择,其灵活性和可扩展性为服务部署提供了强有力的支持。

转载地址:http://wbdt.baihongyu.com/

你可能感兴趣的文章
Objective-C实现MSRCR算法(附完整源码)
查看>>
Objective-C实现multi level feedback queue多级反馈队列算法(附完整源码)
查看>>
Objective-C实现multilayer perceptron classifier多层感知器分类器算法(附完整源码)
查看>>
Objective-C实现multiplesThreeAndFive三或五倍数的算法 (附完整源码)
查看>>
Objective-C实现n body simulationn体模拟算法(附完整源码)
查看>>
Objective-C实现naive string search字符串搜索算法(附完整源码)
查看>>
Objective-C实现natural sort自然排序算法(附完整源码)
查看>>
Objective-C实现nested brackets嵌套括号算法(附完整源码)
查看>>
Objective-C实现nevilles method多项式插值算法(附完整源码)
查看>>
Objective-C实现newton raphson牛顿-拉夫森算法(附完整源码)
查看>>
Objective-C实现newtons second law of motion牛顿第二运动定律算法(附完整源码)
查看>>
Objective-C实现newton_forward_interpolation牛顿前插算法(附完整源码)
查看>>
Objective-C实现newton_raphson牛顿拉夫森算法(附完整源码)
查看>>
Objective-C实现ngram语言模型算法(附完整源码)
查看>>
Objective-C实现NLP中文分词(附完整源码)
查看>>
Objective-C实现NLP中文分词(附完整源码)
查看>>
Objective-C实现NMS非极大值抑制(附完整源码)
查看>>
Objective-C实现NMS非极大值抑制(附完整源码)
查看>>
Objective-C实现Node.Js中生成一个UUID/GUID算法(附完整源码)
查看>>
Objective-C实现not gate非门算法(附完整源码)
查看>>