前言

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

安装etcd集群

下载etcd

下载地址:https://github.com/etcd-io/etcd/releases

选择对应的版本下载即可,Windows版本解压后文件目录如下:
Windows下安装Etcd集群及etcd-viewer - 图1

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

pause

  1. - cluster-2381.cmd
  2. ```powershell
  3. @echo off
  4. echo Starting etcd-cluster-1: 2381
  5. "../etcd.exe" --name etcd02 ^
  6. --data-dir ../data/etcd02 ^
  7. --advertise-client-urls http://127.0.0.1:3379 ^
  8. --listen-client-urls http://127.0.0.1:3379 ^
  9. --listen-peer-urls http://127.0.0.1:2381 ^
  10. --initial-advertise-peer-urls http://127.0.0.1:2381 ^
  11. --initial-cluster-token etcd-cluster-1 ^
  12. --initial-cluster etcd01=http://127.0.0.1:2380,etcd02=http://127.0.0.1:2381,etcd03=http://127.0.0.1:2382 ^
  13. --initial-cluster-state new
  14. pause

pause

  1. - start-cluster.cmd
  2. ```powershell
  3. @echo off
  4. echo Starting Cluster: 2381-2383
  5. pushd %~dp0\Cluster
  6. @start "Etcd (Cluster): 2380" /min cluster-2380.cmd
  7. @start "Etcd (Cluster): 2381" /min cluster-2381.cmd
  8. @start "Etcd (Cluster): 2382" /min cluster-2382.cmd
  9. popd

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

  1. .\etcdctl.exe member list

image.png

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

  1. E:\runtime\etcd-v3.3.12-windows-amd64>etcdctl.exe member list
  2. 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.
  3. ; error #1: client: endpoint http://127.0.0.1:2379 exceeded header timeout

安装etcd-vieweretcd-viewe

etcd-vieweretcd-viewer是一款同时支持v2v3版本接口的etcd可视化web服务,使用java开发,底层基于jetcdApache cxfetcd-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中运行

  3. 安装成功后,界面如下

Windows下安装Etcd集群及etcd-viewer - 图3
etcd-latest.zip

原文链接

http://www.kailing.pub/article/index/arcid/253.html