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.pswp.cn/news/389232.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389232.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389232.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

SpringBoot簡要

2019獨角獸企業重金招聘Python工程師標準>>> 簡化Spring應用開發的一個框架;      整個Spring技術棧的一個大整合;      J2EE開發的一站式解決方案;      自動配置:針對很多Spring應用程序常見的應用功能&…

發送郵件 的類 C# .net

/// <summary> /// 發送郵件 /// </summary> /// <param name"SendTo">發送人的地址</param> /// <param name"MyEmail">我的Email地址</param> /// <param name"SendTit…

簡明易懂的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…

計算機科學期刊_成為數據科學家的五種科學期刊

計算機科學期刊The field of data science is advancing at an incredible pace. New scientific articles are published daily. As a student, I try to stay up-to-date with the scientific literature that is published. In this blog post, I created a list of scienti…

Torch.distributed.elastic 關于 pytorch 不穩定

錯誤日志&#xff1a; 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。自己曾寫過一個只能過樣例的。都放上來吧。 路徑壓縮的…

區塊鏈的模型結構

關于區塊鏈的模型結構問題&#xff0c;行業內已經談論千萬遍了&#xff0c;基本上已經成為一種定義式的問題了。總體上來看&#xff0c;區塊鏈的基礎架構可以分為六層&#xff0c;包括數據層、網絡層、共識層、激勵層、合約層、應用層。每一層分別完成一項核心的功能&#xff0…

數據科學家 數據工程師_數據科學家應該對數據進行版本控制的4個理由

數據科學家 數據工程師While working in a software project it is very common and, in fact, a standard to start right away versioning code, and the benefits are already pretty obvious for the software community: it tracks every modification of the code in a p…

JDK 下載相關資料

所有版本JDK下載地址&#xff1a; http://www.oracle.com/technetwork/java/archive-139210.html 下載賬戶密碼&#xff1a; 2696671285qq.com Oracle123 轉載于:https://www.cnblogs.com/bg7c/p/9277729.html

商米

2019獨角獸企業重金招聘Python工程師標準>>> 今天看了一下商米的官網&#xff0c;發現他家的東西還真的是不錯。有錢了&#xff0c;想去體驗一下。 如果我妹妹還有開便利店的話&#xff0c;我會推薦他用這個。小巧便捷&#xff0c;非常方便。 轉載于:https://my.osc…

C#生成安裝文件后自動附加數據庫的思路跟算法

using System; using System.Collections.Generic; using System.Windows.Forms; using System.Data.SqlClient; using System.Data; using System.ServiceProcess; namespace AdminZJC.DataBaseControl { /// <summary> /// 數據庫操作控制類 /// </summary> …

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…

VS2005 ASP.NET2.0安裝項目的制作(包括數據庫創建、站點創建、IIS屬性修改、Web.Config文件修改)

站點&#xff1a; 如果新建默認的Web安裝項目&#xff0c;那它將創建的默認網站下的一個虛擬應用程序目錄而不是一個新的站點。故我們只有創建新的安裝項目&#xff0c;而不是Web安裝項目。然后通過安裝類進行自定義操作&#xff0c;創建新站如下圖&#xff1a; 2、創建新的安項…