写点什么

手把手教你 Etcd 的云端部署

  • 2019-10-16
  • 本文字数:2596 字

    阅读完需:约 9 分钟

手把手教你Etcd的云端部署

Etcd 是一个开源的分布式键值存储,它由 CoreOS 团队开发,现在由 Cloud Native Computing Foundation 负责管理。这个词的发音是“et-cee-dee”,表示在多台机器上分发 Unix 系统的“/etc”目录,其中包含了大量的全局配置文件。它是许多分布式系统的主干,为跨服务器集群存储数据提供可靠的方式。它适用于各种操作系统,包括 Linux、BSD 和 OS X。


Etcd 具有下面这些属性:


  • 完全复制:集群中的每个节点都可以使用完整的存档

  • 高可用性:Etcd 可用于避免硬件的单点故障或网络问题

  • 一致性:每次读取都会返回跨多主机的最新写入

  • 简单:包括一个定义良好、面向用户的 API(gRPC)

  • 安全:实现了带有可选的客户端证书身份验证的自动化 TLS

  • 快速:每秒 10000 次写入的基准速度

  • 可靠:使用 Raft 算法实现了存储的合理分布


自从 2014 年成为 Kubernetes 的一部分以来,Etcd 社区呈现指数级的增长。CoreOS、谷歌、Redhat、IBM、思科、华为等等均是 Etcd 的贡献成员。其中 AWS、谷歌云平台和 Azure 等大型云提供商成功在生产环境中使用了 Etcd。


Etcd 在 Kubernetes 中的工作是为分布式系统安全存储关键数据。它最著名的是 Kubernetes 的主数据存储,用于存储配置数据、状态和元数据。由于 Kubernetes 通常运行在几台机器的集群上,因此它是一个分布式系统,需要 Etcd 这样的分布式数据存储。内网部署同一网段情况下访问很方便。


但当集群基于云部署的时候客户端多要跨网络访问集群。今天,我们会专门为大家介绍两个跨网络访问方案:


方案一:每个 Etcd 节点拥有公网 ip,通过指定–advertise-client-urls 参数通过公网 IP 广播地址


方案二:Etcd 节点无公网 ip,通过网关及 ssh tunnel 转发请求


具体实施可参考以下步骤:

集群节点

通过 internetwork 访问,每个 Etcd 节点都有公网 IP

如需要通过 internet 访问 Etcd 集群,必须配置 --advertise-client-urls 为内网 ip 和外网 IP 例如:


–advertise-client-urls http://10.0.64.100:2379,http://125.94.39.48:2380

集群配置

./etcd --name etcd0 --initial-advertise-peer-urls http://10.0.64.100:2380 \  --listen-peer-urls http://0.0.0.0:2380 \  --listen-client-urls http://0.0.0.0:2379  \  --advertise-client-urls http://10.0.64.100:2379,http://125.94.39.48:2380 \  --initial-cluster-token etcd-cluster-1 \  --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \  --initial-cluster-state new >> etcd.log 2>&1 &
复制代码


./etcd --name etcd1 --initial-advertise-peer-urls http://10.0.64.101:2380  \  --listen-peer-urls http://0.0.0.0:2380 \  --listen-client-urls http://0.0.0.0:2379 \  --advertise-client-urls http://10.0.64.101:2379,http://125.94.39.105:2380  \  --initial-cluster-token etcd-cluster-1 \  --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \  --initial-cluster-state new  >> etcd.log 2>&1 &
复制代码


./etcd --name etcd2 --initial-advertise-peer-urls http://10.0.64.102:2380 \  --listen-peer-urls http://0.0.0.0:2380 \  --listen-client-urls  http://0.0.0.0:2379  \  --advertise-client-urls http://10.0.64.102:2379,http://59.37.136.50:2380 \  --initial-cluster-token etcd-cluster-1 \  --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \  --initial-cluster-state new  >> etcd.log 2>&1 &
复制代码

访问集群

export ETCDCTL_API=3
#内网访问etcdctl --endpoints=http://10.0.64.100:2379,http://10.0.64.101:2379,http://10.0.64.102:2379 member list
#公网访问etcdctl --endpoints=http://125.94.39.48:2379,http://125.94.39.105:2379,http://59.37.136.50:2379 member listcurl http://125.94.39.48:2379/v2/keys/message
复制代码


通过网关访问集群,集群无公网 IP,gateway 有公网 IP。

Etcd 集群配置

./etcd --name etcd0 --initial-advertise-peer-urls http://10.0.64.100:2380 \  --listen-peer-urls http://0.0.0.0:2380 \  --listen-client-urls http://0.0.0.0:2379  \  --advertise-client-urls http://10.0.64.100:2379 \  --initial-cluster-token etcd-cluster-1 \  --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \  --initial-cluster-state new >> etcd.log 2>&1 &
复制代码


./etcd --name etcd1 --initial-advertise-peer-urls http://10.0.64.101:2380  \  --listen-peer-urls http://0.0.0.0:2380 \  --listen-client-urls http://0.0.0.0:2379 \  --advertise-client-urls http://10.0.64.101:2379  \  --initial-cluster-token etcd-cluster-1 \  --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \  --initial-cluster-state new  >> etcd.log 2>&1 &
复制代码


./etcd --name etcd2 --initial-advertise-peer-urls http://10.0.64.102:2380 \  --listen-peer-urls http://0.0.0.0:2380 \  --listen-client-urls  http://0.0.0.0:2379  \  --advertise-client-urls http://10.0.64.102:2379 \  --initial-cluster-token etcd-cluster-1 \  --initial-cluster etcd0=http://10.0.64.100:2380,etcd1=http://10.0.64.101:2380,etcd2=http://10.0.64.102:2380 \  --initial-cluster-state new  >> etcd.log 2>&1 &
复制代码

开启 gateway

etcd gateway start --endpoints=http://10.0.64.100:2379,http://10.0.64.101:2379,http://10.0.64.102:2379   >> etcd_gateway.log 2>&1 &
复制代码

验证集群

export ETCDCTL_API=3etcdctl  --endpoints=http://10.0.64.100:2379,http://10.0.64.101:2379,http://10.0.64.102:2379 member listetcdctl  --endpoints=http://127.0.0.1:23790 member list
复制代码

创建 ssh tunnel

#有公网ip地址主机上执行ssh  -g -f -N -L 23690:127.0.0.1:23790 root@127.0.0.1
复制代码

通过公网访问网关

export ETCDCTL_API=3etcdctl  --endpoints=http://157.255.51.197:23690 member listetcdctl  --endpoints=http://157.255.51.197:23690 put foo baretcdctl  --endpoints=http://157.255.51.197:23690 get foo 
复制代码


2019-10-16 23:022879

评论

发布
暂无评论
发现更多内容

Android HTTP通信基础

android 程序员 移动开发

Android 6

android 程序员 移动开发

linux几个不常用但是很有用的命令

入门小站

Linux

8年老Android开发谈:Context都没弄明白凭什么拿高薪?

android 程序员 移动开发

Android 12 启动画面-SplashScreen

android 程序员 移动开发

Android Gradle进阶配置指南

android 程序员 移动开发

Android Jetpack架构开发组件化应用实战

android 程序员 移动开发

【LeetCode】丢失的数字Java题解

Albert

算法 LeetCode 11月日更

5月份,京东 Android开发面经分享!

android 程序员 移动开发

A015-布局之LinearLayout

android 程序员 移动开发

Android AsyncTask源码解析

android 程序员 移动开发

Android Framework学习笔记(六)应用程序进程启动过程

android 程序员 移动开发

在线文本中插入符号工具

入门小站

工具

Android - 弹幕实现原理(附Demo源码)

android 程序员 移动开发

Android 11 中的存储机制更新

android 程序员 移动开发

Android Framework学习笔记(五)应用程序启动过程

android 程序员 移动开发

Android ImageView及其子类 介绍+实例

android 程序员 移动开发

Android JNI 入门(含完整Demo)

android 程序员 移动开发

Andorid Studio 制作欢乐写数字(Timer启动+帧动画)

android 程序员 移动开发

Android ExpandableListView折叠菜单的三层嵌套实现

android 程序员 移动开发

Java自定义注解

程序员架构进阶

Java 注解分析 11月日更

Android JNI QQ 搞怪语音实战 (含完整 Demo)

android 程序员 移动开发

Android Launcher——ui框架

android 程序员 移动开发

Android 118道基础面试题,面试途中不卡题

android 程序员 移动开发

android Activity的Task Affinity lanchMode

android 程序员 移动开发

Android ANR:Application Not Responding详解

android 程序员 移动开发

关于调度器的一些思考

Rayjun

调度器 Go 语言

Activity详解与实现

android 程序员 移动开发

AndroiAndroid程序员最大的悲哀是什么?d程序员最大的悲哀是什么?

android 程序员 移动开发

45天拿下字节跳动Android研发岗offer,竟然有个面试真题库,内幕首次公开!

android 程序员 移动开发

【译】Node.js Buffers 完整指南

废材壶

node.js 大前端

手把手教你Etcd的云端部署_架构_贾世闻_InfoQ精选文章