etcd入门-(1)安装篇

一、etcd安装

https://github.com/etcd-io/etcd/releases

根据需要下载安装etcd, 确保添加到环境变量

执行 etcd -v 查看安装版本

二、etcd运行

本地运行集群

1.首先安装goreman

bash 复制代码
go install github.com/mattn/goreman@latest

2.准备Procfile

将脚本下载到本地,或者复制下面脚本

https://github.com/etcd-io/etcd/blob/main/Procfile

bash 复制代码
# Use goreman to run `go install github.com/mattn/goreman@latest`
# Change the path of bin/etcd if etcd is located elsewhere

etcd1: bin/etcd --name infra1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
etcd2: bin/etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
etcd3: bin/etcd --name infra3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
#proxy: bin/etcd grpc-proxy start --endpoints=127.0.0.1:2379,127.0.0.1:22379,127.0.0.1:32379 --listen-addr=127.0.0.1:23790 --advertise-client-url=127.0.0.1:23790 --enable-pprof

# A learner node can be started using the below Procfile.learner (uncomment and run)

# Use goreman to run `go install github.com/mattn/goreman@latest`

# 1. Start the cluster using Procfile
# 2. Add learner node to the cluster
#   % etcdctl member add infra4 --peer-urls="http://127.0.0.1:42380" --learner=true

# 3. Start learner node with goreman
# Change the path of bin/etcd if etcd is located elsewhere

# uncomment below to setup

# etcd4: bin/etcd --name infra4 --listen-client-urls http://127.0.0.1:42379 --advertise-client-urls http://127.0.0.1:42379 --listen-peer-urls http://127.0.0.1:42380 --initial-advertise-peer-urls http://127.0.0.1:42380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra4=http://127.0.0.1:42380,infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state existing --enable-pprof --logger=zap --log-outputs=stderr

# 4. The learner node can be promoted to voting member by the command
#   % etcdctl member promote <memberid>

注意根据 etcd位置修改脚本 bin/etcd

  1. 执行goreman start
bash 复制代码
➜  ~ goreman start
21:52:15 etcd1 | Starting etcd1 on port 5000
21:52:15 etcd2 | Starting etcd2 on port 5100
21:52:15 etcd3 | Starting etcd3 on port 5200

可以看到etcd已经运行起来了

测试一下数据

bash 复制代码
➜  ~ etcdctl put num   1
OK
➜  ~ etcdctl get num
num
1
相关推荐
Edingbrugh.南空11 分钟前
Hadoop高可用集群搭建
大数据·hadoop·分布式
Bug退退退1231 小时前
RabbitMQ 高级特性之重试机制
java·分布式·spring·rabbitmq
在肯德基吃麻辣烫2 小时前
《Redis》缓存与分布式锁
redis·分布式·缓存
亲爱的非洲野猪2 小时前
Kafka消息积压全面解决方案:从应急处理到系统优化
分布式·kafka
掘金-我是哪吒3 小时前
分布式微服务系统架构第157集:JavaPlus技术文档平台日更-Java多线程编程技巧
java·分布式·微服务·云原生·架构
掘金-我是哪吒3 小时前
分布式微服务系统架构第155集:JavaPlus技术文档平台日更-Java线程池实现原理
java·分布式·微服务·云原生·架构
Bug退退退12313 小时前
RabbitMQ 高级特性之死信队列
java·分布式·spring·rabbitmq
prince0514 小时前
Kafka 生产者和消费者高级用法
分布式·kafka·linq
菜萝卜子15 小时前
【Project】基于kafka的高可用分布式日志监控与告警系统
分布式·kafka
程序员爱钓鱼21 小时前
Go语言项目工程化 — 常见开发工具与 CI/CD 支持
开发语言·后端·golang·gin