Windows系统下安装Etcd集群
创始人
2024-11-14 00:07:39

前言

最近在研究etcd,用于解决一个服务的主备切换的问题,工欲善其事必先利其器,先把本地所需的所有环境搭建好。涉及到本地Windows环境的etcd集群的搭建,以及etcd可视化web工具etcd-viewer的搭建。etcd使用go语言开发的,在Windows平台上最终编译成了可执行的exe文件,部署非常容易。

安装etcd集群

下载etcd后,选择对应的版本下载即可,Windows版本解压后文件目录如下:

在同级目录分别创建如下三个启动脚本:

start01.bat

1

2

3

4

5

6

7

8

9

10

11

.\etcd.exe --name etcd01 ^

--data-dir.\data\etcd01 ^

--advertise-client-urls http://127.0.0.1:2379 ^

--listen-client-urls http://127.0.0.1:2379 ^

--listen-peer-urls http://127.0.0.1:2380 ^

--initial-advertise-peer-urls http://127.0.0.1:2380 ^

--initial-cluster-token etcd-cluster-1 ^

--initial-cluster etcd01=http://127.0.0.1:2380,etcd02=http://127.0.0.1:2381,etcd03=http://127.0.0.1:2382 ^

--initial-cluster-state new

pause

start02.bat

1

2

3

4

5

6

7

8

9

10

11

.\etcd.exe --name etcd02 ^

--data-dir.\data\etcd02 ^

--advertise-client-urls http://127.0.0.1:3379 ^

--listen-client-urls http://127.0.0.1:3379 ^

--listen-peer-urls http://127.0.0.1:2381 ^

--initial-advertise-peer-urls http://127.0.0.1:2381 ^

--initial-cluster-token etcd-cluster-1 ^

--initial-cluster etcd01=http://127.0.0.1:2380,etcd02=http://127.0.0.1:2381,etcd03=http://127.0.0.1:2382 ^

--initial-cluster-state new

pause

start03.bat

1

2

3

4

5

6

7

8

9

10

11

.\etcd.exe --name etcd03 ^

--data-dir.\data\etcd03 ^

--advertise-client-urls http://127.0.0.1:4379 ^

--listen-client-urls http://127.0.0.1:4379 ^

--listen-peer-urls http://127.0.0.1:2382 ^

--initial-advertise-peer-urls http://127.0.0.1:2382 ^

--initial-cluster-token etcd-cluster-1 ^

--initial-cluster etcd01=http://127.0.0.1:2380,etcd02=http://127.0.0.1:2381,etcd03=http://127.0.0.1:2382 ^

--initial-cluster-state new

pause

然后在同级目录下创建好对应的data-dir,如/data/etcd01、/data/etcd02、/data/etcd03,创建好后,依次启动start01.bat、start02.bat、start03.bat三个脚本,然后使用etcdctl.exe member list,当输出如下信息时,代表集群创建成功了。

1

2

3

4

E:\runtime\etcd-v3.3.12-windows-amd64>etcdctl.exe member list

19ac17627e3e396f: name=etcd03 peerURLs=http://127.0.0.1:2382 clientURLs=http://127.0.0.1:4379 isLeader=false

bf9071f4639c75cc: name=etcd01 peerURLs=http://127.0.0.1:2380 clientURLs=http://127.0.0.1:2379 isLeader=true

e7b968b9fb1bc003: name=etcd02 peerURLs=http://127.0.0.1:2381 clientURLs=http://127.0.0.1:3379 isLeader=false

如果出现如下的信息,代表可能etcd启动过程阻塞住了,只要在cmd窗口里按下回车键就ok了

1

2

3

E:\runtime\etcd-v3.3.12-windows-amd64>etcdctl.exe member list

client: etcd cluster is unavailable or misconfigured; error #0: dial tcp 127.0.0.1:4001: connectex: No connection could be made because the target machine actively refused it.

; error #1: client: endpoint http://127.0.0.1:2379 exceeded header timeout

安装etcd-viewer

etcd-viewer是一款同时支持v2和v3版本接口的etcd可视化web服务,使用java开发,底层基于jetcd和Apache cxf。etcd-viewer也是etcd官方推荐的一个可视化组件

项目地址:https://github.com/nikfoundas/etcd-viewer

1、etcd-viewer已经提供了docker镜像,并上传到了中央仓库,使用如下docker脚本可以直接运行:

1

docker run -d -p 8080:8080 nikfoundas/etcd-viewer

2、或者下载源码后,导入到IDEA,使用mvn jetty:run运行

3、打包成war包后,丢到tomcat中运行

安装成功后,界面如下

相关内容

热门资讯

裸辞做“一人公司”,我后悔了 去年这个时候,一位以色列程序员正在东南亚旅行。他顺手把一个在脑子里转了很久的想法做成了产品,一个让任...
南京建成国内首个Pre-6G试... 4月21日,2026全球6G技术与产业生态大会在南京开幕。全息互动技术展台前,一名远在北京的工作人员...
超梵求职受邀参加“2025抖音... 超梵求职受邀参加“2025抖音巨量引擎成人教育行业生态大会”,探讨分享优质内容传播,服务万千学员。 ...
摩托罗拉Razr 2026(R... IT之家 4 月 22 日消息,摩托罗拉宣布新一代 Razr 折叠手机将于 4 月 29 日在美国发...
库克卸任,特纳斯领航:苹果新纪... 苹果首席执行官蒂姆·库克将卸任,硬件工程主管约翰·特纳斯将接任,苹果公司今天宣布此事。 库克将在夏季...