解锁高性能工具etcd大牛们常用的命令

目录

1.前言

[2. 常用命令](#2. 常用命令)

[3. 总结](#3. 总结)

1.前言

etcd简介:etcd是CoreOS团队于2013年6月发起的开源项目,它的目标是构建一个高可用的分布式键值(key-value)数据库。etcd内部采用raft协议作为一致性算法,etcd基于Go语言实现;

ETCD官方文档:https://etcd.io/docs/v3.4.0/op-guide/maintenance/#auto-compaction

ETCD文档:https://doczhcn.gitbook.io/etcd/

2. 常用命令

上面就简单的介绍了下etcd ,感兴趣的可以参考官方文档去学习,下面介绍下,平时生产环境中常用的操作命令如下:

etc 实时日志查看命令:journalctl -f -u etcd

  1. put 指定某个键的值。

例如: etcdctl put /test/key1 "Hello world"

  1. get 获取指定键的值。

例如:

etcdctl get /test/key1

etcdctl --write-out="json" get /test/key1

  1. put 更新指定的值。

例如:etcdctl put /test/key1 "baihezhuo"

  1. del 删除指定的key。

例如:

etcdctl put /test/key2 1234

etcdctl del /test/key2

  1. 获取所有前缀的信息

etcdctl get --prefix /test

指定最大获取2条信息

etcdctl get --prefix --limit=2 /test

  1. 删除所有前缀的信息

etcdctl del --prefix /test

  1. watch key

001节点watch test:

etcdctl watch /test

002节点进行修改内容:

etcdctl put /test "base"

003节点进行删除内容,这里千万注意,他们不是真正的目录结构,删除/test 并不会删除/test/key1等子节点

etcdctl del /test

前缀watch,可以实现类似zk的子节点监听

etcdctl watch /test --prefix

  1. lease 申请租约,续约,查看租约时间

查看租期列表

etcdctl lease list

found 0 leases

申请一个200s的租约

etcdctl lease grant 200

-- lease 6fa06eb09efa986e granted with TTL(200s)

续约租期

etcdctl lease keep-alive 6fa06eb09efa986e

查看租约剩余时间

etcdctl lease timetolive 6fa06eb09efa986e

撤销租约

etcdctl lease revoke 6fa06eb09efa986e

添加内容并配置相应的租约

etcdctl put /test/key3 "linghui" --lease=6fa06eb09efa986e

获取内容:

etcdctl get /test/key3

当租约到期时会打印如下:

root@hadoop001 etcd\]# etcdctl lease timetolive 6fa06eb09efa986e lease 6fa06eb09efa986e already expired \[root@hadoop001 etcd\]# etcdctl get /test/key3 9. 分布式锁 lock etcdctl --endpoints=$ENDPOINTS lock mutex1 mutex1/6fa06eb09efa98d1 # another client with the same name blocks etcdctl --endpoints=$ENDPOINTS lock mutex1 10. txn 事务操作 etcdctl put /test/key4 "txn1" ## 进入事务 etcdctl txn --interactive ## 比较:/test/key4=txn 则执行success requests操作,/test/key4 != txn 则执行failure requests操作 compares: value("/test/key4") = "txn2" success requests (get, put, delete): put /test/key4 ok failure requests (get, put, delete): put /test/key4 no ## 最终结果/test/key4 为no etcdctl get /test/key4 ### 3. 总结 以上操作命令,就是平常使用的etcd 命令,此处做个记录,以方便后面用到的时候查看

相关推荐
奔跑吧 android38 分钟前
【linux kernel 常用数据结构和设计模式】【数据结构 2】【通过一个案例属性list、hlist、rbtree、xarray数据结构使用】
linux·数据结构·list·kernel·rbtree·hlist·xarray
NiKo_W2 小时前
Linux 文件系统与基础指令
linux·开发语言·指令
Darkwanderor4 小时前
Linux 的权限详解
linux
SabreWulf20204 小时前
Ubuntu 20.04手动安装.NET 8 SDK
linux·ubuntu·avalonia·.net8
不是吧这都有重名4 小时前
为什么ubuntu大文件拷贝会先快后慢?
linux·运维·ubuntu
sunshine-sm5 小时前
CentOS Steam 9安装 Redis
linux·运维·服务器·redis·centos
小熊h5 小时前
MySQL集群高可用架构——组复制 (MGR)
linux·数据库·mysql
棒棒的唐5 小时前
armbian平台ubuntu环境下telnet安装及启动,给pantherX2增加一个应急通道
linux·运维·armbian·telnetd
bug攻城狮5 小时前
CentOS 7 设置静态 IP 地址
linux·tcp/ip·centos
纳切威6 小时前
CentOS 7部署Zabbix5.0
linux·运维·centos·zabbix