etcd集群部署

解决Elasticsearch集群开启账户密码安全配置自相矛盾的坑 一、采坑过程 最近在配置elasticsearch生产可用的集群环境时,集群搭建完成后,为了安全,启用es集群的安全配置,根据官方文档Set up minimal security for Elasticsearch这一节来配置集群账户密码,然后就出现了开启安全模式后,./bin/elasticsearch-setup-passwords auto ,./bin/elasticsearch-setup-passwords interactive 两个命令均无法访问。提示集群健康状态无法检查,实际上就是集群 阅读详情

一、docker下部署etcd时的docker配置

docker网络配置方式的选择:bridge和host方式都可以。具体配置见下:

bridge方式(缺省):   

    docker run -it -p 2380:2380 -p 2379:2379   --name   myetcd22   4e5b8fabb3af   /bin/sh

host方式:

    docker run -it --network host   --name   myetcd22   4e5b8fabb3af   /bin/sh

说明:

    4e5b8fabb3af 为etcd的docker imageID

    2379和2380为etcd在IANA 的注册端口。以前为私有端口4001和7001。

后续举例,都以bridge方式为例。

 

二、etcd启动参数说明及注意事项

 

参数
使用说明
 
--name etcd0 本member的名字  
--initial-advertise-peer-urls http://192.168.2.55:2380

其他member使用,其他member通过该地址与本member交互信息。一定要保证从其他member能可访问该地址。静态配置方式下,该参数的value一定要同时在--initial-cluster参数中存在。

memberID的生成受--initial-cluster-token和--initial-advertise-peer-urls影响。

 
--listen-peer-urls  http://0.0.0.0:2380 本member侧使用,用于监听其他member发送信息的地址。ip为全0代表监听本member侧所有接口  
--listen-client-urls http://0.0.0.0:2379 本member侧使用,用于监听etcd客户发送信息的地址。ip为全0代表监听本member侧所有接口  
--advertise-client-urls http://192.168.2.55:2379 etcd客户使用,客户通过该地址与本member交互信息。一定要保证从客户侧能可访问该地址  
--initial-cluster-token etcd-cluster-2 用于区分不同集群。本地如有多个集群要设为不同。   

--initial-cluster etcd0=http://192.168.2.55:2380,

etcd1=http://192.168.2.54:2380

,etcd2=http://192.168.2.56:2380

本member侧使用。描述集群中所有节点的信息,本member根据此信息去联系其他member。

memberID的生成受--initial-cluster-token和--initial-advertise-peer-urls影响。

 
--initial-cluster-state new

用于指示本次是否为新建集群。有两个取值new和existing。如果填为existing,则该member启动时会尝试与其他member交互。

集群初次建立时,要填为new,经尝试最后一个节点填existing也正常,其他节点不能填为existing。

集群运行过程中,一个member故障后恢复时填为existing,经尝试填为new也正常。

 
-data-dir 指定节点的数据存储目录,这些数据包括节点ID,集群ID,集群初始化配置,Snapshot文件,若未指定-wal-dir,还会存储WAL文件;如果不指定会用缺省目录。

 

-discovery http://192.168.1.163:20003/v2/keys/discovery/78b12ad7-2c1d-40db-9416-3727baf686cb 用于自发现模式下,指定第三方etcd上key地址,要建立的集群各member都会向其注册自己的地址。  

 

 

三、etcd几种集群部署方式

etcd部署分两个阶段:集群建立阶段,集群运行阶段。

两个阶段中操作etcd的方法不同。

下面各种部署方式也分两个阶段说明。

etcd有三种集群部署方式:

1、static配置方式(要配置本方地址和其他人地址)

适用于在配置前已经明确各种信息的情况,比如集群的大小,各member的ip,端口等信息。

各member依靠配置得知其他member的联系地址。当然ip等信息可以通过环境变量传进去,不一定要写死。

 

假设需要建一个有三个节点的集群,三个节点地址分别为:192.168.2.55,192.168.2.54,192.168.2.56。

1.1、集群建立阶段

在第一个节点上执行:

etcd --name etcd0 --initial-advertise-peer-urls http://192.168.2.55:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.55:2379 \
--initial-cluster-token etcd-cluster-2 \
--initial-cluster etcd0=http://192.168.2.55:2380,etcd1=http://192.168.2.54:2380,etcd2=http://192.168.2.56:2380 \
--initial-cluster-state new

在第二个节点上执行:

etcd --name etcd1 --initial-advertise-peer-urls http://192.168.2.54:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.54:2379 \
--initial-cluster-token etcd-cluster-2 \
--initial-cluster etcd0=http://192.168.2.55:2380,etcd1=http://192.168.2.54:2380,etcd2=http://192.168.2.56:2380 \
--initial-cluster-state new

在第三个节点上执行:
etcd --name etcd2 --initial-advertise-peer-urls http://192.168.2.56:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.56:2379 \
--initial-cluster-token etcd-cluster-2 \
--initial-cluster etcd0=http://192.168.2.55:2380,etcd1=http://192.168.2.54:2380,etcd2=http://192.168.2.56:2380 \
--initial-cluster-state new

 

1.2、运行阶段member异常恢复

假设一个节点etcd2异常重启,可以再执行如下命令拉起来

etcd --name etcd2  \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.56:2379 

static配置方式下,且处于运行阶段时,所有--initial-cluster参数没作用,带与不带都没有影响。

 

2、discovery自发现方式(只配置本方地址,其他人地址从中介处获取)

依赖于第三方etcd服务。在“集群建立阶段”各member都向第三方etcd服务注册,也从其获取其他member的信息。就像有个中介一样。

在“集群运行阶段”,对第三方etcd不再有依赖。

 

以私有etcd方式地址做中介为例说明:

2.1、集群建立阶段

a、首先在中介处申请一块地方

有两种方式,私有和官网方式任选其一

  • 私有etcd方式:

    uuidgen 先生成一个标识78b12ad7-2c1d-40db-9416-3727baf686cb

    curl -X PUT http://192.168.1.163:20003/v2/keys/discovery/78b12ad7-2c1d-40db-9416-3727baf686cb/_config/size -d value=3

  • 官网方式:

    curl https://discovery.etcd.io/new?size=3
    返回 https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

b、在各个节点上分别执行

etcd --name etcd0 --initial-advertise-peer-urls http://192.168.2.55:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.55:2379 \
-discovery http://192.168.1.163:20003/v2/keys/discovery/78b12ad7-2c1d-40db-9416-3727baf686cb \
--initial-cluster-state new

etcd --name etcd1 --initial-advertise-peer-urls http://192.168.2.54:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.54:2379 \
-discovery http://192.168.1.163:20003/v2/keys/discovery/78b12ad7-2c1d-40db-9416-3727baf686cb \
--initial-cluster-state new

etcd --name etcd2 --initial-advertise-peer-urls http://192.168.2.56:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.56:2379 \
-discovery http://192.168.1.163:20003/v2/keys/discovery/78b12ad7-2c1d-40db-9416-3727baf686cb \
--initial-cluster-state new

 

2.1、运行阶段member异常恢复

下面两条命令任选其一都可以起来。优选第一条

etcd --name etcd2 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.56:2379

 

etcd --name etcd2 --initial-advertise-peer-urls http://192.168.2.56:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--listen-client-urls http://0.0.0.0:2379 \
--advertise-client-urls http://192.168.2.56:2379 \
-discovery http://192.168.1.163:20003/v2/keys/discovery/78b12ad7-2c1d-40db-9416-3727baf686cb \
--initial-cluster-state existing

 

3、DNS方式 – 暂未研究,不作说明

 

四、etcd集群运行过程中的改配

主要用于故障节点替换,集群扩容需求。

集群运行过程中的改配不区分static和discovery方式。

1、替换的步骤:

比如集群中某一member重启后仍不能恢复时,就需要替换一个新member进来。

a、从集群中删除老member

etcdctl member remove 1609b5a3a078c227

b、向集群中新增新member

etcdctl member add <name> <peerURL> 
例子:敲命令 etcdctl member add etcd2 http://192.168.2.56:2380  后返回如下信息
Added member named etcd2 with ID b7d510356ee2e68b to cluster

ETCD_NAME="etcd2"
ETCD_INITIAL_CLUSTER="etcd0=http://192.168.2.55:2380,etcd2=http://192.168.2.56:2380,etcd1=http://192.168.2.54:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"

c、删除老节点data目录
如果不删除,启动后节点仍旧沿用之前的老id, 其他正常节点不认,不能建立联系

d、在新member上启动etcd进程

 

2、扩容的步骤:

执行上面第b,d两步即可。

 

五、常见使用场景

1、单节点故障

      在该节点重启后数据会自动同步。包括在该节点故障后与恢复前之间新变化的数据。

2、客户对etcd的读写访问

     对读写操作,客户可以从任一节点发起,数据都会同步到整个集群。

     读操作由各个接收member直接处理,写操作由各个接收member转发给leader处理。

3、集群可服务性对故障的容忍度

以3节点集群为例。

结论:

  • 在1个member故障时,即小部分节点故障:      集群处于健康态,读写都正常。
  • 在2个member故障时,即大部分节点故障情况:集群整体状态为”不健康“,剩下的member也为”不健康“。只能read,但不能write,可能是因为剩下的member竞选leader失败,拿不到多数票。
  • 在大部分节点恢复后,集群整体状态为”健康“,每个member也为”健康“

如下例子,终止掉了54和60,就剩下55

root@paas-controller-1:/home/yan# docker exec -it myetcd22 /bin/sh
/ # etcdctl cluster-health
failed to check the health of member 1018ddcc3ad118c8 on http://192.168.2.60:2379: Gethttp://192.168.2.60:2379/health: dial tcp 192.168.2.60:2379: getsockopt: connection refused
member 1018ddcc3ad118c8 is unreachable: [http://192.168.2.60:2379] are all unreachable
member 35d37c0c6139bb9a is unhealthy: got unhealthy result from http://192.168.2.55:2379
failed to check the health of member bd47c147acde4ad7 on http://192.168.2.54:2379: Gethttp://192.168.2.54:2379/health: dial tcp 192.168.2.54:2379: getsockopt: connection refused
member bd47c147acde4ad7 is unreachable: [http://192.168.2.54:2379] are all unreachable
cluster is unhealthy
/ # exit
root@paas-controller-1:/home/yan# curl http://192.168.2.55:2379/v2/keys/message
{"action":"get","node":{"key":"/message","value":"Hello everyone","modifiedIndex":8,"createdIndex":8}}
root@paas-controller-1:/home/yan# 
root@paas-controller-1:/home/yan# 
root@paas-controller-1:/home/yan# curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello world"
{"errorCode":300,"message":"Raft Internal Error","cause":"etcdserver: request timed out","index":0}
root@paas-controller-1:/home/yan# curl http://192.168.2.55:2379/v2/keys/message -XPUT -d value="Hello world"
{"errorCode":300,"message":"Raft Internal Error","cause":"etcdserver: request timed out","index":0}
root@paas-controller-1:/home/yan# 
root@paas-controller-1:/home/yan# curl http://192.168.2.55:2379/health
{"health": "false"}
root@paas-controller-1:/home/yan# curl http://192.168.2.54:2379/health
curl: (7) Failed to connect to 192.168.2.54 port 2379: Connection refused
root@paas-controller-1:/home/yan# curl http://192.168.2.60:2379/health
curl: (7) Failed to connect to 192.168.2.60 port 2379: Connection refused

 

在恢复54节点后:

root@paas-controller-1:/home/yan# curl http://192.168.2.55:2379/health
{"health": "true"}root@paas-controller-1:/home/yan# curl http://192.168.2.54:2379/health
{"health": "true"}root@paas-controller-1:/home/yan# curl http://192.168.2.60:2379/health
curl: (7) Failed to connect to 192.168.2.60 port 2379: Connection refused
root@paas-controller-1:/home/yan# curl http://192.168.2.55:2379/v2/keys/message
{"action":"get","node":{"key":"/message","value":"Hello everyone","modifiedIndex":8,"createdIndex":8}}
root@paas-controller-1:/home/yan# curl http://192.168.2.55:2379/v2/keys/message -XPUT -d value="Hello world"
{"action":"set","node":{"key":"/message","value":"Hello world","modifiedIndex":20,"createdIndex":20},"prevNode":{"key":"/message","value":"Hello everyone","modifiedIndex":8,"createdIndex":8}}
root@paas-controller-1:/home/yan# docker exec -it myetcd22 /bin/sh
/ # etcdctl cluster-health
failed to check the health of member 1018ddcc3ad118c8 on http://192.168.2.60:2379: Gethttp://192.168.2.60:2379/health: dial tcp 192.168.2.60:2379: getsockopt: connection refused
member 1018ddcc3ad118c8 is unreachable: [http://192.168.2.60:2379] are all unreachable
member 35d37c0c6139bb9a is healthy: got healthy result from http://192.168.2.55:2379
member bd47c147acde4ad7 is healthy: got healthy result from http://192.168.2.54:2379
cluster is healthy

4、static方式下增加新member

cluster的member数之前已经根据initial-cluster描述的成员确定下来了,如果不先add member,直接启动etcd的话生成的clusterID和老clusterID不一致,根本加不进去。

后续要增加member走"运行中改配扩容"流程,即先add  member,然后启动新etcd。加入后都是正式member,不存在降为proxy的机制。

 

5、discovery方式下size对新加入节点的限制。

size这个key如果不存在或者不设置有效值,集群所有节点都建不起来。

在集群中已经存在size个member的情况下,以--initial-cluster-state new参数新加入的节点自动降为proxy。通过该proxy可进行读写操作。该proxy不在member列表中。原member之一退出后(member异常和remove member情况下相同),proxy无变化,不会自动加入集群。

要加入群,必须走"运行中改配替换"流程。

 

不执行add member直接启动etcd的情况下自动降为proxy,新加入节点打印如下信息:

2017-01-24 23:35:47.956624 I | etcdmain: stopping listening for peers on http://0.0.0.0:2380
2017-01-24 23:35:47.956637 N | etcdmain: discovery cluster full, falling back to proxy
2017-01-24 23:35:47.956643 N | etcdmain: proxy: this proxy supports v2 API only!
2017-01-24 23:35:47.965691 I | etcdmain: proxy: using peer urls [http://192.168.2.54:2380http://192.168.2.55:2380 http://192.168.2.60:2380
2017-01-24 23:35:47.988806 I | etcdmain: proxy: listening for client requests on http://0.0.0.0:2379
2017-01-24 23:35:47.989190 I | httpproxy: endpoints found ["http://192.168.2.54:2379" "http://192.168.2.60:2379" "http://192.168.2.55:2379"]

 

六、一些可能遇到的问题

1、各节点时钟相差过大导致集群建立不起来

     etcd启动信息中有提示错误信息

 

2、listen-url配为localhost或127.0.0.1导致集群建立不起来

     localhost为127.0.0.1,对应lo接口,只有同一空间内的进程之间才能通过此接口交互。

     分布在三个不同机器上的各member之间通过--initial-advertise-peer-urls地址交互,该地址与lo对应不同的接口。


3、--listen-client-urls配为--initial-advertise-peer-urls地址导致etcdctl工具执行不正常

     两全其美的方法:

     --listen-client-urls http://192.168.2.55:2379,http://localhost:2379 《–用逗号分隔,且不能有空格

 

4、-data-dir目录的问题

     该目录下保存了memberID,clusterID和数据等信息,如果集群归属有变化,一定要先删除该目录。


5、--initial- 前缀类参数的使用

     所有带此前缀的选项在集群启动后就没用了,member故障后再重起不用带,带了也没影响。


七、常用命令:

1、集群member管理类:

命令行:(在任一健康member上执行)

etcdctl  member list  

etcdctl  cluster-health

etcdctl  member  add   <membername>  <advertise-peer-url>

etcdctl  member  remove   <memberID>


RESTful:

curl http://127.0.0.1:2379/v2/members

curl http://10.0.0.10:2379/health

curl http://127.0.0.1:2379/v2/members -XPOST -H "Content-Type: application/json" -d '{"peerURLs":["http://192.168.2.61:2380"]}'

此处不能填name,在启动etcd时填写会更新member的name属性

curl http://127.0.0.1:2379/v2/members/272e204152 -XDELETE

Centos 7.9 安装 ELK8.1.0+MetricBeat 提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 环境 Hyper-V + CentOS 7.9 系统:CentOS 7.9 下载URL:CentOS Mirrors List 虚拟机:Hyper-V 开启方式:开始菜单->启用或关闭Windows功能->Hyper-V 如果无法开启需要根据CPU修改BIOS 一、前期准备: 1.下载ELK+MetircBeat ... 阅读详情

相关推荐

Kubernetes集群部署教程-ETCD集群部署

Etcd 是一个分布式键值存储系统,Kubernetes使用Etcd进行数据存储,所以先准备一个Etcd数据库,为解决Etcd单点故障,应采用集群方式部署

guting18893110463的博客 1738

elasticsearch7.14安装设置密码时报错Setup-passwords: Failed to determine the health of the cluster

/usr/share/elasticsearch/bin# sudo ./elasticsearch-setup-passwords interactive Failed to determine the health of the cluster running at http://172.31.47.37:9200 Unexpected response code [503] from calling GET http://172.31.47.37:9200/_cluster/health?pret.

爱笑才不是傻帽的博客 1万+

使用Statefulset在Kubernetes集群部署etcd集群

随着微服务架构的火爆,Etcd作为服务发现或者分部式存储的基础平台也越来越频繁的出现在我们的视野里。因此对于快速部署一套高可用的Etcd集群的需求也越来越强烈,本次就带领大家一起使用Kubernetes的Statefulset特性快速部署一套Etcd集群。 什么是Kubernetes? Kubernetes 是一个用于容器集群的自动化部署、扩容以及运维的开源平台。 使用Kubernet...

weixin_41480008的博客 1098

安装 elasticsearch 遇到 ERROR: Failed to determine the health of the cluster 问题解决

elasticsearch ERROR: Failed to determine the health of the cluster.

liangbao568的博客 5852

Docker desktop 安装Elasticsearch-单节点

1.2.3.点击小三角启动此时会发现访问127.0.0.1:9200访问不到找到usr/share/elasticsearch/config/elasticsearch.yml文件此时可以访问。

lzz1098666594的博客 2446

ETCD集群部署

ETCD集群部署+flannel 附件 /opt/soft/etcd/etcd-v3.4.4-linux-amd64.tar.gz 下载地址:https://github.com/etcd-io/etcd/releases 服务器 192.168.1.54、192.168.1.65、192.168.1.105 安装 1、解压包(每台机器) ETCD_VER=v3.4.4 cd /opt/soft/...

小单的博客专栏 4996

部署etcd集群

etcd是一个高可用的分布式键值存储系统,是CoreOS(现在隶属于Red Hat)公司开发的一个开源项目。它提供了一个简单的接口来存储和检索键值对数据,并使用Raft协议实现了分布式一致性。etcd广泛应用于Docker、Kubernetes等分布式系统中,用于存储配置信息、服务发现、领导者选举等方面。

sre救赎之路 3254

etcd高可用集群部署

在生产环境中,为了整个集群的高可用,etcd 正常都会集群部署,避免单点故障。

the_coco的博客 2747

Docker desktop 安装Elasticsearch-单节点_error failed to determine the health of the clust

这个到这个步骤的话我就不知道怎么解决了,在网上找了好多。是集群的问题,但是我是自己玩的,单节点就可以了,所以就没有去管这个问题具体怎么解决。此时会出现一个ERROR: Failed to determine the health of the cluster的报错。此时会发现访问127.0.0.1:9200访问不到。还要在注释一下这个集群配置,因为自己做的事单点启动。这个提示是让在ES容器的bin目录下执行这个命令。这个错误是因为给的内存太小了,ES启动不起来。输入docker ps。点击run开始启动。

2401_84159966的博客 858

etcd集群部署、备份还原、etcdctl命令行工具

k8s集群中使用etcd数据库作为数据后端存储,所以本篇来学习etcd。截止目前2023-11月,官网最新版是etcd v3.6,但是3.6版本处于草稿状态,所以官网目前推荐使用最新稳定版本是etcd-v3.5,本篇来学习etcd v3.5版本。分布式、可靠的键值存储,用于存储分布式系统中最关键的数据。

MssGuo的博客 2725

Windows 下 ElasticSearch8.5.1下载安装及使用

ElasticSearch下载安装及使用 前言 Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式的全文搜索引擎,基于restful web接口。Elasticsearch是用Java语言开发的,基于Apache协议的开源项目,是目前最受欢迎的企业搜索引擎。Elasticsearch广泛运用于云计算中,能够达到实时搜索,具有稳定,可靠,快速的特点。 由于是个人开发环...

CodeRain的博客 737

vmware 搭建ES8的常见错误

1. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least 解决方法:很明显,已经提示了内存过少,如果虚拟机是2G内存,是不够的,我关机调成了4G,还是出现这个,然后再用root用户修改/etc/sysctl.conf vm.max_map_count=655360 添加完之后 sysctl -p 立刻生效。 2. max file descriptors [4096] fo..

醉世老翁的博客 4760

K8S核心组件etcd详解(上)

k8s中所有对象的manifest都需要保存到某个地方,这样他们的manifest在api server重启和失败的时候才不会丢失,因此引入了etcd。在k8s中只有api server和etcd直接交互,其它组件都通过api server间接和etcd交互,这样做的好处如下。增强乐观锁系统及验证系统的健壮性方便后续存储的替换,只需修改api server组件的相关接口。etcd是一个响应快、分布式、一致的KV存储,也是k8s存储集群状态和元数据的唯一地方。

singless的博客 2628

高可用集群系列——Etcd集群部署

etcd部署时推荐

Intershark的博客 3140

Rancher 部署etcd“Get https://xxx:2379/health: net/http: TLS handshake timeout

现象 我用rancher 部署k8s集群的时候出现Failed to get /health for host [10.154.12.79]: Get https://xxx:2379/health: net/http: TLS handshake timeout 这一错误. 执行./rke_linux-amd64 -d up --config=cluster.yml 命令打开debug模式发现更多报错信息 WARN[0134] [etcd] host [xxx] failed to check etcd

Kainx 3550
上一篇: C语言对宏的处理
下一篇: [转发]网络虚拟化技术(一): Linux网络虚拟化
yasonan
博客等级 码龄23年 1粉丝 3原创
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值