资讯专栏INFORMATION COLUMN

分布式 key-value 存储系统 etcd 的安装备忘

isaced / 1226人阅读

摘要:地址这里介绍集群的启动方式,假设我们有两台机器机器一机器二注两台机器无需建立互信下载从页面下载最新版本这里下载当前年月日最新版本,解压并进入目录注集群中的每一台机器都需进行该操作。

由于 etcd 的安装、启动等过程与官方文档所说的有些不同,这里备忘以免重复采坑。

Github 地址:https://github.com/coreos/etcd

这里介绍集群的启动方式,假设我们有两台机器:

机器一:192.168.33.10
机器二:192.168.33.11

注:两台机器无需建立 SSH 互信

1. 下载

从 Github release 页面下载最新版本:Releases · coreos/etcd · GitHub

这里下载当前( 2018 年 07 月 01 日 )最新版本,Linux amd64:https://github.com/coreos/etc...

解压并进入目录:

tar -zvxf etcd-v3.3.8-linux-amd64.tar.gz

cd etcd-v3.3.8-linux-amd64

注:集群中的每一台机器都需进行该操作。

2. 启动

官方文档:Install etcd | Get Started with etcd | CoreOS

根据官网文档的介绍,我们可以使用参数或配置文件启动,以下分别介绍这两种方式。

2.1 通过参数启动

注:以下使用 nohup,使其以后台方式运行

2.1.1 在 192.168.33.10 中启动
nohup ./etcd --name my-etcd-1 
--listen-client-urls http://192.168.33.10:2379 
--advertise-client-urls http://192.168.33.10:2379 
--listen-peer-urls http://192.168.33.10:2380 
--initial-advertise-peer-urls http://192.168.33.10:2380 
--initial-cluster my-etcd-1=http://192.168.33.10:2380,my-etcd-2=http://192.168.33.11:2380 
--initial-cluster-token my-etcd-token 
--initial-cluster-state new 
>/dev/null 2>&1 &
2.1.2 在 192.168.33.11 中启动
nohup ./etcd --name my-etcd-2 
--listen-client-urls http://192.168.33.11:2379 
--advertise-client-urls http://192.168.33.11:2379 
--listen-peer-urls http://192.168.33.11:2380 
--initial-advertise-peer-urls http://192.168.33.11:2380 
--initial-cluster my-etcd-1=http://192.168.33.10:2380,my-etcd-2=http://192.168.33.11:2380 
--initial-cluster-token my-etcd-token 
--initial-cluster-state new 
>/dev/null 2>&1 &
2.2 通过配置文件启动

配置文件参考:Install etcd | Get Started with etcd | CoreOS 及 etcd/etcd.conf.yml.sample at master · coreos/etcd · GitHub

我们将配置文件命名为:etcd.conf.yml,并将其置于与 etcd-v3.3.8-linux-amd64 同级目录下。

2.2.1 在 192.168.33.10 中添加配置文件并启动
vim ./etcd.conf.yml

内容为:

name:                        my-etcd-1
listen-client-urls:          http://192.168.33.10:2379
advertise-client-urls:       http://192.168.33.10:2379
listen-peer-urls:            http://192.168.33.10:2380
initial-advertise-peer-urls: http://192.168.33.10:2380
initial-cluster:             my-etcd-1=http://192.168.33.10:2380,my-etcd-2=http://192.168.33.11:2380
initial-cluster-token:       my-etcd-token
initial-cluster-state:       new

然后执行:

nohup ./etcd --config-file ./etcd.conf.yml >/dev/null 2>&1 &
2.2.2 在 192.168.33.11 中添加配置文件并启动
vim ./etcd.conf.yml
name:                        my-etcd-2
listen-client-urls:          http://192.168.33.11:2379
advertise-client-urls:       http://192.168.33.11:2379
listen-peer-urls:            http://192.168.33.11:2380
initial-advertise-peer-urls: http://192.168.33.11:2380
initial-cluster:             my-etcd-1=http://192.168.33.10:2380,my-etcd-2=http://192.168.33.11:2380
initial-cluster-token:       my-etcd-token
initial-cluster-state:       new

然后执行:

nohup ./etcd --config-file ./etcd.conf.yml >/dev/null 2>&1 &
3. 检测启动

按照官方文档所说,我们可以在集群的任意一台节点上,通过执行如下指令检测集群的运行情况:

# 仍然在 etcd-v3.3.8-linux-amd64 目录下

./etcdctl cluster-health

然而,当执行这句指令后,我们会得到如下信息:

[vagrant@192-168-33-10 etcd-v3.3.8-linux-amd64]$ ./etcdctl cluster-health
cluster may be unhealthy: failed to list members
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

这个报错很奇怪,启动时明明指定的不是 127.0.0.1。

查阅了一些资料,最终在 Github issue 中找到了问题所在:

I faced the same situation. After searching, I find etcdctl cmd use default endpoints "http://127.0.0.1:2379,http://127.0.0.1:4001". If etcd start with --listen-client-urls http://HOST_IP:2379, then you can use etcdctl like etcdctl --endpoints "http://HOST_IP:2379" member list

这个 issue 中提供了多种方式,个人感觉最好的解决方式是通过追加 --endopoints 参数:

./etcdctl --endpoints http://192.168.33.10:2379,http://192.168.33.11:2379 cluster-health

当然,--endpoints 参数的值可以只添加其中一台机器,如:

./etcdctl --endpoints http://192.168.33.10:2379 cluster-health

细节可以参考:Etcd2 cluster working but etcdctl broken · Issue #1028 · coreos/bugs · GitHub

这样我们就能发现,etcd 集群已经成功启动了:

[vagrant@192-168-33-10 etcd-v3.3.8-linux-amd64]$ ./etcdctl --endpoints http://192.168.33.10:2379 cluster-health
member 42ab269b4f75b118 is healthy: got healthy result from http://192.168.33.11:2379
member 7118e8ab00eced36 is healthy: got healthy result from http://192.168.33.10:2379
cluster is healthy

当然,我们也可以添加 member list 指令查看:

[vagrant@192-168-33-11 etcd-v3.3.8-linux-amd64]$ ./etcdctl --endpoints http://192.168.33.10:2379 member list
42ab269b4f75b118: name=my-etcd-2 peerURLs=http://192.168.33.11:2380 clientURLs=http://192.168.33.11:2379 isLeader=true
7118e8ab00eced36: name=my-etcd-1 peerURLs=http://192.168.33.10:2380 clientURLs=http://192.168.33.10:2379 isLeader=false
参考链接

linux重定向及nohup不输出的方法 - CSDN博客

etcd/etcd.conf.yml.sample at master · coreos/etcd · GitHub

Etcd2 cluster working but etcdctl broken · Issue #1028 · coreos/bugs · GitHub

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/27343.html

相关文章

  • 谈谈 Docker 网络

    摘要:基于近期学习的内容,整理与网络相关的知识。针对这一问题,采用网络来解决。但这篇博客的重点不在,我们可以在启动时,为其指定一个分布式存储,从而使得我们能够实验网络。 基于近期学习的 Docker 内容,整理与 Docker 网络相关的知识。实验环境:Centos 7.4 Docker 版本如下: Client: Version: 18.03.1-ce API versio...

    mozillazg 评论0 收藏0
  • Kubernetes 尝鲜

    摘要:是谷歌官方根据自己容器经验开源的产品。当然,这不可能是,而且它的底层是替换成了,但是这不能掩盖它解决的问题。因此笔者决定尝试玩玩。不然启动会报错。 背景 容器技术在目前很火,而且确确实实的解决了很多的痛点,但是如果只使用目前 Docker 官方提供的 engine+compose+swarm 方案,是很难再实际生产中使用的。Kubernetes 是谷歌官方根据自己容器经验 Borg 开...

    KunMinX 评论0 收藏0
  • Kubernetes 尝鲜

    摘要:是谷歌官方根据自己容器经验开源的产品。当然,这不可能是,而且它的底层是替换成了,但是这不能掩盖它解决的问题。因此笔者决定尝试玩玩。不然启动会报错。 背景 容器技术在目前很火,而且确确实实的解决了很多的痛点,但是如果只使用目前 Docker 官方提供的 engine+compose+swarm 方案,是很难再实际生产中使用的。Kubernetes 是谷歌官方根据自己容器经验 Borg 开...

    ashe 评论0 收藏0
  • 搭建 etcd 集群 - 暴走漫画容器实践系列 Part3

    摘要:如果用命令行参数,应该将下列参数附在的启动命令后面其中表示这是在从无到有搭建集群。命令行参数环境变量以命令行参数启动方式为例公共服务如果没有已有的集群,也可以用提供的公共服务。 etcd 是一个高可用的分布式 key-value(键值) 存储系统。在暴漫我们用他用来做配置管理和服务发现。 这一次我们主要介绍关于 etcd 集群的搭建与管理。 1. etcd 集群概述 首先我们需要理解,...

    happen 评论0 收藏0
  • TiDB 架构演进和开发哲学

    摘要:从这个阶段开始,我们慢慢摸索出了几个实践中深有体会的开发哲学。你怎么控制每一层的复杂度是非常重要的,特别是对于一个架构师来说,所有的工作都是在去规避复杂度,提升开发效率和稳定性。 本文来自 CSDN《程序员》2017 年 2 月的封面报道。对于一个从零开始的数据库来说:选择什么语言,整体架构怎么做,要不要开源,如何去测试…太多的问题需要去考量。 在本篇文章中,PingCAP 联合创始人...

    phpmatt 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<