概述

etcd 是兼具一致性和高可用性的键值数据库,为云原生架构中重要的基础组件,由CNCF 孵化托管。etcd 在微服务和 Kubernates 集群中不仅可以作为服务注册与发现,还可以作为 key-value 存储的中间件。

先决条件

  • 运行的 etcd 集群个数成员为奇数。
  • etcd 是一个 leader-based 分布式系统。确保主节点定期向所有从节点发送心跳,以保持集群稳定。
  • 保持稳定的 etcd 集群对 Kubernetes 集群的稳定性至关重要。因此,请在专用机器或隔离环境上运行 etcd 集群,以满足所需资源需求]。
  • 确保不发生资源不足。
    集群的性能和稳定性对网络和磁盘 IO 非常敏感。任何资源匮乏都会导致心跳超时,从而导致集群的不稳定。不稳定的情况表明没有选出任何主节点。在这种情况下,集群不能对其当前状态进行任何更改,这意味着不能调度新的 pod。

相关术语

  • Raft:etcd所采用的保证分布式系统强一致性的算法。
  • Node:节点 ,Raft状态机的一个实例,具有唯一标识。
  • Member: 成员,一个etcd实例。承载一个Node,且可为客户端请求提供服务。
  • Cluster:集群,由多个Member构成可以协同工作的etcd集群。
  • Peer:同伴,Cluster中其他成员。
  • Proposal :提议,一个需要完成 raft 协议的请求(例如写请求,配置修改请求)。
  • Client: 向etcd集群发送HTTP请求的客户端。
  • WAL:预写式日志,etcd用于持久化存储的日志格式。
  • snapshot:etcd防止WAL文件过多而设置的快照,存储etcd数据状态。
  • Proxy:etcd的一种模式,为etcd集群提供反向代理服务。
  • Leader:Raft算法中通过竞选而产生的处理所有数据提交的节点。
  • Follower:竞选失败的节点作为Raft中的从属节点,为算法提供强一致性保证。
  • Candidate:当Follower超过一定时间接收不到Leader的心跳时转变为Candidate开始竞选。
  • Term:某个节点成为Leader到下一次竞选时间,称为Ubuntu一个Term。
  • Index:数据项编号。Raft中通过Term和Index来定位数据。

ETCD 部署

源码安装

基于master分支构建etcd

git clone https://github.com/etcd-io/etcd.git
cd etcd
./build # 如脚本格式为dos的,需要将其格式修改为unix,否则报错。

启动命令

--listen-client-urls--listen-peer-urls 不能为域名

--listen-client-urls--advertise-client-urls

 ./etcd --name=etcd \
--data-dir=/var/lib/etcd/ \
--listen-client-urls=https://10.0.0.1:2379 \
--listen-peer-urls=https://10.0.0.1:2380 \
--advertise-client-urls=https://hketcd:2379 \
--initial-advertise-peer-urls=https://hketcd:2380 \
--cert-file="/etc/etcd/pki/server.crt" \
--key-file="/etc/etcd/pki/server.key" \
--client-cert-auth=true \
--trusted-ca-file="/etc/etcd/pki/ca.crt" \
--auto-tls=false \
--peer-cert-file="/etc/etcd/pki/peer.crt" \
--peer-key-file="/etc/etcd/pki/peer.key" \
--peer-client-cert-auth=true \
--peer-trusted-ca-file="/etc/etcd/pki/ca.crt" \
--peer-auto-tls=false

其他方式

  • CentOS 可以使用 yum install etcd -y
  • Ubuntu 可以预构建的二进制文件

安装报错

certificate: x509: certificate specifies an incompatible key usage

原因:此处证书用于serverAuthclientAuth,缺少clientAuth导致

解决:extendedKeyUsage=serverAuth, clientAuth

WARNING: 2020/11/12 14:11:42 grpc: addrConn.createTransport failed to connect to {0.0.0.0:2379  <nil> 0 <nil>}. Err: connection error: desc = "transport: authentication handshake failed: remote error: tls: bad certificate". Reconnecting...
{"level":"warn","ts":"2020-11-12T14:11:46.415+0800","caller":"embed/config_logging.go:198","msg":"rejected connection","remote-addr":"127.0.0.1:52597","server-name":"","error":"tls: failed to verify client certificate: x509: certificate specifies an incompatible key usage"}

原因:证书使用的者不对。

解决:查看subjectAltName 是否与请求地址一致。

error "tls: failed to verify client's certificate: x509: certificate specifies an incompatible key usage", ServerName ""

原因:ETCD_LISTEN_PEER_URLSETCD_LISTEN_CLIENT_URLS 不能用域名

error verifying flags, expected IP in URL for binding (https://hketcd:2380). See 'etcd --help'

error #0: x509: certificate has expired or is not yet valid

原因:证书还未生效

解决:因服务器时间不对导致,校对时间后正常

配置文件详解

config

etcdctl 使用

etcdctl --key-file=/etc/etcd/pki/client.key \
--cert-file=/etc/etcd/pki/client.crt \
--ca-file=/etc/etcd/pki/ca.crt \
--endpoint="https://node01.k8s.test:2379" \
cluster-health member 288506ee270a7733 is healthy: got healthy result from https://node03.k8s.test:2379
member 863156df9b1575d1 is healthy: got healthy result from https://node02.k8s.test:2379
member ff386de9dc0b3c40 is healthy: got healthy result from https://node01.k8s.test:2379

v3 版本客户端使用

export ETCDCTL_API=3

etcdctl --key=/etc/etcd/pki/client.key \
--cert=/etc/etcd/pki/client.crt \
--cacert=/etc/etcd/pki/ca.crt \
--endpoints="https://master.k8s:2379" \
endpoint health etcdctl \
--key=/etc/etcd/pki/client.key \
--cert=/etc/etcd/pki/client.crt \
--cacert=/etc/etcd/pki/ca.crt \
--endpoints="https://master.k8stx.com:2379" \
endpoint status

日志独立

etcd日志默认输出到 /var/log/message 如果想独立日志为一个文件,可以使用rsyslogd过滤器功能,使etcd的日志输出到单独的文件内。

  1. 新建/etc/rsyslog.d/xx.conf文件
  2. 在新建文件内写入内容如下
if $programname == 'etcd' then /var/log/etcd.log
# 停止往其他文件内写入,如果不加此句,会继续往/var/log/message写入。
if $programname == 'etcd' then stop

也可以

if ($programname == 'etcd') then {
action(type="omfile" file="/var/log/etcd.log")
stop
}

etcd install & configuration的更多相关文章

  1. Zabbix 3.4.2 install && Configuration

    原理: 1)zabbix server:负责接收agent发送的报告信息的核心组件,所有配置.统计数据及操作数据都由它组织进行: 2)database storage:专用于存储所有配置信息,以及由z ...

  2. etcd -> Highly-avaliable key value store for shared configuration and service discovery

    The name "etcd" originated from two ideas, the unix "/etc" folder and "d&qu ...

  3. webserver Etcd Cluster / CoreOS etcd / macOS etcd

    s https://coreos.com/etcd/ https://coreos.com/etcd/docs/latest/ macOS mojave etcd 003deMac-mini:~ ma ...

  4. Eclipse Configuration

    *** Date: 2013年9月12日星期四中国标准时间上午8时41分50秒 *** Platform Details: *** System properties:applicationXMI=o ...

  5. Go -- etcd详解(转)

    CoreOS是一个基于Docker的轻量级容器化Linux发行版,专为大型数据中心而设计,旨在通过轻量的系统架构和灵活的应用程序部署能力简化数据中心的维护成本和复杂度.CoreOS作为Docker生态 ...

  6. etcd和flannel实现docker跨物理机通信

    实验目标 跨物理机的容器之间能直接访问docker通过Flannel可以实现各容器间的相互通信,即宿主机和容器,容器和容器之间都能相互通信 实验环境 192.168.3.50 //etcd.flann ...

  7. etcd 与 Zookeeper、Consul 等其它 kv 组件的对比

    基于etcd的分布式配置中心 etcd docs | etcd versus other key-value stores https://etcd.io/docs/v3.4.0/learning/w ...

  8. 一键部署etcd集群管理脚本

    一.编写脚本 1 #!/bin/sh 2 # 安装 3 # ./run.sh etcd03 etcd01=http://192.168.2.44:2380,etcd02=http://192.168. ...

  9. Docker+etcd+flanneld+kubernets 构建容器编排系统(1)

    Docker: Docker Engine, 一个client-server 结构的应用, 包含Docker daemon,一个 用来和daemon 交互的REST API, 一个命令行应用CLI. ...

随机推荐

  1. bash是什么?

    bash shell就是一个bash程序 ​ --解释器,启动器 ​ --解释器: ​ 用户交互输入 如vim 文本文件输入 脚本本质: !/bin/bash !/usr/bin/python 读取方 ...

  2. C++ Primer 查漏补缺 —— C++ 中的各种初始化

    初学者在刚开始读 C++ Primer 的时候,总是容易被书中各种初始化搞得头大:默认初始化.列表初始化.值初始化.类内初始值.构造函数初始值列表.new int 和 new int() 的区别... ...

  3. Data Management Tools(数据管理工具)《一》

    数据管理工具 1.LAS数据集 # Process: LAS 数据集统计数据 arcpy.LasDatasetStatistics_management("", "SKI ...

  4. 熊猫分布密度制图(ArcPy实现)

    一.背景 大熊猫是我国国家级珍惜保护动物,熊猫的生存必须满足一定槽域(独占的猎食与活动范围)条件.因此,科学准确的分析熊猫的分布情况,对合理制定保护措施和评价保护成效具有重要意义. 二.目的 通过练习 ...

  5. 洛谷3119 草鉴定(tarjan)

    题目大意 约翰有\(n\)块草场,编号\(1\)到\(n\),这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从\(1\)号草场出发,最后回到\(1 ...

  6. L1-027 出租 (20 分) java题解

    下面是新浪微博上曾经很火的一张图: 一时间网上一片求救声,急问这个怎么破.其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对 ...

  7. 试题 算法训练 最大最小公倍数 java题解

    资源限制 时间限制:1.0s   内存限制:256.0MB 问题描述 已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少. 输入格式 输入一个正整数N. 输出格式 输出一个整数 ...

  8. FastAPI 学习之路(八)路径参数和数值的校验

    系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...

  9. CompleteFuture实现简单的任务编排实践

    CompleteFuture实现简单的任务编排实践 一:前言 ​ CompleteFuture是java8 新提供的API,是对函数式编程思想的体现,提供了很多的对于函数式编程支持.不止有同步处理功能 ...

  10. Kubernetes Job Controller 原理和源码分析(一)

    概述什么是 JobJob 入门示例Job 的 specPod Template并发问题其他属性 概述 Job 是主要的 Kubernetes 原生 Workload 资源之一,是在 Kubernete ...