etcd集群部署(持续更新)

集群部署
切换命令行版本到v3:export ETCDCTL_API=3

本地集群部署
官方工具:goreman。提供基于Procfile配置文件的方式,部署简单。

实际使用时,考虑服务的可用性,一般采用多机集群。本地集群可用于测试时快速搭建服务,具体操作参考官方文档,个人推荐测试时也是用多机集群部署方案。

多机集群
参考自官方文档。共有三种集群部署方案:

Static
etcd Discovery
DNS Discovery
假设要部署的三台机器:

192.168.1.11
192.168.1.12
192.168.1.13
集群配置参数详解:etcd --help查看

–name:当前节点唯一名称

–data-dir:数据存储目录,可用于备份、恢复。

–initial-advertise-peer-urls:用于节点成员间的识别地址。

–initial-cluster:所有集群成员的识别地址,initial-advertise-peer-urls集合。

–initial-cluster-token:集群的唯一标识,token不变,重启时复用集群,否则新建。

–initial-cluster-state:集群状态,新建时填new。

–listen-peer-urls:与其他节点成员间通信的监听地址,≥1。

–listen-client-urls:用于监听客户端请求的地址,≥1。

–advertise-client-urls:用于监听所有请求,广义上的,包括客户端、其他成员、代理等。

  1. 静态部署
    要求:启动前需要知道所有etcd成员地址。

将以下shell脚本(替换HOST_1-3)分别在三台对应的机器上直接执行即可。

#!/bin/bash
set -e

HOST_1=192.168.1.11
HOST_2=192.168.1.12
HOST_3=192.168.1.13
NAME_1=machine-1
NAME_2=machine-2
NAME_3=machine-3

数据存储目录

DATADIR=data.etcd

获取本机ip

IP=ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"

启动时清空旧的数据

rm -fr $DATADIR

获取本机名称

if [[ $IP =~ H O S T 1 ] ] ; t h e n I P = HOST_1 ]]; then IP= HOST1]];thenIP=HOST_1
NAME=${NAME_1}

elif [[ $IP =~ H O S T 2 ] ] ; t h e n I P = HOST_2 ]]; then IP= HOST2]];thenIP=HOST_2
NAME=${NAME_2}

elif [[ $IP =~ H O S T 3 ] ] ; t h e n I P = HOST_3 ]]; then IP= HOST3]];thenIP=HOST_3
NAME=${NAME_3}

else
echo “deploy on incorrected machine:” $IP
exit
fi

启动节点

etcd --name KaTeX parse error: Expected 'EOF', got '\ ' at position 6: NAME \̲ ̲ --data-dir=DATADIR
–initial-advertise-peer-urls http://KaTeX parse error: Expected 'EOF', got '\ ' at position 9: IP:2380 \̲ ̲ --listen-peer…IP:2380 \

注:http://127.0.0.1:2379,允许本地访问,方便操作

–listen-client-urls http://KaTeX parse error: Expected 'EOF', got '\ ' at position 31: …127.0.0.1:2379 \̲ ̲ --advertise-c…IP:2379
–initial-cluster N A M E 1 = h t t p : / / NAME_1=http:// NAME1=http://HOST_1:2380, N A M E 2 = h t t p : / / NAME_2=http:// NAME2=http://HOST_2:2380, N A M E 3 = h t t p : / / NAME_3=http:// NAME3=http://HOST_3:2380
–initial-cluster-token etcd-cluster-01
–initial-cluster-state new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1.1 查看集群成员列表:

etcdctl --endpoints=192.168.1.11:2379,192.168.1.12:2379,192.168.1.13:2379 member list

如果listen-client-urls指定了http://127.0.0.1:2379,则可以简化操作命令:etcdctl member list

8e9e05c52164694d, started, machine-1, http://192.168.1.11:2380, http://192.168.1.11:2379
75e05c5dg64694qs, started, machine-2, http://192.168.1.12:2380, http://192.168.1.12:2379
3kf5c5216469qo5d, started, machine-3, http://192.168.1.13:2380, http://192.168.1.13:2379

1.2 查看集群成员健康状态:

etcdctl --endpoints=192.168.1.11:2379,192.168.1.12:2379,192.168.1.13:2379 endpoint health

如果listen-client-urls指定了http://127.0.0.1:2379,则可以简化操作命令:etcdctl endpoint health

192.168.1.11:2379 is healthy: successfully committed proposal: took = 2.322755ms
192.168.1.12:2379 is healthy: successfully committed proposal: took = 2.322755ms
192.168.1.13:2379 is healthy: successfully committed proposal: took = 2.322755ms

  1. etcd发现部署
    要求:已经存在一个etcd服务,基于此服务创建新的集群。

可以理解为,用一个已有的etcd来管理集群成员的注册信息。
(未完待续)

  1. DNS发现部署
    (未完待续)

作者:清风半夜鸣蝉
来源:CSDN
原文:https://blog.csdn.net/ys5773477/article/details/80144910
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值