docker etcd

etcd是CoreOS团队于2013年6月发起的开源项目,它的目标是构建一个高可用的分布式键值(key-value)数据库用于配置共享和服务发现

etcd内部采用raft协议作为一致性算法,etcd基于Go语言实现。

 

etcd作为服务发现系统,有以下的特点:

  • 简单:安装配置简单,HTTP+JSON的 API进行交互,使用curl命令可以轻松使用
  • 安全:支持SSL证书验证机制
  • 快速:根据官方提供的benchmark数据,单实例支持每秒1k+写操作
  • 可靠:采用raft算法,实现分布式系统数据的可用性和一致性
    • 分布式系统中数据分为控制数据和应用数据,etcd处理的数据为控制数据

 

同一个分布式集群中的进程或服务,互相感知并建立链接,这就是服务发现。解决服务发现问题的三大支柱:

  • 一个强一致性、高可用的服务存储目录
    • 基于Raft算法
  • 一种注册服务和监控服务健康状态的机制
  • 一种查找和链接服务的机制
  • 微服务协同工作架构中,服务动态添加 

 

 

etcd基本命令

集群搭建参考k8s集群搭建里的etcd

 

更新一个节点

#首先查看所有节点
[root@slave2 ~]# etcdctl member list
646ec025a72fc8a: name=etcd3 peerURLs=http://192.168.132.133:2380 clientURLs=http://192.168.132.133:2379 isLeader=true
dde447f371b55f50: name=etcd1 peerURLs=http://192.168.132.131:2380 clientURLs=http://192.168.132.131:2379 isLeader=false
e96057c7f8ba5f4b: name=etcd2 peerURLs=http://192.168.132.132:2380 clientURLs=http://192.168.132.132:2379 isLeader=false#更新一个节点
[root@slave2 ~]# etcdctl member update 646ec025a72fc8a http://192.168.132.133:2380
Updated member with ID 646ec025a72fc8a in cluster

 

删除一个节点

#查看所有节点
[root@slave2 ~]# etcdctl member list 646ec025a72fc8a: name=etcd3 peerURLs=http://192.168.132.133:2380 clientURLs=http://192.168.132.133:2379 isLeader=false dde447f371b55f50: name=etcd1 peerURLs=http://192.168.132.131:2380 clientURLs=http://192.168.132.131:2379 isLeader=true e96057c7f8ba5f4b: name=etcd2 peerURLs=http://192.168.132.132:2380 clientURLs=http://192.168.132.132:2379 isLeader=false
#删除一个节点
[root@slave2
~]# etcdctl member remove 646ec025a72fc8a Removed member 646ec025a72fc8a from cluster
#再次查看节点,使用当前命令报错
[root@slave2
~]# etcdctl member list Error: client: etcd cluster is unavailable or misconfigured; error #0: dial tcp 127.0.0.1:2379: getsockopt: connection refused ; error #1: dial tcp 127.0.0.1:4001: getsockopt: connection refused error #0: dial tcp 127.0.0.1:2379: getsockopt: connection refused error #1: dial tcp 127.0.0.1:4001: getsockopt: connection refused
#换一个命令
[root@slave2 ~]# etcdctl --endpoints "http://192.168.132.131:2379" member list dde447f371b55f50: name=etcd1 peerURLs=http://192.168.132.131:2380 clientURLs=http://192.168.132.131:2379 isLeader=true e96057c7f8ba5f4b: name=etcd2 peerURLs=http://192.168.132.132:2380 clientURLs=http://192.168.132.132:2379 isLeader=false

 

添加节点

#将删除的节点添加回来
[root@slave2 ~]# etcdctl --endpoints "http://192.168.132.132:2379" member add etcd3 http://192.168.132.133:2380 Added member named etcd3 with ID 7a6809311b4a3579 to clusterETCD_NAME="etcd3" ETCD_INITIAL_CLUSTER="etcd3=http://192.168.132.133:2380,etcd1=http://192.168.132.131:2380,etcd2=http://192.168.132.132:2380" ETCD_INITIAL_CLUSTER_STATE="existing"
#再次查看,状态为unstarted [root@slave2
~]# etcdctl --endpoints "http://192.168.132.132:2379" member list 7a6809311b4a3579[unstarted]: peerURLs=http://192.168.132.133:2380 dde447f371b55f50: name=etcd1 peerURLs=http://192.168.132.131:2380 clientURLs=http://192.168.132.131:2379 isLeader=true e96057c7f8ba5f4b: name=etcd2 peerURLs=http://192.168.132.132:2380 clientURLs=http://192.168.132.132:2379 isLeader=false

清空目标节点数据

目标节点从集群中删除后,成员信息会更新。新节点是作为一个全新的节点加入集群,如果data-dir有数据,etcd启动时会读取己经存在的数据,仍然用旧的memberID会造成无法加入集群,所以一定要清空新节点的data-dir。

#删除的节点的主机
$ rm -rf /var/lib/etcd/etcd3

 

在目标节点上启动新增加的成员

修改配置文件中ETCD_INITIAL_CLUSTER_STATE标记为existing,如果为new,则会自动生成一个新的memberID,这和前面添加节点时生成的ID不一致,故日志中会报节点ID不匹配的错。

[root@slave2 ~]# cat /etc/etcd/etcd.conf |grep -v "^#"
[Member]
ETCD_DATA_DIR="/var/lib/etcd/etcd3"
ETCD_LISTEN_PEER_URLS="http://192.168.132.133:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.132.133:2379,http://127.0.0.1:2379"
ETCD_NAME="etcd3"
[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.132.133:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.132.133:2379"
ETCD_INITIAL_CLUSTER_STATE="existing"
ETCD_INITIAL_CLUSTER="etcd1=http://192.168.132.131:2380,etcd2=http://192.168.132.132:2380,etcd3=http://192.168.132.133:2380"

 

重启服务,再次查看

[root@slave2 ~]# systemctl restart etcd
[root@slave2 ~]# etcdctl --endpoints "http://192.168.132.132:2379" member list
7a6809311b4a3579: name=etcd3 peerURLs=http://192.168.132.133:2380 clientURLs=http://192.168.132.133:2379 isLeader=false
dde447f371b55f50: name=etcd1 peerURLs=http://192.168.132.131:2380 clientURLs=http://192.168.132.131:2379 isLeader=true
e96057c7f8ba5f4b: name=etcd2 peerURLs=http://192.168.132.132:2380 clientURLs=http://192.168.132.132:2379 isLeader=false
[root@slave2 ~]# etcdctl member list
7a6809311b4a3579: name=etcd3 peerURLs=http://192.168.132.133:2380 clientURLs=http://192.168.132.133:2379 isLeader=false
dde447f371b55f50: name=etcd1 peerURLs=http://192.168.132.131:2380 clientURLs=http://192.168.132.131:2379 isLeader=true
e96057c7f8ba5f4b: name=etcd2 peerURLs=http://192.168.132.132:2380 clientURLs=http://192.168.132.132:2379 isLeader=false

 

转载于:https://www.cnblogs.com/FRESHMANS/p/9268693.html

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

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

相关文章

SpringBoot简要

2019独角兽企业重金招聘Python工程师标准>>> 简化Spring应用开发的一个框架;      整个Spring技术栈的一个大整合;      J2EE开发的一站式解决方案;      自动配置:针对很多Spring应用程序常见的应用功能&…

简明易懂的c#入门指南_统计假设检验的简明指南

简明易懂的c#入门指南介绍 (Introduction) One of the main applications of frequentist statistics is the comparison of sample means and variances between one or more groups, known as statistical hypothesis testing. A statistic is a summarized/compressed proba…

Torch.distributed.elastic 关于 pytorch 不稳定

错误日志: Epoch: [229] Total time: 0:17:21 Test: [ 0/49] eta: 0:05:00 loss: 1.7994 (1.7994) acc1: 78.0822 (78.0822) acc5: 95.2055 (95.2055) time: 6.1368 data: 5.9411 max mem: 10624 WARNING:torch.distributed.elastic.agent.server.api:Rec…

0x22 迭代加深

poj2248 真是个新套路。还有套路剪枝...大到小和判重 #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<bitset> using namespace std;int n,D,x[110];bool…

云原生全球最大峰会之一KubeCon首登中国 Kubernetes将如何再演进?

雷锋网消息&#xff0c;11月14日&#xff0c;由CNCF发起的云原生领域全球最大的峰会之一KubeConCloudNativeCon首次登陆中国&#xff0c;中国已经成为云原生领域一股强大力量&#xff0c;并且还在不断成长。 毫无疑问&#xff0c;Kubernetes已经成为容器编排事实标准&#xff…

分布分析和分组分析_如何通过群组分析对用户进行分组并获得可行的见解

分布分析和分组分析数据分析 (DATA ANALYSIS) Being a regular at a restaurant is great.乙 eing定期在餐厅是伟大的。 When I started university, my dad told me I should find a restaurant I really liked and eat there every month with some friends. Becoming a reg…

python 工具箱_Python交易工具箱:通过指标子图增强图表

python 工具箱交易工具箱 (trading-toolbox) After a several months-long hiatus, I can finally resume posting to the Trading Toolbox Series. We started this series by learning how to plot indicators (specifically: moving averages) on the top of a price chart.…

PDA端的数据库一般采用的是sqlce数据库

PDA端的数据库一般采用的是sqlce数据库,这样与PC端的sql2000中的数据同步就变成了一个问题,如在PDA端处理,PDA端的内存,CPU等都是一个制约因素,其次他们的一个连接稳定及其间的数据传输也是一个难点.本例中通过在PC端的转化后再复制到PDA上面,这样,上面所有的问题都得到了一个有…

bzoj 1016 [JSOI2008]最小生成树计数——matrix tree(相同权值的边为阶段缩点)(码力)...

题目&#xff1a;https://www.lydsy.com/JudgeOnline/problem.php?id1016 就是缩点&#xff0c;每次相同权值的边构成的联通块求一下matrix tree。注意gauss里的编号应该是从1到...的连续的。 学习了一个TJ。用了vector。自己曾写过一个只能过样例的。都放上来吧。 路径压缩的…

商米

2019独角兽企业重金招聘Python工程师标准>>> 今天看了一下商米的官网&#xff0c;发现他家的东西还真的是不错。有钱了&#xff0c;想去体验一下。 如果我妹妹还有开便利店的话&#xff0c;我会推荐他用这个。小巧便捷&#xff0c;非常方便。 转载于:https://my.osc…

python交互式和文件式_使用Python创建和自动化交互式仪表盘

python交互式和文件式In this tutorial, I will be creating an automated, interactive dashboard of Texas COVID-19 case count by county using python with the help of selenium, pandas, dash, and plotly. I am assuming the reader has some familiarity with python,…

不可不说的Java“锁”事

2019独角兽企业重金招聘Python工程师标准>>> 前言 Java提供了种类丰富的锁&#xff0c;每种锁因其特性的不同&#xff0c;在适当的场景下能够展现出非常高的效率。本文旨在对锁相关源码&#xff08;本文中的源码来自JDK 8&#xff09;、使用场景进行举例&#xff0c…

数据可视化 信息可视化_可视化数据以帮助清理数据

数据可视化 信息可视化The role of a data scientists involves retrieving hidden relationships between massive amounts of structured or unstructured data in the aim to reach or adjust certain business criteria. In recent times this role’s importance has been…

seaborn添加数据标签_常见Seaborn图的数据标签快速指南

seaborn添加数据标签In the course of my data exploration adventures, I find myself looking at such plots (below), which is great for observing trend but it makes it difficult to make out where and what each data point is.在进行数据探索的过程中&#xff0c;我…

使用python pandas dataframe学习数据分析

⚠️ Note — This post is a part of Learning data analysis with python series. If you haven’t read the first post, some of the content won’t make sense. Check it out here.Note️ 注意 -这篇文章是使用python系列学习数据分析的一部分。 如果您还没有阅读第一篇文…

无向图g的邻接矩阵一定是_矩阵是图

无向图g的邻接矩阵一定是To study structure,tear away all flesh soonly the bone shows.要研究结构&#xff0c;请尽快撕掉骨头上所有的肉。 Linear algebra. Graph theory. If you are a data scientist, you have encountered both of these fields in your study or work …

前端绘制绘制图表_绘制我的文学风景

前端绘制绘制图表Back when I was a kid, I used to read A LOT of books. Then, over the last couple of years, movies and TV series somehow stole the thunder, and with it, my attention. I did read a few odd books here and there, but not with the same ferocity …

如何描绘一个vue的项目_描绘了一个被忽视的幽默来源

如何描绘一个vue的项目Source)来源 ) Data visualization is a great way to celebrate our favorite pieces of art as well as reveal connections and ideas that were previously invisible. More importantly, it’s a fun way to connect things we love — visualizing …

数据存储加密和传输加密_将时间存储网络应用于加密预测

数据存储加密和传输加密I’m not going to string you along until the end, dear reader, and say “Didn’t achieve anything groundbreaking but thanks for reading ;)”.亲爱的读者&#xff0c;我不会一直待到最后&#xff0c;然后说&#xff1a; “没有取得任何开创性的…

熊猫分发_熊猫新手:第一部分

熊猫分发For those just starting out in data science, the Python programming language is a pre-requisite to learning data science so if you aren’t familiar with Python go make yourself familiar and then come back here to start on Pandas.对于刚接触数据科学的…