美文网首页already
一文学会多节点etcd安装

一文学会多节点etcd安装

作者: sknfie | 来源:发表于2022-07-01 21:41 被阅读0次

1.下载与安装

go env -w GOPROXY=https://goproxy.cn
go get github.com/etcd-io/etcd   
go get github.com/mattn/goreman

go install github.com/etcd-io/etcd          #KV服务
go install github.com/etcd-io/etcd/etcdctl           #读写控件
go install github.com/mattn/goreman      #KV集群管理

cd /usr/local/go/src/goreman
go install github.com/mattn/goreman

2.配置

进入bin目录

cd /usr/local/go/bin

创建Procfile文件

# Use goreman to run `go get github.com/mattn/goreman`
etcd1: 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: 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: 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: 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

3.启动

goreman -f ./Procfile start

4.执行命令

# 添加一个Key,默认缺省endpoints服务为端口2379,可以不用写
etcdctl put mykey "this is a hello world"


# 在2379上读取
etcdctl get mykey

# 在22379上读取
etcdctl --endpoints=http://localhost:22379 get mykey

# 在33379上读
etcdctl --endpoints=http://localhost:32379 get mykey

备注

如果下载不下来

go env -w GOPROXY=https://goproxy.cn
git clone https://github.com/mattn/goreman.git
mv ~/goreman/ /usr/local/go/src
cd /usr/local/go/src/goreman
go install github.com/mattn/goreman

执行成功后,会在/usr/local/go/bin目录下发现goreman,可以将之前下载下来的etcd和etcdctl文件拷贝过来。


bin目录

最后执行启动命令。

相关文章

网友评论

    本文标题:一文学会多节点etcd安装

    本文链接:https://www.haomeiwen.com/subject/hmqhbrtx.html