菜鸟笔记
提升您的技术认知

windows系统下etcd的安装与使用-ag真人游戏

一、简介

  etcd是一个分布式一致性键值存储,其主要用于分布式系统的共享配置和服务发现。

  etcd由go语言编写

二、下载并安装

  1.下载地址:

  releases · etcd-io/etcd · github

2. 将压缩文件解压到指定文件夹

 解压后的目录如下:

 

其中etcd.exe是服务端,etcdctl.exe是客户端

二、简单实用

1. 点击etcd.exe运行etcd服务

2. 客户端是有etcdctl来执行命令的

  1)帮助文档

  

  在安装目录命令提示符中执行 etcdctl help 可以查看etcdctl的基本命令如下:

name:
   etcdctl - a simple command line client for etcd.
usage:
   etcdctl [global options] command [command options] [arguments...]
version:
   3.3.8
commands:
     backup          backup an etcd directory
     cluster-health  check the health of the etcd cluster
     mk              make a new key with a given value
     mkdir           make a new directory
     rm              remove a key or a directory
     rmdir           removes the key if it is an empty directory or a key-value pair
     get             retrieve the value of a key
     ls              retrieve a directory
     set             set the value of a key
     setdir          create a new directory or update an existing directory ttl
     update          update an existing key with a given value
     updatedir       update an existing directory
     watch           watch a key for changes
     exec-watch      watch a key for changes and exec an executable
     member          member add, remove and list subcommands
     user            user add, grant and revoke subcommands
     role            role add, grant and revoke subcommands
     auth            overall auth controls
     help, h         shows a list of commands or help for one command
global options:
   --debug                          output curl commands which can be used to reproduce the request
   --no-sync                        don't synchronize cluster information before sending request
   --output simple, -o simple       output response in the given format (simple, `extended` or `json`) (default: "simple")
   --discovery-srv value, -d value  domain name to query for srv records describing cluster endpoints
   --insecure-discovery             accept insecure srv records describing cluster endpoints
   --peers value, -c value          deprecated - "--endpoints" should be used instead
   --endpoint value                 deprecated - "--endpoints" should be used instead
   --endpoints value                a comma-delimited list of machine addresses in the cluster (default: "http://127.0.0.1:2379,http://127.0.0.1:4001")
   --cert-file value                identify https client using this ssl certificate file
   --key-file value                 identify https client using this ssl key file
   --ca-file value                  verify certificates of https-enabled servers using this ca bundle
   --username value, -u value       provide username[:password] and prompt if password is not supplied.
   --timeout value                  connection timeout per request (default: 2s)
   --total-timeout value            timeout for the command execution (except watch) (default: 5s)
   --help, -h                       show help
   --version, -v                    print the version

2)查看版本号  etcdctl --version

  

3) 由于文档中建议api version的版本设为3

  设置版本set etcdctl_api=3

 

即可设置api version,设置成功后etcdctl help查看版本3和2命令和功能方面有不少的差别

3)通过put和get 存取值

 

存取key为hello,value为world

 

获取key为hello的值

常见的错误

当我们双击可执行文件出现闪退时说明etcd服务无法正常启动,此时我们可以通过在命令提示符中打开执行文件

1.端口被占用

etcd默认使用2379,启动etcd服务时提示2379端口被占用,启动失败

我们看到有个虚拟机的程序占用了2379端口,此时我们可以kill掉占用改端口的程序(如果是不重要的程序可以kill掉的话),或者我们修改etcd服务启动监听的端口

etcd启动如果需要自定义参数的话,需要指定配置文件,并且配置文件的内容需要是json格式,我们创建etcd.conf文件,并且写入监听的端口配置   {"listen-client-urls":"http://localhost:12379"}

我们可以通过指定配置文件启动etcd服务

> etcd.exe --config-file etcd.conf

etcd服务启动正常

当我们自定义了etcd的服务监听端口时,使用etcdctl客户端工具时也需要通过--endpoints=127.0.0.1:12379 参数指定

完美

网站地图