我是靠谱客的博主 单纯小懒猪,这篇文章主要介绍etcd docker-compose 跨机器三节点集群部署 手工加入节点,现在分享给大家,希望可以做个参考。

三台服务器组成一个集群,ip分别为 10.100.46.6 10.100.46.7 10.100.46.10 。

启动顺序为 10.100.46.10 =》 10.100.46.6 =》10.100.46.7

主节点 docker-compose文件

10.100.46.10的docker-compose.yml

复制代码
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
version: '2' services: etcd: container_name: etcd-offline-10 image: registry.cn-hangzhou.aliyuncs.com/coreos_etcd/etcd:v3 network_mode: "host" ports: - "2379:2379" - "2380:2380" environment: - TZ=CST-8 - LANG=zh_CN.UTF-8 command: /usr/local/bin/etcd -name etcd-offline-10 -data-dir /etcd-data -advertise-client-urls http://10.100.46.10:2379 -listen-client-urls http://10.100.46.10:2379,http://127.0.0.1:2379 -initial-advertise-peer-urls http://10.100.46.10:2380 -listen-peer-urls http://10.100.46.10:2380 -initial-cluster-token xingchen -initial-cluster-state new volumes: - "/data/etcd/data:/etcd-data"

使用命令 docker-compose up后启动

然后使用本地的 etcdctl进行添加节点的操作(注意:要向集群添加节点再启动节点)

46.10的操作记录

复制代码
1
2
3
4
5
6
[root@localhost etcd]# ./etcdctl member add etcd-offline-6 http://10.100.46.6:2380 Added member named etcd-offline-6 with ID 3bf8c1715d31b529 to cluster ETCD_NAME="etcd-offline-6" ETCD_INITIAL_CLUSTER="etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380" ETCD_INITIAL_CLUSTER_STATE="existing"

然后根据提示在46.6上修改docker-compose文件 增加 -name etcd-offline-6 -initial-cluster etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380 -initial-cluster-state existing
10.100.46.6 上的docker-compose.yml

复制代码
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
version: '2' services: etcd: container_name: etcd-offline-6 image: registry.cn-hangzhou.aliyuncs.com/coreos_etcd/etcd:v3 network_mode: "host" ports: - "2379:2379" - "2380:2380" environment: - TZ=CST-8 - LANG=zh_CN.UTF-8 command: /usr/local/bin/etcd -name etcd-offline-6 -data-dir /etcd-data -advertise-client-urls http://10.100.46.6:2379 -listen-client-urls http://10.100.46.6:2379,http://127.0.0.1:2379 -initial-advertise-peer-urls http://10.100.46.6:2380 -listen-peer-urls http://10.100.46.6:2380 -initial-cluster-token xingchen -initial-cluster etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380 -initial-cluster-state existing volumes: - "/data/etcd/data:/etcd-data"

然后运行docker-compose up 启动节点 在46.10上查看集群状态 etcdctl member list

节点状态

复制代码
1
2
3
4
[root@localhost etcd]# ./etcdctl --endpoint http://10.100.46.6:2379 member list 3bf8c1715d31b529: name=etcd-offline-6 peerURLs=http://10.100.46.6:2380 clientURLs=http://10.100.46.6:2379 isLeader=false 51430d988a335e3c: name=etcd-offline-10 peerURLs=http://10.100.46.10:2380 clientURLs=http://10.100.46.10:2379 isLeader=true

可以看到集群中有两个节点了 然后在增加46.7进入集群

增加46.7

复制代码
1
2
3
4
5
6
[root@localhost etcd]# ./etcdctl member add etcd-offline-7 http://10.100.46.7:2380 Added member named etcd-offline-7 with ID f61051e7f96e81f2 to cluster ETCD_NAME="etcd-offline-7" ETCD_INITIAL_CLUSTER="etcd-offline-6=http://10.100.46.6:2380,etcd-offline-10=http://10.100.46.10:2380,etcd-offline-7=http://10.100.46.7:2380" ETCD_INITIAL_CLUSTER_STATE="existing"

在46.7上修改配置,启动docker容器 docker-compose up

复制代码
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
version: '2' services: etcd: container_name: etcd-offline-7 image: registry.cn-hangzhou.aliyuncs.com/coreos_etcd/etcd:v3 network_mode: "host" ports: - "2379:2379" - "2380:2380" environment: - TZ=CST-8 - LANG=zh_CN.UTF-8 command: /usr/local/bin/etcd -name etcd-offline-7 -data-dir /etcd-data -advertise-client-urls http://10.100.46.7:2379 -listen-client-urls http://10.100.46.7:2379,http://127.0.0.1:2379 -initial-advertise-peer-urls http://10.100.46.7:2380 -listen-peer-urls http://10.100.46.7:2380 -initial-cluster-token xingchen -initial-cluster etcd-offline-6=http://10.100.46.6:2380,etcd-offline-7=http://10.100.46.7:2380,etcd-offline-10=http://10.100.46.10:2380 -initial-cluster-state existing volumes: - "/data/etcd/data:/etcd-data"

在46.10上查看新的集群状态发现已经是三节点了。

三节点状态

复制代码
1
2
3
4
5
[root@localhost etcd]# ./etcdctl --endpoint http://10.100.46.6:2379 member list 3bf8c1715d31b529: name=etcd-offline-6 peerURLs=http://10.100.46.6:2380 clientURLs=http://10.100.46.6:2379 isLeader=false 51430d988a335e3c: name=etcd-offline-10 peerURLs=http://10.100.46.10:2380 clientURLs=http://10.100.46.10:2379 isLeader=true f61051e7f96e81f2: name=etcd-offline-7 peerURLs=http://10.100.46.7:2380 clientURLs=http://10.100.46.7:2379 isLeader=false

在一开始单节点时写入的数据会自动同步到整个集群!

搞定!

最后

以上就是单纯小懒猪最近收集整理的关于etcd docker-compose 跨机器三节点集群部署 手工加入节点的全部内容,更多相关etcd内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部