首页 技术 正文
技术 2022年11月21日
0 收藏 369 点赞 3,562 浏览 4057 个字

0. 前言
  时隔多日,前段时间忙完一个可有可无的项目后,又进入摸鱼时间,没有办法,非互联网公司,就是闲得蛋疼。又开始了自学之路。以前入门过Docker,然后又很久没有看了,最近重新看了一下,推荐一下这个人的博客: https://www.cnblogs.com/CloudMan6 写得不错,深入浅出。然后学着测试练习一下,部署Etcd服务当作练手。下面是利用Docker部署一个Etcd单机集群测试环境。顺便回顾一下Docker 基本操作。
  由于Docker更新特别快,需要较新的Linux内核版本,加上墙的原因,有时候安装Docker不是那么顺心,建议保持好心态。IRNG加油!
  可以参考
  https://www.cnblogs.com/wunaozai/p/6936787.html
  https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.1cbe1991CFEvea

 apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y update
apt-get -y install docker-ce

1. 下载Etcd
  在这里 https://github.com/etcd-io/etcd/releases 下载最新二进制包,用Go写的,最近遇到的一些开源软件,Go语言的出镜率有点高啊,是不是有必要入坑了呀!

2. 编写Dockerfile
  既然学了Docker,那么就自己写个Dockerfile来build一个Docker Image,现在etcd最新版是3.3.10

 FROM alpine:3.2
RUN apk add --update ca-certificates openssl tar && \
wget https://github.com/etcd-io/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz && \
tar -zxvf etcd-v3.3.10-linux-amd64.tar.gz && \
mv etcd-v3.3.10-linux-amd64/etcd* /bin/ && \
apk del --purge tar openssl && \
rm -Rf etcd-v3.3.10-linux-amd64* /var/cache/apk/*
VOLUME /data
EXPOSE 2379 2380
CMD ["/bin/etcd"]

  Docker构建

docker build -t etcd:3.3 .

  这里顺便介绍一下如何把Image推送到私有仓库(阿里云)

 docker login registry.cn-shenzhen.aliyuncs.com
docker tag etcd:3.3 registry.cn-shenzhen.aliyuncs.com/wunaozai/etcd:3.3
docker push registry.cn-shenzhen.aliyuncs.com/wunaozai/etcd:3.3 docker pull registry.cn-shenzhen.aliyuncs.com/wunaozai/etcd:3.3

3. 启动

  我这里模拟启动3个Etcd服务,之前需要创建虚拟网卡

docker network create --driver bridge --subnet 172.22.16.0/ --gateway 172.22.16.254 my_net2

  创建etcd服务

 docker run -d --name etcd-client- -p : -p : -v /root/workspace/docker/k8s/etcd/data1/:/data --network my_net2 --ip 172.22.16.1 etcd:3.3 \
      /bin/etcd \
      --data-dir=/data --name node1 \
      --initial-advertise-peer-urls http://172.22.16.1:2380 --listen-peer-urls http://0.0.0.0:2380 \
      --advertise-client-urls http://172.22.16.1:2379 --listen-client-urls http://172.22.16.1:2379,http://127.0.0.1:2379 \
      --initial-cluster-state new --initial-cluster-token docker-etcd \
      --initial-cluster node1=http://172.22.16.1:2380,node2=http://172.22.16.2:2380,node3=http://172.22.16.3:2380 docker run -d --name etcd-client- -p : -p : -v /root/workspace/docker/k8s/etcd/data2/:/data --network my_net2 --ip 172.22.16.2 etcd:3.3 \
      /bin/etcd \
      --data-dir=/data --name node2 \
      --initial-advertise-peer-urls http://172.22.16.2:2380 --listen-peer-urls http://0.0.0.0:2380 \
      --advertise-client-urls http://172.22.16.2:2379 --listen-client-urls http://172.22.16.2:2379,http://127.0.0.1:2379 \
      --initial-cluster-state new --initial-cluster-token docker-etcd \
      --initial-cluster node1=http://172.22.16.1:2380,node2=http://172.22.16.2:2380,node3=http://172.22.16.3:2380 docker run -d --name etcd-client- -p : -p : -v /root/workspace/docker/k8s/etcd/data3/:/data --network my_net2 --ip 172.22.16.3 etcd:3.3 \
      /bin/etcd \
      --data-dir=/data --name node3 \
      --initial-advertise-peer-urls http://172.22.16.3:2380 --listen-peer-urls http://0.0.0.0:2380 \
      --advertise-client-urls http://172.22.16.3:2379 --listen-client-urls http://172.22.16.3:2379,http://127.0.0.1:2379 \
      --initial-cluster-state new --initial-cluster-token docker-etcd \
      --initial-cluster node1=http://172.22.16.1:2380,node2=http://172.22.16.2:2380,node3=http://172.22.16.3:2380

  docker ps -a 命令界面

物联网架构成长之路(22)-Docker练习之Etcd服务搭建

  weaveworks/scope 管理界面 安装参考 https://github.com/weaveworks/scope

 curl -L git.io/scope -o /usr/local/bin/scope
chmod a+x /usr/local/bin/scope
scope launch

物联网架构成长之路(22)-Docker练习之Etcd服务搭建

4. 进入到etcd容器

docker exec -it etcd-client- /bin/sh
etcdctl member list

物联网架构成长之路(22)-Docker练习之Etcd服务搭建

5. API操作
  我们可以对任意一个node节点进行读写,即使容器关闭,这些KV数据都保存在Host主机上的。

curl http://127.0.0.1:2001/v2/keys/hello -XPUT -d value="hello world"
curl http://127.0.0.1:2003/v2/keys/hello

物联网架构成长之路(22)-Docker练习之Etcd服务搭建

参考资料
  https://github.com/etcd-io/etcd
  https://www.cnblogs.com/CloudMan6
  https://www.cnblogs.com/xishuai/p/docker-etcd.html
  https://www.cnblogs.com/wunaozai/p/6936787.html
  https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.1cbe1991CFEvea

本文地址: https://www.cnblogs.com/wunaozai/p/9917488.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844