跳过正文
  1. Etcds/

etcd 基本操作

·230 字·2 分钟· loading
etcd devops
demo007x
作者
demo007x
目录

image.png

etcd
#

etcd(读作et-see-dee)是一种开源的分布式统一键值存储,用于分布式系统或计算机集群的共享配置、服务发现和的调度协调etcd 有助于促进更加安全的自动更新,协调向主机调度的工作,并帮助设置容器的覆盖网络。 etcd 是许多其他项目的核心组件。

安装
#

  • 1、第一种方式就是通过 github 安装,可自行在一下网站下载

Releases · etcd-io/etcd (github.com)

  • 2、 通过命令安装

mac brew install etcd

添加环境变量
#

安装完成后需要将 etcd 的目录添加到环境变量中,这样就可以调用 etcd 命令操作。

add path

执行以下命令查看是否生效: etcd --version

输出:

etcd --version
etcd Version: 3.5.10
Git SHA: 0223ca52b
Go Version: go1.20.10
Go OS/Arch: darwin/amd64

启动 etcd 服务
#

./etcd

输出:
#

image-20231031151027987

基础使用
#

设置值 etcdctl put
#

etcdctl put greeting "hello world"

获取值 etcdctl get
#

etcdctl get greeting

授权 auth
#

  • 设置环境变量 ETCDCTL_API=3 ENDPOINTS=localhost:2379
export ETCDCTL_API=3
ENDPOINTS=localhost:2379
  • 添加角色: etcd 可以通过添加用户,添加角色,角色授权,将用户添加到角色进行权限管控:
# 添加 root 角色
etcdctl --endpoints=${ENDPOINTS} role add root
  • 获取角色信息
etcdctl --endpoints=${ENDPOINTS} role get root
Role root
KV Read:
KV Write:
  • 添加 root 成员 / 获取成员信息

# 添加成员 root
etcdctl --endpoints=${ENDPOINTS} user add root

# 设置密码
Password of root:
Type password of root again for confirmation:
User root created

# 查看用户信息
etcdctl --endpoints=${ENDPOINTS} user get root
User: root
Roles:
  • 成员授权角色
# 将 root 用户授权给 root 角色
etcdctl --endpoints=${ENDPOINTS} user grant-role root root

# 用户 root 授权 root 成功
Role root is granted to user root
  • 添加新的角色,授权角色的权限
etcdctl --endpoints=${ENDPOINTS} role add role0
etcdctl --endpoints=${ENDPOINTS} role grant-permission role0 readwrite foo
etcdctl --endpoints=${ENDPOINTS} user add user0
etcdctl --endpoints=${ENDPOINTS} user grant-role user0 role0
  • 启用角色授权

# 最后需要启用 etcd 的auth 功能
etcdctl --endpoints=${ENDPOINTS} auth enable
Authentication Enabled
  • 使用新添加的成员user0来操作etcd
etcdctl --endpoints=${ENDPOINTS} --user=user0:123 put foo bar
etcdctl --endpoints=${ENDPOINTS} get foo
#权限被拒绝,用户名为空,因为请求未发出身份验证请求
etcdctl --endpoints=${ENDPOINTS} --user=user0:123 get foo
#user0可以读取关键字foo
etcdctl --endpoints=${ENDPOINTS} --user=user0:123 get foo1

相关文章

2023 年要学习的 10 大 DevOps 技能
devops linux
DevOps 是两个不同领域的混合体,即开发和运维。这提高了更快地发布软件应用程序的能力,与传统软件开发方法相比,具有快节奏的改进和演变。它使团队能够更快地根据市场进行创新和适应,促进版本的增加,这有助于轻松识别和修复错误,并在改进团队间协作的帮助下鼓励可靠性、安全性和可扩展性。
Kubernetes 工具
devops Kubernetes
不可否认的是,复杂性是会减慢任何进程的限制之一–无论是软件开发还是其他。我们需要使用正确的工具来简化复杂性或完全消除它。在这一点上,当涉及到大规模的软件开发、部署和维护时,毫无疑问,复杂性可能在任何阶段出现。我们必须识别并使用正确的工具来尽快解决复杂性。要知道,Kubernetes是强大的容器编排系统之一,用于自动部署、扩展和维护软件应用。在处理Kubernetes中的大型工作负载时,不可避免地会出现复杂情况。然而,有很多Kubernetes工具在很大程度上简化了Kubernetes的管理。一下是基于不同类别列出的各种Kubernetes工具。同时,你将快速了解这些工具的目的和重要功能。
现代 IT 人一定要知道的 Ansible系列教程:Roles详解
devops
ansible 中角色允许我们根据已知的文件结构自动加载相关的变量、文件、任务、处理程序和其他 Ansible 工件。将内容分组到角色后,我们可以轻松地重复使用它们并与其他用户共享它们。