简介:Etcd 是什么
* etcd是一个分布式可靠的键值存储,用于分布式系统的最关键数据,重点是:
1.*简单*:定义明确,面向用户的API(gRPC)
2.*安全*:具有可选客户端证书身份验证的自动TLS
3.*快速*:基准测试10,000次/秒
4.*可靠*:使用Raft一致性算法分布集群
* etcd是用Go编写的,使用[Raft](https://raft.github.io/)一致性算法来管理高度可用的复制日志。
* etcd被[许多公司](https://github.com/coreos/etcd/blob/master/Documentation/production-users.md)用于[生产](https://github.com/coreos/etcd/blob/master/Documentation/production-users.md),开发团队在关键部署场景中支持它,其中etcd经常与[Kubernetes](http://kubernetes.io/),[locksmith](https://github.com/coreos/locksmith),[vulcand](https://github.com/vulcand/vulcand),[Doorman](https://github.com/youtube/doorman)等许多应用程序配合使用。通过**严格的测试**进一步确保可靠性。
* 有关简单的命令行客户端,请参阅[etcdctl](https://github.com/coreos/etcd/tree/master/etcdctl)(etcdctl --helper)
### 一、ETCD单机部署
##### 1、下载二进制包
https://github.com/coreos/etcd/releases
```
wget https://github.com/etcd-io/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-arm64.tar.gz
```
##### 2、解压缩
```
tar -zxvf etcd-v3.3.12-linux-arm64.tar.gz
```
##### 3、设置环境变量
```
export ETCDPATH="/home/etcd/etcd-v3.3.12-linux-amd64"
export ETCDCTL_API=3
export PATH="$PATH:$ETCDPATH"
```
##### 4、启动etcd
```
etcd --data-dir $ETCDPATH/test_data
```
##### 5、客户端测试
```
etcdctl --endpoints=http://127.0.0.1:2379 put foo bar
etcdctl --endpoints=http://127.0.0.1:2379 get foo
```
```
[root@bogon /]# etcdctl --endpoints=http://127.0.0.1:2379 put foo bar
OK
[root@bogon /]# etcdctl --endpoints=http://127.0.0.1:2379 get foo
foo
bar
```
### 二、docker单机部署ETCD
##### 1、拉取etcd镜像
```
docker pull quay.io/coreos/etcd:v3.3.9
```
##### 2、设置环境变量和监听地址
```
-e ETCDCTL_API=3
-p 2379:2379 -p 2380:2380
```
##### 3、运行etcd容器
```
docker run -d -it --rm \
--name etcd_test \
-e ETCDCTL_API=3 \
-p 2379:2379 \
-p 2380:2380 \
quay.io/coreos/etcd:v3.3.9 \
etcd \
--advertise-client-urls http://0.0.0.0:2379 \
--listen-client-urls http://0.0.0.0:2379
```
容器退出自动删除rm
```
[root@bogon etcd]# docker run -d -it --rm --name etcd_test -e ETCDCTL_API=3 -p 2379:2379 -p 2380:2380 quay.io/coreos/etcd:v3.3.9 etcd --advertise-client-urls http://0.0.0.0:2379 --listen-client-urls http://0.0.0.0:2379
ca444c094b6bf00b47726b0dee600620d3962cd0fb78d224db9fae12da94dc13
```
容器停止总是重启
```
[root@ansible-server ~]# docker run -d -it --restart=always --name etcd1 -e ETCDCTL_API=3 -p 2379:2379 -p 2380:2380 quay.io/coreos/etcd:v3.3.9 etcd --advertise-client-urls http://0.0.0.0:2379 --listen-client-urls http://0.0.0.0:2379
199b521dcdd1a742701350c8024dd76c179db2ded0d05a40dd44adfd14f2fb27
```
其他状态:
* no,默认策略,在容器退出时不重启容器
* on-failure,在容器非正常退出时(退出状态非0),才会重启容器
* on-failure:3,在容器非正常退出时重启容器,最多重启3次
* always,在容器退出时总是重启容器
* unless-stopped,在容器退出时总是重启容器,但是不考虑在Docker守护进程启动时就已经停止了的容器
```
[root@bogon etcd]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ca444c094b6b quay.io/coreos/etcd:v3.3.9 "etcd --advertise-..." 4 seconds ago Up 3 seconds 0.0.0.0:2379-2380->2379-2380/tcp etcd_test
```
##### 4、客户端测试
```
etcdctl --endpoints=http://127.0.0.1:2379 put foo bar
etcdctl --endpoints=http://127.0.0.1:2379 get foo
```
```
[root@bogon etcd]# etcdctl --endpoints=http://127.0.0.1:2379 put foo bar
OK
[root@bogon etcd]# etcdctl --endpoints=http://127.0.0.1:2379 get foo
foo
bar
[root@bogon etcd]# etcdctl --endpoints=http://127.0.0.1:2379 put foo bar1
OK
[root@bogon etcd]# etcdctl --endpoints=http://127.0.0.1:2379 get foo
foo
bar1
```
### 三、Etcd本地集群(使用goreman管理)
#### 1、下载etcd二进制包&&设置环境变量&&参考Etcd单机部署
#### 2、安装goreman,安装goreman前需要安装go环境和git。
#### 3、安装go环境
```
wget https://studygolang.com/dl/golang/go1.10.1.linux-amd64.tar.gz
tar -xvf go1.10.1.linux-amd64.tar.gz
vim /etc/profile
export GOROOT=/home/go/go
export GOPATH=/home/go/data
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source /etc/profile
```
#### 4、安装git
```
yum -y install git
```
#### 5、安装 goreman
```
go get github.com/mattn/goreman
```
下载后的文件在```export GOPATH=/home/go/data```设置的路径中
#### 6、编写Procfile(管理集群)
[https://github.com/coreos/etcd/blob/master/Procfile](https://github.com/coreos/etcd/blob/master/Procfile)
#### 7、启动etcd(goreman runlist)
```
goreman -f Procfile start
```
### 四、docker cluster(集群)
#### 8、etcd集群
```
docker pull busybox
```
##### docker netword
```
#docker network create etcd_cluster
docker network create --subnet 172.16.3.0/16 etcd_cluster
docker network inspect etcd_cluster
#docker network rm etcd_cluster
docker run -itd --rm --network etcd_cluster --ip 172.16.3.0 --name test busybox
```
```
docker network ls
docker network rm etcd_cluster
```
#### 9、etcd cluster
```
# etcd1
docker run -itd --restart=always \
--network etcd_cluster \
--ip 172.16.3.31 \
--hostname etcd1 \
--name etcd1 \
-e ETCDCTL_API=3 \
-p 12379:2379 \
-p 12380:2380 \
quay.io/coreos/etcd:v3.3.9 \
etcd --name etcd1 \
--initial-advertise-peer-urls http://172.16.3.31:2380 \
--listen-peer-urls http://172.16.3.31:2380 \
--listen-client-urls http://172.16.3.31:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.16.3.31:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster etcd1=http://172.16.3.31:2380,etcd2=http://172.16.3.32:2380,etcd3=http://172.16.3.33:2380 \
--initial-cluster-state new
# etcd2
docker run -itd --restart=always \
--network etcd_cluster \
--ip 172.16.3.32 \
--hostname etcd2 \
--name etcd2 \
-e ETCDCTL_API=3 \
-p 22379:2379 \
-p 22380:2380 \
quay.io/coreos/etcd:v3.3.9 \
etcd --name etcd2 \
--initial-advertise-peer-urls http://172.16.3.32:2380 \
--listen-peer-urls http://172.16.3.32:2380 \
--listen-client-urls http://172.16.3.32:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.16.3.32:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster etcd1=http://172.16.3.31:2380,etcd2=http://172.16.3.32:2380,etcd3=http://172.16.3.33:2380 \
--initial-cluster-state new
# etcd3
docker run -itd --restart=always \
--network etcd_cluster \
--ip 172.16.3.33 \
--hostname etcd3 \
--name etcd3 \
-e ETCDCTL_API=3 \
-p 32379:2379 \
-p 32380:2380 \
quay.io/coreos/etcd:v3.3.9 \
etcd --name etcd3 \
--initial-advertise-peer-urls http://172.16.3.33:2380 \
--listen-peer-urls http://172.16.3.33:2380 \
--listen-client-urls http://172.16.3.33:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://172.16.3.33:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster etcd1=http://172.16.3.31:2380,etcd2=http://172.16.3.32:2380,etcd3=http://172.16.3.33:2380 \
--initial-cluster-state new
# client
#进入容器
docker exec -it etcd1 bin/sh
#客户端测试
etcdctl --write-out=table --endpoints=http://127.0.0.1:2379 member list
etcdctl --endpoints=http://127.0.0.1:2379 put foo bar
etcdctl --endpoints=http://127.0.0.1:2379 get foo
#测试结果如下
[root@bogon ~]# docker exec -it etcd1 bin/sh
/ # etcdctl --write-out=table --endpoints=http://127.0.0.1:2379 member list
+------------------+---------+-------+-------------------------+-------------------------+
| ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS |
+------------------+---------+-------+-------------------------+-------------------------+
| c26d6ba798c079c | started | etcd3 | http://172.16.3.33:2380 | http://172.16.3.33:2379 |
| 4631df2115e1ef72 | started | etcd2 | http://172.16.3.32:2380 | http://172.16.3.32:2379 |
| a92fe5422902bc40 | started | etcd1 | http://172.16.3.31:2380 | http://172.16.3.31:2379 |
+------------------+---------+-------+-------------------------+-------------------------+
/ # etcdctl --endpoints=http://127.0.0.1:2379 put foo bar
OK
/ # etcdctl --endpoints=http://127.0.0.1:2379 get foo
foo
bar
#docker ps
[root@bogon docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5988c4443eb5 quay.io/coreos/etcd:v3.3.9 "etcd --name etcd3..." 37 seconds ago Up 36 seconds 0.0.0.0:32379->2379/tcp, 0.0.0.0:32380->2380/tcp etcd3
d4fdda6400cc quay.io/coreos/etcd:v3.3.9 "etcd --name etcd2..." 44 seconds ago Up 44 seconds 0.0.0.0:22379->2379/tcp, 0.0.0.0:22380->2380/tcp etcd2
af86e5fd2ae5 quay.io/coreos/etcd:v3.3.9 "etcd --name etcd1..." 53 seconds ago Up 52 seconds 0.0.0.0:2379-2380->2379-2380/tcp etcd1
```
- Linux
- linux常用命令
- awk
- cp
- scp
- mv
- screen工具
- rsync
- Linux设置静态IP
- vim常用
- ssh免密登录
- linux挂载磁盘和开机自动挂载
- 文件的时间戳
- 重定向
- 防火墙
- Vultr 服务器利用快照更换IP
- ss
- node-yarn
- ES安装向导
- lnmp/lamp
- windows安装mysql
- windows安装nginx
- Let'sEncrypt 免费通配符/泛域名SSL证书
- 开机自动挂载硬盘
- 普通用户提权
- ELK日志分析系统
- Docker
- docker
- centos7安装docker
- Centos7安装redis
- CentOS 7 使用Docker搭建Nginx
- CentOS 7 使用Docker搭建Jenkins
- CentOS 7 使用Docker搭建Zookeeper
- CentOS 7 使用Docker搭建Tomcat
- CentOS 7 使用Docker搭建Mysql
- CentOS 7 使用Docker搭建PHP环境
- 使用docker搭建Swagger
- docker阿里云私有仓库
- docker zookeeper集群
- docker部署ES
- docker之java容器运行外置springboot-jar
- docker部署owncloud云盘
- ETCD
- centos7部署etcd节点
- Dockerfile
- Docker-compose
- gitlab.yml
- db.yml
- 安装docker-compose
- gitlab-docker-compose.yml
- nginx-docker-compose.yml
- Mysql
- mysql开启远程访问及相关权限控制
- mysql授权
- mysql快速导出导入大数据
- mysql单机备份
- binlog日志
- shell
- 经典案例
- 俄罗斯方块游戏
- 系统初始化
- 服务器监控
- go基础环境
- shell.监控日志.elk
- shell.检查各服务脚本
- shell.删除文件脚本
- shell.守护进程
- shell.数据库
- shell.Ansible
- shell.dev
- shell.ftp环境
- shell.docker环境
- shell.k8s环境
- k8s.二进制安装
- K8s.一主多从
- k8s.三主两从高可用
- k8s.检查服务与配置
- k8s.jenkins
- k8s.gitlab
- go-install.sh
- jenkins-install.sh
- node-install.sh
- redis-install.sh
- zabbix-install.sh
- zabbix-dockerfile.sh
- nginx-install.sh
- shell变量
- 用户自定义变量
- 环境变量
- shell特殊变量
- shell条件判断
- 流程控制
- shell运算符
- Shell _printf
- shell_test
- shell函数
- 输出重定向
- 网络相关
- 安全相关
- 堡垒机部署
- 区块链威胁情报共享平台
- 签名与验签
- 浅谈区块链
- 智能合约
- 黄金币GTF智能合约
- 节点
- 以太坊公链私链geth同步
- 比特节点同步
- BTC节点错误解决方法
- eth硬分叉
- omni钱包节点搭建
- 架构
- K8s
- 搭建k8s集群完整篇
- 二进制部署k8s
- Devops
- git
- Jenkins
- svn
- 禅道
- CI/CD
- docker+jenkins+golang持续集成持续交付(CI/CD)
- 项目部署
- config.env
- docker-compose.yml
- Dockerfile模板
- .dockerignore
- run.sh
- nginx.conf模板
- 跨域
- jenkins配置
- 测试
- Python