goreman管理本地etcd集群
环境:macos
1. 安装etcd
克隆etcd源码
v3.5.0 是etcd版本,想要下载指定版本在此指定即可
$ mkdir $GOPATH/src/github.com/etcd-io $ cd $GOPATH/src/github.com/etcd-io $ git clone -b v3.5.0 https://github.com/etcd-io/etcd.git
编译
$ cd etcd $ ./build.sh
会下载依赖包执行编译,确保网络环境可以下载github上的依赖包
编译成功页面
将etcd添加到系统路径
$ vim ~/.zshrc $ export PATH="$PATH:$GOPATH/src/github.com/etcd-io/etcd/bin" $ source ~/.zshrc
测试etcd是否安装成功
$ etcd --version etcd Version: 3.5.0 Git SHA: 946a5a6f2 Go Version: go1.17.7 Go OS/Arch: darwin/amd64
2. 安装goreman
安装goremane
$ go install github.com/mattn/goreman@latest
检查goreman是否安装成功
$ goreman Tasks: goreman check # Show entries in Procfile goreman help [TASK] # Show this help goreman export [FORMAT] [LOCATION] # Export the apps to another process (upstart) goreman run COMMAND [PROCESS...] # Run a command start stop stop-all restart restart-all list status goreman start [PROCESS] # Start the application goreman version # Display Goreman version Options: -b uint base number of port (default 5000) -basedir string base directory -exit-on-error Exit goreman if a subprocess quits with a nonzero return code -exit-on-stop Exit goreman if all subprocesses stop (default true) -f string proc file (default "Procfile") -logtime show timestamp in log (default true) -p uint port (default 8555) -rpc-server Start an RPC server listening on 0.0.0.0 (default true) -set-ports False to avoid setting PORT env var for each subprocess (default true)
3. 利用goreman启动本地三节点etcd集群
编写Procfile文件,可参考etcd代码库里面的写法
$ cd ~ $ vim Procfile
在Procfile文件中写入以下指令
etcd1: etcd --name infra1 --listen-client-urls http://127.0.0.1:12379 --advertise-client-urls http://127.0.0.1:12379 --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
开始启动etcd集群
$ goreman -f Procfile start
查看集群状态
三个etcd节点分别在12379、22379、32379三个端口来监听请求
$ etcdctl --write-out=table --endpoints=localhost:12379 member list
关闭某个节点
$ goreman run stop etcd2
重启某个节点
$ goreman run restart etcd2
向节点中插入数据
注意要指明一个etcd节点,否则默认向2379端口发送请求,而本地2379是没有etcd节点的
get/watch同理,就是一些etcd的简单命令行操作了,加上终端信息就行
$ etcdctl put hello world --endpoints http://localhost:12379
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理