CentOS7安装ETCD

使用安装脚步

ETCD_VER=v3.4.14# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GITHUB_URL}rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
rm -rf /tmp/etcd && mkdir -p /tmp/etcdcurl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd --strip-components=1
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz/tmp/etcd/etcd --version
/tmp/etcd/etcdctl version

下图为执行上述脚步时的下载过程

将上述脚步保存为etcd_install.sh,设置chmod 755 etcd_install.sh,执行脚步./etcd_install.sh即可将etcd保存到/tmp/etcd/目录中。

从Github上下载并解压安装包

wget https://github.com/coreos/etcd/releases/download/v3.4.14/etcd-v3.4.14-linux-amd64.tar.gz
tar xzvf etcd-v3.4.14-linux-amd64.tar.gz
mv etcd-v3.4.14-linux-amd64 /tmp/etcd
  • 解压后是一些文档和两个二进制文件etcd和etcdctl。etcd是server端,etcdctl是客户端。

测试环境,启动一个单节点的etcd服务,只需要运行etcd命令就行。

./etcd

启动etcd服务:

配置信息

为了可以使用系统命令运行etcd,将文件夹下的二进制文件复制到bin下

cp /tmp/etcd/etcd* /usr/local/bin/

设定etcd配置文件

mkdir -p /var/lib/etcd/
mkdir -p /opt/etcd/config/
chmod 700 /var/lib/etcd #注意修改权限,否则无法启动

创建etcd配置文件

cat <<EOF | sudo tee /opt/etcd/config/etcd.conf
#节点名称
ETCD_NAME=$(hostname -s)
#数据存放位置
ETCD_DATA_DIR=/var/lib/etcd
EOF

创建systemd配置文件

cat <<EOF | sudo tee /etc/systemd/system/etcd.service[Unit]
Description=Etcd Server
Documentation=https://github.com/coreos/etcd
After=network.target[Service]
User=root
Type=notify
EnvironmentFile=-/opt/etcd/config/etcd.conf
ExecStart=/tmp/etcd/etcd
Restart=on-failure
RestartSec=10s
LimitNOFILE=40000[Install]
WantedBy=multi-user.target
EOF

ExecStart是etcd的启动路径,EnvironmentFile是etcd的配置文件存放路径,根据你的情况修改一下

启动etcd

systemctl daemon-reload && systemctl enable etcd && systemctl start etcd

基本操作

etcdctl -h
NAME:etcdctl - A simple command line client for etcd3.USAGE:etcdctl [flags]VERSION:3.4.10API VERSION:3.4COMMANDS:alarm disarm       Disarms all alarmsalarm list        Lists all alarmsauth disable        Disables authenticationauth enable      Enables authenticationcheck datascale       Check the memory usage of holding data for different workloads on a given server endpoint.check perf        Check the performance of the etcd clustercompaction     Compacts the event history in etcddefrag            Defragments the storage of the etcd members with given endpointsdel         Removes the specified key or range of keys [key, range_end)elect            Observes and participates in leader electionendpoint hashkv     Prints the KV history hash for each endpoint in --endpointsendpoint health      Checks the healthiness of endpoints specified in `--endpoints` flagendpoint status        Prints out the status of endpoints specified in `--endpoints` flagget         Gets the key or a range of keyshelp         Help about any commandlease grant       Creates leaseslease keep-alive  Keeps leases alive (renew)lease list        List all active leaseslease revoke      Revokes leaseslease timetolive  Get lease informationlock           Acquires a named lockmake-mirror        Makes a mirror at the destination etcd clustermember add        Adds a member into the clustermember list       Lists all members in the clustermember promote      Promotes a non-voting member in the clustermember remove        Removes a member from the clustermember update      Updates a member in the clustermigrate          Migrates keys in a v2 store to a mvcc storemove-leader      Transfers leadership to another etcd cluster member.put         Puts the given key into the storerole add       Adds a new rolerole delete      Deletes a rolerole get      Gets detailed information of a rolerole grant-permission    Grants a key to a rolerole list     Lists all rolesrole revoke-permission   Revokes a key from a rolesnapshot restore   Restores an etcd member snapshot to an etcd directorysnapshot save      Stores an etcd node backend snapshot to a given filesnapshot status     Gets backend snapshot status of a given filetxn         Txn processes all the requests in one transactionuser add       Adds a new useruser delete      Deletes a useruser get      Gets detailed information of a useruser grant-role      Grants a role to a useruser list        Lists all usersuser passwd      Changes password of useruser revoke-role    Revokes a role from a userversion           Prints the version of etcdctlwatch          Watches events stream on keys or prefixesOPTIONS:--cacert=""             verify certificates of TLS-enabled secure servers using this CA bundle--cert=""                  identify secure client using this TLS certificate file--command-timeout=5s         timeout for short running command (excluding dial timeout)--debug[=false]              enable client-side debug logging--dial-timeout=2s              dial timeout for client connections-d, --discovery-srv=""            domain name to query for SRV records describing cluster endpoints--discovery-srv-name=""         service name to query when using DNS discovery--endpoints=[127.0.0.1:2379]     gRPC endpoints-h, --help[=false]               help for etcdctl--hex[=false]              print byte strings as hex encoded strings--insecure-discovery[=true]       accept insecure SRV records describing cluster endpoints--insecure-skip-tls-verify[=false] skip server certificate verification (CAUTION: this option should be enabled only for testing purposes)--insecure-transport[=true]     disable transport security for client connections--keepalive-time=2s           keepalive time for client connections--keepalive-timeout=6s            keepalive timeout for client connections--key=""                 identify secure client using this TLS key file--password=""              password for authentication (if this option is used, --user option shouldn't include password)--user=""                 username[:password] for authentication (prompt if password is not supplied)-w, --write-out="simple"          set the output format (fields, json, protobuf, simple, table)

输入、查看、更新、删除k-v:

[root@localhost ~] etcdctl put /testkey "Hello world"
OK
[root@localhost ~] etcdctl get /testkey "Hello world"
/testkey
Hello world
[root@localhost ~] etcdctl put /testkey "Hello"
OK
[root@localhost ~] etcdctl get /testkey "Hello"
/testkey
Hello
[root@localhost ~] etcdctl del /testkey
1

获取json输出:

[root@localhost ~] etcdctl get key1 -w json
{"header":{"cluster_id":14841639068965178418,"member_id":10276657743932975437,"revision":6,"raft_term":2},"kvs":[{"key":"a2V5MQ==","create_revision":5,"mod_revision":5,"version":1,"value":"dmFsdWUx"}],"count":1}
[root@localhost ~] etcdctl get key1
key1
value1
[root@localhost ~] echo dmFsdWUx|base64 -d
value1[root@localhost ~]#

watch
在一个终端运行:

[root@localhost etcd] etcdctl watch key1
PUT
key1
valuex
PUT
key1
valuez

在另一个终端:

[root@localhost ~] etcdctl put key1 valuex
OK
[root@localhost ~] etcdctl put key1 valuez
OK

租约
lease。etcd支持申请定时器,申请一个lease,会返回一个lease ID标识定时器。如果在put一个key的同时携带lease ID,就实现了一个自动过期的key。在etcd中,一个lease可以关联任意多的key,当lease过期后所有关联的key都将被自动删除。

#生成
[root@localhost etcd] etcdctl lease grant 300
lease 694d73749a9d0515 granted with TTL(300s)
#关联到key
[root@localhost etcd] etcdctl put key3 300 --lease=694d73749a9d0515
OK
#维持租约
[root@localhost etcd] etcdctl lease keep-alive 694d73749a9d0515
lease 694d73749a9d0515 keepalived with TTL(300)
#撤销租约
[root@localhost ~] etcdctl lease revoke 694d73749a9d0515
lease 694d73749a9d0515 revoked

Etcd集群搭建

一、etcd介绍:

ETCD 是一个高可用的分布式键值数据库,可用于服务发现。ETCD 采用 raft 一致性算法,基于 Go 语言实现。etcd作为一个高可用键值存储系统,天生就是为集群化而设计的。由于Raft算法在做决策时需要多数节点的投票,所以etcd一般部署集群推荐奇数个节点,推荐的数量为3、5或者7个节点构成一个集群。

二、特点

实际上,etcd作为一个受到Zookeeper与doozer启发而催生的项目,除了拥有与之类似的功能外,更具有以下4个特点{![引自Docker官方文档]}。

三、etcd关键词汇:

四、etcd应用场景:

1、服务发现:

服务发现(Service Discovery)要解决的是分布式系统中最常见的问题之一,即在同一个分布式集群中的进程或服务如何才能找到对方并建立连接。从本质上说,服务发现就是想要了解集群中是否有进程在监听udp或tcp端口,并且通过名字就可以进行查找和连接。

2、消息发布与订阅:

在分布式系统中,最为适用的组件间通信方式是消息发布与订阅机制。具体而言,即构建一个配置共享中心,数据提供者在这个配置中心发布消息,而消息使用者则订阅他们关心的主题,一旦相关主题有消息发布,就会实时通知订阅者。通过这种方式可以实现分布式系统配置的集中式管理与实时动态更新

3、负载均衡:

在分布式系统中,为了保证服务的高可用以及数据的一致性,通常都会把数据和服务部署多份,以此达到对等服务,即使其中的某一个服务失效了,也不影响使用。这样的实现虽然会导致一定程度上数据写入性能的下降,但是却能实现数据访问时的负载均衡。因为每个对等服务节点上都存有完整的数据,所以用户的访问流量就可以分流到不同的机器上。

4、分布式通知与协调:

这里讨论的分布式通知与协调,与消息发布和订阅有些相似。两者都使用了etcd中的Watcher机制,通过注册与异步通知机制,实现分布式环境下不同系统之间的通知与协调,从而对数据变更进行实时处理。实现方式通常为:不同系统都在etcd上对同一个目录进行注册,同时设置Watcher监控该目录的变化(如果对子目录的变化也有需要,可以设置成递归模式),当某个系统更新了etcd的目录,那么设置了Watcher的系统就会收到通知,并作出相应处理。

5、分布式锁:

因为etcd使用Raft算法保持了数据的强一致性,某次操作存储到集群中的值必然是全局一致的,所以很容易实现分布式锁。锁服务有两种使用方式,一是保持独占,二是控制时序。

五、搭建集群:

主机信息:

角色 系统 节点
master CentOS-7 192.168.10.5
node-1 CentOS-7 192.168.10.6
node-2 CentOS-7 192.168.10.7

配置阿里epel源:

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup

mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

安装配置存储etcd(高可用): 

1、在三台安装etcd(集群)、做高可用
[root@node1 ~]# yum -y install etcd
[root@node2 ~]# yum -y install etcd
[root@master ~]# yum -y install etcd[root@master ~]# etcd --version
etcd Version: 3.2.22
Git SHA: 1674e68
Go Version: go1.9.4
Go OS/Arch: linux/amd64
2 配置文件修改
master节点
[root@master ~]# egrep -v "^$|^#" /etc/etcd/etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"   #etcd数据保存目录
ETCD_LISTEN_PEER_URLS="http://192.168.10.5:2380"  #集群内部通信使用的URL
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"   #供外部客户端使用的url
ETCD_NAME="etcd01"      #etcd实例名称
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.10.5:2380"  #广播给集群内其他成员访问的URL
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"      #广播给外部客户端使用的url
ETCD_INITIAL_CLUSTER="etcd01=http://192.168.10.5:2380,etcd02=http://192.168.10.6:2380,etcd03=http://192.168.10.7:2380" #初始集群成员列表
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"  #集群的名称
ETCD_INITIAL_CLUSTER_STATE="new"  #初始集群状态,new为新建集群
node-1
[root@node1 etcd]# egrep -v "^$|^#" /etc/etcd/etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.10.6:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="etcd02"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.10.6:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_INITIAL_CLUSTER="etcd01=http://192.168.10.5:2380,etcd02=http://192.168.10.6:2380,etcd03=http://192.168.10.7:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="exist"
node-2
[root@node2 ~]# egrep -v "^$|^#" /etc/etcd/etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.10.7:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="etcd03"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.10.7:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_INITIAL_CLUSTER="etcd01=http://192.168.10.5:2380,etcd02=http://192.168.10.6:2380,etcd03=http://192.168.10.7:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="exist"

分别进行启动:

[root@master etcd]# systemctl start etcd
[root@master etcd]# systemctl status etcd
● etcd.service - Etcd ServerLoaded: loaded (/usr/lib/systemd/system/etcd.service; disabled; vendor preset: disabled)Active: active (running) since Tue 2019-01-08 17:28:34 CST; 2h 32min agoMain PID: 114077 (etcd)Tasks: 7Memory: 48.7MCGroup: /system.slice/etcd.service└─114077 /usr/bin/etcd --name=etcd01 --data-dir=/var/lib/etcd/default.etcd --listen-client-urls=http://0.0.0.0:2379Jan 08 20:00:08 master etcd[114077]: 4c5d727d37966a87 became candidate at term 16
Jan 08 20:00:08 master etcd[114077]: 4c5d727d37966a87 received MsgVoteResp from 4c5d727d37966a87 at term 16
Jan 08 20:00:08 master etcd[114077]: 4c5d727d37966a87 [logterm: 11, index: 44] sent MsgVote request to 315fd62e577c4037 at term 16
Jan 08 20:00:08 master etcd[114077]: 4c5d727d37966a87 [logterm: 11, index: 44] sent MsgVote request to f617da66fb9b90ad at term 16
Jan 08 20:00:08 master etcd[114077]: 4c5d727d37966a87 received MsgVoteResp from f617da66fb9b90ad at term 16
Jan 08 20:00:08 master etcd[114077]: 4c5d727d37966a87 [quorum:2] has received 2 MsgVoteResp votes and 0 vote rejections
Jan 08 20:00:08 master etcd[114077]: 4c5d727d37966a87 became leader at term 16
Jan 08 20:00:08 master etcd[114077]: raft.node: 4c5d727d37966a87 elected leader 4c5d727d37966a87 at term 16
Jan 08 20:00:09 master etcd[114077]: the clock difference against peer 315fd62e577c4037 is too high [4.285950016s > 1s]
Jan 08 20:00:09 master etcd[114077]: the clock difference against peer f617da66fb9b90ad is too high [4.120954945s > 1s]
[root@master etcd]# netstat -tunlp|grep etcd
tcp        0      0 192.168.10.5:2380       0.0.0.0:*               LISTEN      114077/etcd
tcp6       0      0 :::2379                 :::*                    LISTEN      114077/etcd 

3、etc集群测试

  集群数据操作命令:

查看集群节点
[root@node1 etcd]# etcdctl member list
315fd62e577c4037: name=etcd03 peerURLs=http://192.168.10.7:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
4c5d727d37966a87: name=etcd01 peerURLs=http://192.168.10.5:2380 clientURLs=http://0.0.0.0:2379 isLeader=true
f617da66fb9b90ad: name=etcd02 peerURLs=http://192.168.10.6:2380 clientURLs=http://0.0.0.0:2379 isLeader=false查看集群健康状态:

[root@master etcd]# etcdctl cluster-health
member 315fd62e577c4037 is healthy: got healthy result from http://0.0.0.0:2379
member 4c5d727d37966a87 is healthy: got healthy result from http://0.0.0.0:2379
member f617da66fb9b90ad is healthy: got healthy result from http://0.0.0.0:2379
cluster is healthy

设置键值:

在一个节点设置值
[root@master etcd]# etcdctl set /test/key "test kubernetes"
test kubernetes在另一个节点获取值

[root@node1 etcd]# etcdctl get /test/key
test kubernetes

更新键值:

[root@master etcd]# etcdctl update /test/key "test kubernetes cluster"
test kubernetes cluster[root@node1 etcd]# etcdctl get /test/key
test kubernetes cluster

删除键值:

[root@master etcd]# etcdctl rm /test/key
PrevNode.Value: test kubernetes cluster当键不存在时,会报错
[root@node1 etcd]# etcdctl get /test/key
Error:  100: Key not found (/test/key) [15]

etcd帮助:

[root@master etcd]# etcdctl help
NAME:etcdctl - A simple command line client for etcd.WARNING:Environment variable ETCDCTL_API is not set; defaults to etcdctl v2.Set environment variable ETCDCTL_API=3 to use v3 API or ETCDCTL_API=2 to use v2 API.USAGE:etcdctl [global options] command [command options] [arguments...]VERSION:3.2.22COMMANDS:backup          backup an etcd directorycluster-health  check the health of the etcd clustermk              make a new key with a given valuemkdir           make a new directoryrm              remove a key or a directoryrmdir           removes the key if it is an empty directory or a key-value pairget             retrieve the value of a keyls              retrieve a directoryset             set the value of a keysetdir          create a new directory or update an existing directory TTLupdate          update an existing key with a given valueupdatedir       update an existing directorywatch           watch a key for changesexec-watch      watch a key for changes and exec an executablemember          member add, remove and list subcommandsuser            user add, grant and revoke subcommandsrole            role add, grant and revoke subcommandsauth            overall auth controlshelp, h         Shows a list of commands or help for one command

使用docker-compose搭建etcd集群环境

etcd是一个集群环境,用来管理微服务架构下面的配置管理功能。
A distributed, reliable key-value store for the most critical data of a distributed system.

这篇文章是一个基础步骤如何搭建etcd的docker集群环境。
我们使用docker-compose来搭建如下的etcd集群环境:

  1. 集群包含三个node:etcd1, etcd2, etcd3
  1. 下载consul docker image
$ docker pull quay.io/coreos/etcd
  1. 编辑docker-compose.yaml文件
$ cat docker-compose.yaml
version: '2'
networks:byfn:services:etcd1:image: quay.io/coreos/etcdcontainer_name: etcd1command: etcd -name etcd1 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state newports:- 2379- 2380networks:- byfnetcd2:image: quay.io/coreos/etcdcontainer_name: etcd2command: etcd -name etcd2 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state newports:- 2379- 2380networks:- byfnetcd3:image: quay.io/coreos/etcdcontainer_name: etcd3command: etcd -name etcd3 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state newports:- 2379- 2380networks:- byfn
  1. 启动服务
$ docker-compose up -d
  1. 验证集群的状态

验证从三个node返回的v2/members数据是一样的值。

$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
33785a959d95        quay.io/coreos/etcd   "etcd -name etcd1 ..."   2 hours ago         Up 2 hours          0.0.0.0:32791->2379/tcp, 0.0.0.0:32790->2380/tcp   etcd1
106ba12b1c25        quay.io/coreos/etcd   "etcd -name etcd2 ..."   2 hours ago         Up 2 hours          0.0.0.0:32789->2379/tcp, 0.0.0.0:32788->2380/tcp   etcd2
76cd127439a3        quay.io/coreos/etcd   "etcd -name etcd3 ..."   2 hours ago         Up 2 hours          0.0.0.0:32787->2379/tcp, 0.0.0.0:32786->2380/tcp   etcd3$ curl -L http://127.0.0.1:32787/v2/members
{"members":[{"id":"ade526d28b1f92f7","name":"etcd1","peerURLs":["http://etcd1:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"bd388e7810915853","name":"etcd3","peerURLs":["http://etcd3:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"d282ac2ce600c1ce","name":"etcd2","peerURLs":["http://etcd2:2380"],"clientURLs":["http://0.0.0.0:2379"]}]}$ curl -L http://127.0.0.1:32789/v2/members
{"members":[{"id":"ade526d28b1f92f7","name":"etcd1","peerURLs":["http://etcd1:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"bd388e7810915853","name":"etcd3","peerURLs":["http://etcd3:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"d282ac2ce600c1ce","name":"etcd2","peerURLs":["http://etcd2:2380"],"clientURLs":["http://0.0.0.0:2379"]}]}$ curl -L http://127.0.0.1:32791/v2/members
{"members":[{"id":"ade526d28b1f92f7","name":"etcd1","peerURLs":["http://etcd1:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"bd388e7810915853","name":"etcd3","peerURLs":["http://etcd3:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"d282ac2ce600c1ce","name":"etcd2","peerURLs":["http://etcd2:2380"],"clientURLs":["http://0.0.0.0:2379"]}]}

也可以用命令行工具etcdctl:

$ docker exec -t etcd1 etcdctl member list
ade526d28b1f92f7: name=etcd1 peerURLs=http://etcd1:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
bd388e7810915853: name=etcd3 peerURLs=http://etcd3:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
d282ac2ce600c1ce: name=etcd2 peerURLs=http://etcd2:2380 clientURLs=http://0.0.0.0:2379 isLeader=true$ docker exec -t etcd3 etcdctl -C http://etcd1:2379,http://etcd2:2379,http://etcd3:2379 member list
ade526d28b1f92f7: name=etcd1 peerURLs=http://etcd1:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
bd388e7810915853: name=etcd3 peerURLs=http://etcd3:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
d282ac2ce600c1ce: name=etcd2 peerURLs=http://etcd2:2380 clientURLs=http://0.0.0.0:2379 isLeader=true
  1. 集群的使用

我们往一个node上上传数据,在其他node上就能下载到。

curl -L http://127.0.0.1:32789/v2/keys/foo -XPUT -d value="Hello foo"
curl -L http://127.0.0.1:32789/v2/keys/foo1/foo1 -XPUT -d value="Hello foo1"
curl -L http://127.0.0.1:32789/v2/keys/foo2/foo2 -XPUT -d value="Hello foo2"
curl -L http://127.0.0.1:32789/v2/keys/foo2/foo21/foo21 -XPUT -d value="Hello foo21"curl -L http://127.0.0.1:32787/v2/keys/foo
curl -L http://127.0.0.1:32787/v2/keys/foo2
curl -L http://127.0.0.1:32787/v2/keys/foo2?recursive=true

etcd的详细API请参考相关文档。

参考文档:

https://www.jianshu.com/p/44022c67f117

https://github.com/etcd-io/etcd

https://yq.aliyun.com/articles/623228

https://blog.csdn.net/hxpjava1/article/details/78275995

CentOS7安装ETCD相关推荐

  1. VMware下centos7安装k8s(Kubernetes)多master集群

    上一节:VMware下centos7安装k8s(Kubernetes)集群 1.使用MobaXterm打开多个窗口,进行多窗口同时编辑,已提前改好IP和hostname. 2.修改hosts,用vim ...

  2. CentOS7安装k8s服务--Master节点和Node节点

    CentOS7安装k8s服务 需求是在六台服务器上安装k8s服务,三台master节点,三台node节点,服务器的操作系统是BC-Linux,就当Centos用吧. 先给出大佬的文章(我就是看他的): ...

  3. centos7安装与配置OpenStack-Zun组件(Stein版)

    文章目录 一.基本环境参数 二.controller节点zun安装 2.1 创建数据库 2.2 创建openstack用户.服务.端点 2.3 安装.启动zun服务 2.3.1 创建用户.组 2.3. ...

  4. 搭建 K8S 环境:Centos7安装生产环境可用的K8S集群图文教程指南

    搭建 K8S 环境:Centos7安装生产环境可用的K8S集群图文教程指南 一. K8S 简介 二. K8S 学习的几大拦路虎 2.1 K8S 安装对硬件要求比较高 2.2. K8S 对使用者来说要求 ...

  5. etcd 笔记(02)— etcd 安装(apt 或 yum 安装 、二进制包安装、Docker 安装 etcd、etcd 前端工具etcdkeeper)

    1. 使用 apt 或 yum 安装 etcd 命令如下: sudo apt-get install etcd 或者 sudo yum install etcd 这样安装的缺点是:安装的 etcd 版 ...

  6. Ubuntu 安装 Etcd

    1. 使用软件包安装 curl -L https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.t ...

  7. centos7 nginx配置php7,centos7安装并配置nginx+php,centos7nginx

    centos7安装并配置nginx+php,centos7nginx centos7安装并配置nginx+php 安装nginx yum install nginx 设置nginx开启起动 syste ...

  8. centos7安装配置pgAgent

    centos7安装pgagent: 默认cmake已经安装 编译wxGTK https://excellmedia.dl.sourceforge.net/project/wxwindows/2.8.7 ...

  9. centos7 安装mysql php_Centos7安装mysql与php的方法

    本文主要和大家分享Centos7安装mysql与php的方法,希望能帮助到大家. 相关mysql视频教程推荐:<mysql教程> 官网下载安装mysql-server 依次使用下面三个命令 ...

最新文章

  1. select三级联动 怎么删除前一个的_python测试开发django57.xadmin选项二级联动
  2. Codeforces Round #316 (Div. 2) D. Tree Requests dfs序
  3. 快速了解Scala技术栈
  4. 在ubuntu20.10上搭建SVN Server
  5. 透视大数据,未来市场谁主沉浮?这个4月,3W企服大数据OpenForm等你报名!
  6. 【NLP】新分类!全总结!最新Awesome-SLU-Survey资源库开源!
  7. LVS负载均衡下session共享的实现方式-持久化连接
  8. vilatile 深入理解java虚拟机_深入理解Java虚拟机(jvm性能调优+内存模型+虚拟机原理)...
  9. js css模仿打字效果
  10. 解决Ubuntu系统“无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系”的有效方法
  11. Arista CloudVision软件部署
  12. 小艾果果的伤感空间日志发布:分手后,温暖很稀少
  13. thinkphp 通过Redis实现增删改查操作
  14. 学习电子书和视频大全
  15. 2020年低压电工模拟考试题及低压电工实操考试视频
  16. 每次遇到浏览器主页被篡改的问题,就特别气愤加头疼
  17. pdf转图片 jpg png
  18. 如何给PDF文件加密和解密?
  19. 伦敦银实时走势图决胜关键
  20. 远程协助软件推荐,有哪些远程协助工具?

热门文章

  1. 精选30个优秀的CSS技术和实例
  2. Shopify:删除版权信息 Powered by Shopify 在网站底部
  3. Bootstrap ScrollSpy 用法
  4. 解决nginx无法启动的问题——端口被占用
  5. LeetCode 523. Continuous Subarray Sum
  6. Linux——find命令常见用法
  7. LeetCode 287. Find the Duplicate Number
  8. linux 分卷解压
  9. jdbc的小结 mysql
  10. ListView控件 1130