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 命令界面

  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

4. 进入到etcd容器

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

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

参考资料
  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

物联网架构成长之路(22)-Docker练习之Etcd服务搭建的更多相关文章

  1. 物联网架构成长之路(23)-Docker练习之Elasticsearch服务搭建

    0. 前言 最近基本都是学一些环境配置,和一些中间件的安装与配置.没有实际编写代码.可能看起来有点水,我对自己的学习方式是,先要了解各个中间件的安装配置以及简单使用,理论应用场景,然后我在小项目中,逐 ...

  2. 物联网架构成长之路(25)-Docker构建项目用到的镜像1

    0. 前言 现在项目处于初级阶段,按照规划,先构建几个以后可能会用到的Image,并上传到阿里云的Docker仓库.以后博客中用到的Image,大部分都会用到这几个基础的Image,构建一个简单的物联 ...

  3. 物联网架构成长之路(24)-Docker练习之Compose容器编排

    0.前言 一开始学的之后,是想一步到位直接上Kubernetes(K8s)的,后面没想到,好像有点复杂,有些概念不是很懂.因此学习东西还是要循序渐进,慢慢来.先了解单机编排技术Docker Compo ...

  4. 物联网架构成长之路(28)-Docker练习之MQ中间件(Kafka)

    0. 前言 消息队列MQ,这个在一般的系统上都是会用到的一个中间件,我选择Kafka作为练手的一个中间件,Kafka依赖Zookeeper.Zookeeper安装上一篇博客已经介绍过了. 1. Kaf ...

  5. 物联网架构成长之路(27)-Docker练习之Zookeeper安装

    0. 前言 准备了解一下消息队列MQ,对比了一些开源的中间件,最后选择Kafka作为以后用到的消息队列,消息队列的应用场景及Kafka与其他消息队列的优缺点这里就不细说了,具体的可以参考其他博客说明. ...

  6. 物联网架构成长之路(26)-Docker构建项目用到的镜像2

    0. 前言 前面介绍的都是一些标准的第三方中间件,基本都是有现成的Dockerfile或者Image,不需要我过多的关心,这一篇要介绍一些自己构建的Docker Image了.刚开始学,Dockerf ...

  7. 物联网架构成长之路(44)-Docker私有仓库Harbor

    0. 前言 安装docker.docker-compose,这些在我以前的博客讲过,这里就不继续说明了,有需要的可以参考我之前的博客. https://www.cnblogs.com/wunaozai ...

  8. 物联网架构成长之路(30)-Spring Boot Admin微服务WebUI监控

    0. 前言 一个完整的微服务解决方案包含了许多微服务,基于我们需要观察各个微服务的运行状态,因此Spring Boot 生态提供了Spring Boot Admin 这个组件来实现微服务管理WEB U ...

  9. 物联网架构成长之路(18)-接阿里云OSS服务

    1.申请/购买OSS服务 在阿里云上申请/购买OSS服务, 然后在会得AccessKeyID,AccessKeySecret,bucketName 这三个东西 2.增删改查 在pom.xml文件上增加 ...

随机推荐

  1. SparseArray源码解析

    转载自SparseArray源码解析 No1: Android官方推荐:当使用HashMap(K, V),如果K为整数类型时,使用SparseArray的效率更高. No2: HashMap是使用数组 ...

  2. shell 环境变量

    Ubuntu系统设置的环境变量 .profile .bashrc 在 .profile中 有一段代码: if [ -d "$HOME/bin" ] ; then PATH=&quo ...

  3. supervisor 管理 celery

    安装supervisor [root@ipv6-api ~]# pip3 install  supervisor 生成配置文件 [root@ipv6-api ~]#echo_supervisord_c ...

  4. jquery监听input元素输入

    一般我们监听input内容的变化都是通过onchange()事件来绑定,但这个做法有一个缺陷就是只有当正在被输入的input元素失去焦点时(即鼠标点击了别处)才会触发,而实际上我们往往希望能够满足在用 ...

  5. GCC&&GDB在OI中的介绍

    序言 这本来是用Word写的,但是后来我换了系统所以只能用markdown迁移然后写了...... $\qquad$本文主要投食给那些在Windows下活了很久然后考试时发现需要用命令行来操作时困惑万 ...

  6. 4712: 洪水 基于链分治的动态DP

    国际惯例的题面:看起来很神的样子......如果我说这是动态DP的板子题你敢信?基于链分治的动态DP?说人话,就是树链剖分线段树维护DP.既然是DP,那就先得有转移方程.我们令f[i]表示让i子树中的 ...

  7. [CF896C]Willem, Chtholly and Seniorious(珂朵莉树)

    https://www.cnblogs.com/WAMonster/p/10181214.html 主要用于支持含有较难维护的区间操作与查询的问题,要求其中区间赋值操作(assign())是纯随机的. ...

  8. 洛谷.3391.文艺平衡树(fhq Traep)

    题目链接 //注意反转时先分裂r,因为l,r是针对整棵树的排名 #include<cstdio> #include<cctype> #include<algorithm& ...

  9. 最全的JS判断是否为中文的方法

    第一种代码:EXFCODE:1     function isChinese(temp)2     {3       var re=/[^/u4e00-/u9fa5]/;4       if (re. ...

  10. 处理全站请求编码,无论是GET还是POST,默认是UTF-8

    1.java类: import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;imp ...