中小企业网站制作,要塑造什么品牌加快建设博物馆群,济南企业建站哪家做的好,西安专业房产网站建设文章目录 概要一、安装1.1 单点1.2 集群 概要
在微服务中服务发现是必不可少的#xff0c;此时ETCD中间件就是一种可选项#xff0c;其实ETCD除了服务发现功能#xff0c;还有#xff1a;
元数据存储#xff0c;比如存储服务配置等数据#xff0c;以实现配置中心化此时ETCD中间件就是一种可选项其实ETCD除了服务发现功能还有
元数据存储比如存储服务配置等数据以实现配置中心化进行统一的有版本记录的变更管理分布式锁选主master-slave的软件架构中可以通过etcd快速实现选主的功能。
ETCD 采用 raft 算法实现分布式数据的一致性和高可用遵循CP原则支持10 k/s 的并发读写操作。
一、安装
安装的方法有很多
二进制安装yum一键安装docker安装
安装模式有单点和集群两种
1.1 单点
直接yum下最简单了
yum install etcd如果服务器上已经装有docker了可以docker安装
docker pull bitnami/etcd:latest
docker network create app-tier --driver bridge
docker run -d --name etcd-server \--network app-tier \--publish 2379:2379 \--publish 2380:2380 \--env ALLOW_NONE_AUTHENTICATIONyes \--env ETCD_ADVERTISE_CLIENT_URLShttp://etcd-server:2379 \bitnami/etcd:latest1.2 集群
这里采用二进制的方式首先到github下载自己所要的版本本人选的v3.5.11。
ETCD集群部署有三种模式
静态配置ETCD 动态发现DNS发现。
由于是测试使用所以在一台Linux服务器上基于静态配置搭建了个三节点的集群。 配置项指标见官网 节点1
mkdir -p /usr/local/etcd-v3.5.11/etcd1/data
vim /usr/local/etcd-v3.5.11/etcd1/conf.ymlname: etcd1
data-dir: /usr/local/etcd-v3.5.11/etcd1/data
initial-advertise-peer-urls: http://127.0.0.1:2380
listen-peer-urls: http://127.0.0.1:2380
listen-client-urls: http://172.20.101.222:2379,http://127.0.0.1:2379
advertise-client-urls: http://127.0.0.1:2379
initial-cluster-token: test-etcd-cluster
initial-cluster: etcd1http://127.0.0.1:2380,etcd2http://127.0.0.1:2370,etcd3http://127.0.0.1:2360
initial-cluster-state: new节点2
mkdir -p /usr/local/etcd-v3.5.11/etcd2/data
vim /usr/local/etcd-v3.5.11/etcd2/conf.ymlname: etcd2
data-dir: /usr/local/etcd-v3.5.11/etcd2/data
initial-advertise-peer-urls: http://127.0.0.1:2370
listen-peer-urls: http://127.0.0.1:2370
listen-client-urls: http://172.20.101.222:2369,http://127.0.0.1:2369
advertise-client-urls: http://127.0.0.1:2369
initial-cluster-token: test-etcd-cluster
initial-cluster: etcd1http://127.0.0.1:2380,etcd2http://127.0.0.1:2370,etcd3http://127.0.0.1:2360
initial-cluster-state: new节点3
mkdir -p /usr/local/etcd-v3.5.11/etcd3/data
vim /usr/local/etcd-v3.5.11/etcd3/conf.ymlname: etcd2
data-dir: /usr/local/etcd-v3.5.11/etcd3/data
initial-advertise-peer-urls: http://127.0.0.1:2360
listen-peer-urls: http://127.0.0.1:2360
listen-client-urls: http://172.20.101.222:2359,http://127.0.0.1:2359
advertise-client-urls: http://127.0.0.1:2359
initial-cluster-token: test-etcd-cluster
initial-cluster: etcd1http://127.0.0.1:2380,etcd2http://127.0.0.1:2370,etcd3http://127.0.0.1:2360
initial-cluster-state: new启动
/usr/local/etcd-v3.5.11/etcd --config-file /usr/local/etcd-v3.5.11/etcd1/conf.yml
/usr/local/etcd-v3.5.11/etcd --config-file /usr/local/etcd-v3.5.11/etcd2/conf.yml
/usr/local/etcd-v3.5.11/etcd --config-file /usr/local/etcd-v3.5.11/etcd2/conf.yml默认的etcdctrl使用的是v2版本的API我们需要设置环境变量来使用v3版本的API
//window
set ETCDCTL_API3
//linux
export ETCDCTL_API3验证
[roottest etcd-v3.5.11]# /usr/local/etcd-v3.5.11/etcdctl put /test/hello helloworld
OK
[roottest etcd-v3.5.11]# /usr/local/etcd-v3.5.11/ get /test/hello
/test/hello
helloworld
至此就可以用于测试使用了当然还支持配置校验证书等功能。