ETCD本地多成员集群部署

news2024/9/24 11:31:39

目录

  • 安装部署
    • etcdctl 操作etcd
    • 使用http请求操作etcd
  • 本地多成员集群搭建
    • python获取成员信息
  • 参考

安装部署

按照官网文档,安装release版本

https://etcd.io/docs/v3.4/install/

[root@VM-33-162-centos /usr/local/bin]# etcd --version
etcd Version: 3.4.16
Git SHA: d19fbe541
Go Version: go1.12.17
Go OS/Arch: linux/amd64

直接使用etcdctl不行,需要添加到path,或者

/tmp/etcd-download-test/etcdctl

etcd_svr默认开放端口2379

后台启动etcd

 etcd &

etcdctl 操作etcd

put / get

/tmp/etcd-download-test/etcdctl put greeting "hello etcd"
OK
[root@VM-33-162-centos /usr/local/bin]# /tmp/etcd-download-test/etcdctl get greeting 
greeting
hello etcd

使用http请求操作etcd

首先安装etcd3,注意可能会出现问题

关于protobuf报错:If this call came from a _pb2.py file, 
your generated code is out of date and must be regenerated with protoc >= 3.19.0.

所以我们安装的时候需要:

pip install etcd3
pip3 install --upgrade protobuf==3.20.1

接下来我们对本地的etcd进行访问

import etcd3

etcd = etcd3.client(host='127.0.0.1', port=2379)

print(etcd.put('bar', 'doot'))
print(etcd.get('bar'))
print(etcd.delete('bar'))
print(etcd.get('bar'))

(env) [hanhandi@VM-33-162-centos ~/hanhan_PythonScripts/etcdTest]$ python demo.py 
header {
  cluster_id: 14841639068965178418
  member_id: 10276657743932975437
  revision: 5
  raft_term: 4
}

(b'doot', <etcd3.client.KVMetadata object at 0x7f07150efa30>)
True
(None, None)

本地多成员集群搭建

 go get github.com/mattn/goreman
 goreman -f Procfile start

在执行第二句时:

goreman: open Procfile: no such file or directory

我们从下面这个网址拷贝出Profile

https://github.com/etcd-io/etcd/blob/main/Procfile

然后在/usr/local/bin/目录下创建文件,粘贴进去,并将bin/去除

# Use goreman to run `go install github.com/mattn/goreman@latest`
# Change the path of bin/etcd if etcd is located elsewhere

etcd1: etcd --name infra1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
etcd2: etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
etcd3: etcd --name infra3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
#proxy: bin/etcd grpc-proxy start --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379 --listen-addr=127.0.0.1:23790 --advertise-client-url=127.0.0.1:23790 --enable-pprof

# A learner node can be started using Procfile.learner

然后在该目录下执行

 goreman -f ./Procfile start &

然后就可以看到有三个etcd节点在运行了

在这里插入图片描述

查看一下集群运行状态:

(env) [hanhandi@VM-33-162-centos ~/hanhan_PythonScripts]$ export ETCDCTL_API=3
(env) [hanhandi@VM-33-162-centos ~/hanhan_PythonScripts]$ /tmp/etcd-download-test/etcdctl --write-out=table --endpoints=localhost:2379 member list
+------------------+---------+--------+------------------------+------------------------+------------+
|        ID        | STATUS  |  NAME  |       PEER ADDRS       |      CLIENT ADDRS      | IS LEARNER |
+------------------+---------+--------+------------------------+------------------------+------------+
| 8211f1d0f64f3269 | started | infra1 | http://127.0.0.1:12380 |  http://127.0.0.1:2379 |      false |
| 91bc3c398fb3c146 | started | infra2 | http://127.0.0.1:22380 | http://127.0.0.1:22379 |      false |
| fd422379fda50e48 | started | infra3 | http://127.0.0.1:32380 | http://127.0.0.1:32379 |      false |
+------------------+---------+--------+------------------------+------------------------+------------+

为了模拟容灾情况,我们手动kill一个etcd节点

$ ps -ef | grep etcd | grep 127.0.0.1:22379
root     29622 29613  0 14:45 pts/4    00:00:00 etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380 --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
$ kill -9 29622

然后向其他节点插入key value

# /tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 put key hello
OK
# /tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 get key
key
hello

然后尝试从已删除节点进行获取信息

# /tmp/etcd-download-test/etcdctl --endpoints=localhost:22379 get key
{"level":"warn","ts":"2023-02-18T14:49:58.251+0800","caller":"clientv3/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"endpoint://client-6cf6d681-cf64-4762-bb9d-c2a2d1332190/localhost:22379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: all SubConns are in TransientFailure, latest connection error: connection error: desc = \"transport: Error while dialing dial tcp [::1]:22379: connect: connection refused\""}
Error: context deadline exceeded

我们再重启该节点,并尝试获取

# goreman run restart etcd2
# /tmp/etcd-download-test/etcdctl --endpoints=localhost:22379 get key
key
hello

获取成功

python获取成员信息

import etcd3
import json
etcd = etcd3.client(host='127.0.0.1', port=2379)
members = etcd.members
for mem in members:
    print(mem.__str__())
    print(mem.id)
    print(mem.name)
    print(mem.peer_urls)
    print(mem.client_urls)

(env) [root@VM-33-162-centos /data/home/hanhandi/hanhan_PythonScripts/etcdTest]# python demo.py 
Member 9372538179322589801: peer urls: ['http://127.0.0.1:12380'], client urls: ['http://127.0.0.1:2379']
9372538179322589801
infra1
['http://127.0.0.1:12380']
['http://127.0.0.1:2379']
Member 10501334649042878790: peer urls: ['http://127.0.0.1:22380'], client urls: ['http://127.0.0.1:22379']
10501334649042878790
infra2
['http://127.0.0.1:22380']
['http://127.0.0.1:22379']
Member 18249187646912138824: peer urls: ['http://127.0.0.1:32380'], client urls: ['http://127.0.0.1:32379']
18249187646912138824
infra3
['http://127.0.0.1:32380']
['http://127.0.0.1:32379']

参考

etcd基本操作:

https://python-etcd3.readthedocs.io/en/latest/readme.html

https://cizixs.com/2016/08/02/intro-to-etcd/

https://python-etcd3.readthedocs.io/en/latest/

中文文档:https://www.zhaowenyu.com/etcd-doc/ops/etcd-install-shell.html

集群部署文档:

https://blog.51cto.com/xiaoyaoyou10/5468746

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/356692.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

点云配准方法原理(NDT、ICP)

配准是点云处理中的一个基础问题&#xff0c;众多学者此问题进行了广泛而深入的研究&#xff0c;也出现了一系列优秀成熟的算法&#xff0c;在三维建模、自动驾驶等领域发挥着重要的作用。 本文主要介绍粗配准NDT (Normal Distribution Transform) 与 精配准ICP (Iterative Cl…

最新最全中小微企业研究数据:海量创业公司信息与获取投资信息(1985-2021年)

一、企业获取投资名单&资方信息 数据来源&#xff1a;搜企网、企查查、天眼查 时间跨度&#xff1a;1985年8月-2021年9月 区域范围&#xff1a;全国范围 数据字段&#xff1a;企业名称、时间、获得投资金额以及投资方信息 部分数据&#xff1a; DateCompany_nameUnit…

摄影师没了?!生成式人工智能即将降维打击摄影行业

本文是Mixlab无界社区成员的投稿&#xff1a;滚石deepfacelab和deepfacelive项目组成员摄影师失业了&#xff1f;&#xff1f;怎么说&#xff1f;##你还以为AI绘画影响的只是插画师行业吗&#xff1f;错了&#xff0c;摄影行业也即将面临技术洗牌。话不多说&#xff0c;先看一下…

java并发编程原理2 (AQS, ReentrantLock,线程池)

一、AQS&#xff1a; 1.1 AQS是什么&#xff1f; AQS就是一个抽象队列同步器&#xff0c;abstract queued sychronizer&#xff0c;本质就是一个抽象类。 AQS中有一个核心属性state&#xff0c;其次还有一个双向链表以及一个单项链表。 首先state是基于volatile修饰&#x…

分享113个HTML艺术时尚模板,总有一款适合您

分享113个HTML艺术时尚模板&#xff0c;总有一款适合您 113个HTML艺术时尚模板下载链接&#xff1a;https://pan.baidu.com/s/1ReoPNIRjkYov-SjsPo0vhg?pwdjk4a 提取码&#xff1a;jk4a Python采集代码下载链接&#xff1a;采集代码.zip - 蓝奏云 女性化妆用品网页模板 粉…

【Linux】用户分类+权限管理+umask+粘滞位说明

目录 1.用户分类 su指令 2.认识Linux权限 2.1 文件访问者的分类 2.2 文件类型和访问权限 a. 文件类型 file指令 b. 访问权限 2.3 文件权值的表示方法 a. 字母表示法 b. 八进制表示法 3.如何修改文件访问者的权限及相关指令 1. chmod指令 2. chown指令 3. chgrp指…

Python语言零基础入门教程(二十七)

Python OS 文件/目录方法 Python语言零基础入门教程&#xff08;二十六&#xff09; 61、Python os.utime() 方法 概述 os.utime() 方法用于设置指定路径文件最后的修改和访问时间。 在Unix&#xff0c;Windows中有效。 语法 utime()方法语法格式如下&#xff1a; os.uti…

SortableJS/Sortable拖拽组件,使用详细(Sortablejs安装使用)

简述 作为一名前端开发人员&#xff0c;在工作中难免会遇到拖拽功能&#xff0c;分享一个github上一个不错的拖拽js库&#xff0c;能满足我们在项目开发中的需要&#xff0c;支持Vue和React&#xff0c;下面是SortableJS的使用详细&#xff1b; 这个是sortableJS中文官方文档&…

kafka-6-python单线程操作kafka

使用Python操作Kafka&#xff1a;KafkaProducer、KafkaConsumer Python kafka-python API的帮助文档 1 kafka tools连接 (1)/usr/local/kafka_2.13-3.4.0/config/server.properties listeners PLAINTEXT://myubuntu:9092 advertised.listenersPLAINTEXT://192.168.1.8:2909…

MotoSimEG-VRC教程:动态输送带创建以及示教编程与仿真运行

目录 任务描述 简易输送带外部设备创建 输送带模型添加与配置 工件安装到输送带 输送带输送工件程序编写与仿真运行 任务描述 在MotoSimEG-VRC中创建1条输送带&#xff0c;并且能够实现将工件从输送带起始点位置处输送到结束点位置处。 简易输送带外部设备创建 在MotoS…

Linux系统之终端管理命令的基本使用

Linux系统之终端管理命令的基本使用一、检查本地系统环境1.检查系统版本2.检查系统内核版本二、终端介绍1.终端简介2.Linux终端简介3.终端的发展三、终端的相关术语1.终端模拟器2.tty终端3.pts终端4.pty终端5.控制台终端四、终端管理命令ps1.直接使用ps命令2.列出登录详细信息五…

RPA落地指南:什么是RPA

什么是RPA RPA在企业中起什么作用并扮演什么角色呢&#xff1f;想要充分了解RPA&#xff0c;我们需要知道RPA的相关概念、特点、功能以及能解决的问题。接下来对这些内容进行详细介绍。 1.1 RPA的3个核心概念 RPA的中文译名是“机器人流程自动化”&#xff0c;顾名思义&…

初始C语言 - 数组(一维数组、二维数组、数组越界、数组传参)

目录 一、一维数组的创建和初始化 1、数组的创建 2、 数组的初始化 3.一维数组的使用 数组通过下标来访问 总结: 1. 数组是使用下标来访问的&#xff0c;下标是从0开始。 2. 数组的大小可以通过计算得到。 4、一维数组在内存中的存储 二、 二维数组的创建和初始化 1.二…

算法导论【分治思想】—大数乘法、矩阵相乘、残缺棋盘

这里写自定义目录标题分治法概述特点大数相乘问题分治算法矩阵相乘分治算法残缺棋盘分治算法分治法概述 在分而治之的方法中&#xff0c;一个问题被划分为较小的问题&#xff0c;然后较小的问题被独立地解决&#xff0c;最后较小问题的解决方案被组合成一个大问题的解决。 通常…

【软件测试】自动化测试工程师必会的单元测试编写(总结),你真的了解吗......

目录&#xff1a;导读前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09;前言 单元测试编写的目的…

supervisor-男程序员的福音

supervisor是什么 supervisor是用python语言编写的&#xff0c;只能用于类Unix系统上的进程管理工具。 supervisor有什么用 举一个常见的场景&#xff0c;比如你的项目已经到了测试联调阶段&#xff0c;QA需要你把程序启动起来&#xff0c;然后进行测试&#xff0c;那么启动…

用Java实现多线程打印奇偶数

用Java实现多线程打印奇偶数1. wait()和 notify() 方法的作用&#xff1a;2. Java实现&#xff08;1&#xff09;Thread1.class 奇数线程&#xff08;2&#xff09;Thread2.class 偶数线程&#xff08;3&#xff09;共享资源类&#xff08;4&#xff09;测试1. wait()和 notify…

一篇文章带你玩转 Kubernetes:组件、核心概念和Nginx实战演示

目录一、简介1.1 容器部署时代1.2 Kubernetes有哪些优点二、Kubernetes 组件介绍三、Kubernetes 核心概念3.1 Namespace3.2 Pod3.3 Deployment3.4 Service3.5 Ingress四、Kubernetes 核心概念实战4.1 部署yaml文件4.2 通过Pod IP访问Nginx4.3 通过Service IP访问Nginx4.4 修改i…

[数据结构]:顺序表(C语言实现)

目录 前言 顺序表实现 01-开发环境 02-文件布局 03-代码 01-主函数 02-头文件 03-SeqListCommon.cpp 04-SeqListPositionOperation.cpp 05-SeqListValueOperation.cpp 结语 前言 此专栏包含408考研数据结构全部内容&#xff0c;除其中使用到C引用外&#xff0c;全为…