go+etcd(二): 使用docker模拟etcd集群的创建

4 篇文章 0 订阅
3 篇文章 0 订阅

一. 搭建准备

#创建docker网络
docker network  create etcdnet  --subnet 172.25.0.0/16
#创建配置文件
mkdir -p etcd/conf etcd/data
mkdir -p etcd2/conf etcd2/data
vi etcd/conf/etcd.yml
vi etcd2/conf/etcd.yml

etcd/conf/etcd.yml文件

name: etcd1
data-dir: /etcd/data
listen-client-urls: http://172.25.0.101:2379, http://127.0.0.1:2379
advertise-client-urls: http://172.25.0.101:2379
listen-peer-urls: http://172.25.0.101:2380
initial-advertise-peer-urls: http://172.25.0.101:2380
initial-cluster: etcd1=http://172.25.0.101:2380,etcd2=http://172.25.0.102:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

etcd2/conf/etcd.yml文件

name: etcd2
data-dir: /etcd/data
listen-client-urls: http://172.25.0.102:2379, http://127.0.0.1:2379
advertise-client-urls: http://172.25.0.102:2379
listen-peer-urls: http://172.25.0.102:2380
initial-advertise-peer-urls: http://172.25.0.102:2380
initial-cluster: etcd1=http://172.25.0.101:2380,etcd2=http://172.25.0.102:2380
initial-cluster-token: etcd-cluster-token
initial-cluster-state: new

二. 做一个etcd docker镜像

#实例化容器
docker run --name testgo -it golang:1.12-alpine sh
#进入etcd文件夹
cd etcd33
#要保证etcd和etcdctl是可执行文件
docker cp etcd testgo:/usr/bin && docker cp etcdctl testgo:/usr/bin
#退出容器,快捷键(Ctrl+Q+P)
docker commit testgo etcd:my

三. 创建etcd容器

# 容器1
docker run -d --name etcd1 --network etcdnet --ip 172.25.0.101 -p 23791:2379 -e ETCDCTL_API=3  -v /home/gin/etcd:/etcd etcd:my /usr/bin/etcd --config-file /etcd/conf/etcd.yml
# 容器2
docker run -d  --name etcd2 --network etcdnet --ip 172.25.0.102 -p 23792:2379 -e ETCDCTL_API=3 -v /home/gin/etcd2:/etcd etcd:my  /usr/bin/etcd --config-file  /etcd/conf/etcd.yml
# 查看集群列表
./etcdctl --endpoints http://localhost:23791 member list
# 结果
97f72e8299c69562: name=etcd1 peerURLs=http://172.25.0.101:2380 clientURLs=http://172.25.0.101:2379 isLeader=true
aea8ea6030d288e8: name=etcd2 peerURLs=http://172.25.0.102:2380 clientURLs=http://172.25.0.102:2379 isLeader=false
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值