ETCD部署及实战

简介

etcd是CoreOS团队于2013年6月发起的开源项目,它的目标是构建一个高可用的分布式键值(key-value)数据库。etcd内部采用raft协议作为一致性算法,etcd基于Go语言实现。
etcd作为服务发现系统,有以下的特点:
简单:安装配置简单,而且提供了HTTP API进行交互,使用也很简单
安全:支持SSL证书验证
快速:根据官方提供的benchmark数据,单实例支持每秒2k+读操作
可靠:采用raft算法,实现分布式系统数据的可用性和一致性

单点部署及启动

文件下载
下载安装文件,可以到git上直接下载也可以 点击下载
将下载的etcd-v3.2.32-linux-amd64 (1).tar.gz 上传至服务器。
解压并启动
解压压缩包

tar -zvxf etcd-v3.2.32-linux-amd64 (1).tar.gz

将解压结果 mv到 opt/etcd 目录,结果如下

[root@localhost etcd]# ll /opt/etcd
total 38940
drwxr-xr-x.  2 root   root          6 Apr  7 01:58 config
drwx------.  3 root   root         20 Apr  7 01:45 default.etcd
drwxr-xr-x. 10 114762 114762     4096 Mar 29 06:30 Documentation
-rwxr-xr-x.  1 114762 114762 21359584 Mar 29 06:30 etcd
-rwxr-xr-x.  1 114762 114762 18456544 Mar 29 06:30 etcdctl
-rw-r--r--.  1 114762 114762    34246 Mar 29 06:30 README-etcdctl.md
-rw-r--r--.  1 114762 114762     5801 Mar 29 06:30 README.md
-rw-r--r--.  1 114762 114762     7855 Mar 29 06:30 READMEv2-etcdctl.md
[root@localhost etcd]# 

etcd 为服务端启动程序
etcdctl 为客户端启动程序
直接运行 etcd 命令,启动服务端,启动日志展示了etcd 的关键参数及选举过程

[root@localhost etcd]# ./etcd
2021-04-07 17:32:20.149506 I | etcdmain: etcd Version: 3.2.32
2021-04-07 17:32:20.149551 I | etcdmain: Git SHA: 7dc07f2a9
2021-04-07 17:32:20.149554 I | etcdmain: Go Version: go1.12.17
2021-04-07 17:32:20.149556 I | etcdmain: Go OS/Arch: linux/amd64
2021-04-07 17:32:20.149559 I | etcdmain: setting maximum number of CPUs to 4, total number of available CPUs is 4
2021-04-07 17:32:20.149565 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd    --默认数据目录
2021-04-07 17:32:20.149619 N | etcdmain: the server is already initialized as member before, starting as etcd member...
2021-04-07 17:32:20.149866 I | embed: listening for peers on http://localhost:2380--使用 http://localhost:2380 和 etcd Cluster 中其他节点通信。
2021-04-07 17:32:20.149967 I | embed: listening for client requests on localhost:2379  --使用 http://localhost:2379 提供 HTTP API 服务,与客户端通信。
2021-04-07 17:32:20.151065 I | etcdserver: name = default --节点名称
2021-04-07 17:32:20.151070 I | etcdserver: data dir = default.etcd -- 数据目录
2021-04-07 17:32:20.151072 I | etcdserver: member dir = default.etcd/member
2021-04-07 17:32:20.151075 I | etcdserver: heartbeat = 100ms  --表示 Leader 多久发送一次心跳到所有 Followers。
2021-04-07 17:32:20.151077 I | etcdserver: election = 1000ms --该参数的作用是重新投票的超时时间,如果 Follow 在该时间间隔内没有收到 Leader 发出的心跳包,就会触发重新投票。
2021-04-07 17:32:20.151079 I | etcdserver: snapshot count = 100000  --该参数的作用是指定有多少次事务被提交后触发快照截取动作并持久化到磁盘
2021-04-07 17:32:20.151085 I | etcdserver: advertise client URLs = http://localhost:2379
2021-04-07 17:32:20.151447 I | etcdserver: restarting member 8e9e05c52164694d in cluster cdf818194e3a8c32 at commit index 6--成员id 8e9e05c52164694d   集群id cdf818194e3a8c32 
2021-04-07 17:32:20.151657 I | raft: 8e9e05c52164694d became follower at term 3
2021-04-07 17:32:20.151665 I | raft: newRaft 8e9e05c52164694d [peers: [], term: 3, commit: 6, applied: 0, lastindex: 6, lastterm: 3]
2021-04-07 17:32:20.152947 W | auth: simple token is not cryptographically signed
2021-04-07 17:32:20.153636 I | etcdserver: starting server... [version: 3.2.32, cluster version: to_be_decided]
2021-04-07 17:32:20.154391 I | etcdserver/membership: added member 8e9e05c52164694d [http://localhost:2380] to cluster cdf818194e3a8c32
2021-04-07 17:32:20.154459 N | etcdserver/membership: set the initial cluster version to 3.2
2021-04-07 17:32:20.154484 I | etcdserver/api: enabled capabilities for version 3.2
2021-04-07 17:32:21.254486 I | raft: 8e9e05c52164694d is starting a new election at term 3  ---开始通过raft 协议选举 
2021-04-07 17:32:21.254549 I | raft: 8e9e05c52164694d became candidate at term 4
2021-04-07 17:32:21.254566 I | raft: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 4
2021-04-07 17:32:21.254578 I | raft: 8e9e05c52164694d became leader at term 4  --当前节点成为 leader
2021-04-07 17:32:21.254586 I | raft: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 4
2021-04-07 17:32:21.255465 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32--发布服务
2021-04-07 17:32:21.255559 I | embed: ready to serve client requests --等待接收用户请求
2021-04-07 17:32:21.255709 E | etcdmain: forgot to set Type=notify in systemd service file?
2021-04-07 17:32:21.256216 N | embed: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!

配置自启动

创建数据目录和配置文件目录

[root@localhost etcd]# mkdir -p /var/lib/etcd/
[root@localhost etcd]# mkdir -p /etc/etcd/config/

创建配置文件 (注意必须用yml 格式)

[root@localhost etcd]#  vi  /etc/etcd/config/etcd.conf 
name: 184etcd
data-dir: /home/scapp/app/etcd/data
listen-peer-urls: http://10.252.161.184:2380
listen-client-urls: http://10.252.161.184:9004,http://127.0.0.1:9004
advertise-client-urls: http://10.252.161.184:9004


创建服务文件

[root@localhost etcd]# vi /etc/systemd/system/etcd.service
[Unit]
Description=Etcd Server
Documentation=https://github.com/coreos/etcd
After=network.target

[Service]
User=root
Type=notify
ExecStart=/opt/etcd/etcd  --config-file  /etc/etcd/config/etcd.conf 
Restart=on-failure
RestartSec=10s
LimitNOFILE=40000

[Install]
WantedBy=multi-user.target

启动服务

[root@localhost etcd]# systemctl daemon-reload 
[root@localhost etcd]# systemctl enable etcd
Created symlink from /etc/systemd/system/multi-user.target.wants/etcd.service to /etc/systemd/system/etcd.service.
[root@localhost etcd]# systemctl start etcd

查看服务状态

关键配置参数说明
–name:指定 etcd Node 名称,可以使用 hostname。
–data-dir:指定 etcd Server 持久化数据存储目录路径。
–snapshot-count:指定有多少事务(transaction)被提交后,触发截取快照并持久化到磁盘。
–heartbeat-interval:指定 Leader 多久发送一次心跳到 Followers。
–eletion-timeout:指定重新投票的超时时间,如果 Follow 在该时间间隔没有收到 Leader 发出的心跳包,则会触发重新投票。
–listen-peer-urls:指定和 Cluster 其他 Node 通信的地址,比如:http://IP:2380,如果有多个,则使用逗号分隔。需要所有节点都能够访问,所以不要使用 localhost。
–listen-client-urls:指定对外提供服务的地址,比如:http://IP:2379,http://127.0.0.1:2379。
–advertise-client-urls:对外通告的该节点的客户端监听地址,会告诉集群中其他节点。
–initial-advertise-peer-urls:对外通告该节点的同伴(Peer)监听地址,这个值会告诉集群中其他节点。
–initial-cluster:指定集群中所有节点的信息,通常为 IP:Port 信息,格式为:node1=http://ip1:2380,node2=http://ip2:2380,…。这里的 node1 就是 --name 指定的名字,ip1:2380 就是 --initial-advertise-peer-urls 指定的值。
–initial-cluster-state:新建集群时,这个值为 new;假如已经存在了集群,这个值为 existing。
–initial-cluster-token:创建集群的 token,这个值每个集群保持唯一。这样的话,如果你要重新创建集群,即使配置和之前一样,也会再次生成新的集群和节点 UUID;否则会导致多个集群之间的冲突,造成未知的错误。

集群部署

就是多个主机上分别安装etcd节点,节点加入到统一的集群中。
etcd Cluster 必须具有时间同步服务器,否则会导致 Cluster 频繁进行 Leader Change。在 OpenShift 的 etcd Cluster 中,会每隔 100ms 进行心跳检测。
在安装和启动 etcd 服务进程的时候,各个 Node 都需要知道 Cluster 中其他 Nodes 的信息,一般是 IP:Port 信息。根据用户是否提前知晓(规划)了每个 Node 的 IP 地址,有以下几种不同的集群部署方案:

  1. 静态配置:在启动 etcd Server 的时候,通过 --initial-cluster 参数配置好所有的节点信息。
  2. 注册到已有的 etcd Cluster:比如官方提供的 discovery.etcd.io。
  3. 使用 DNS 启动

我们采用第一种方案

服务器准备
这里准备三台服务器 分别为
192.168.47.10(已按照上述步骤部署单点etcd) 从192.168.47.10克隆两台虚拟机IP分别设置为:192.168.47.11 和 192.168.47.12
增加启动脚本
192.168.47.10增加启动脚 /opt/etcd/etcdClusterStart.sh

也可以通过配置文件来启动 配置文件内容如下:

/opt/etcd/etcd  --name node10 --data-dir /var/lib/etcd  --listen-peer-urls http://192.168.47.10:2380 --listen-client-urls http://192.168.47.1:2379,http://127.0.0.1:2379 --snapshot-count 5 --initial-advertise-peer-urls http://192.168.47.11:2380 --initial-cluster node10=http://192.168.47.10:2380,node11=http://192.168.47.11:2380,node12=http://192.168.47.12:2380 --initial-cluster-state new  --initial-cluster-token etcd-cluster --advertise-client-urls http://192.168.47.11:2379

[scapp@iZd4l01sl2kkco2pihvlk1Z ~]$ sudo cat  /usr/local/etcd/etcd.yml
name: node179
data-dir: /usr/local/etcd/data
wal-dir: /usr/local/etcd/wal
listen-peer-urls: http://10.252.161.179:2380
listen-client-urls: http://10.252.161.179:443,http://127.0.0.1:443
snapshot-count: 5
initial-advertise-peer-urls: http://10.252.161.179:2380
initial-cluster: node178_89=http://10.252.161.179:2381,node179=http://10.252.161.179:2380,node180=http://10.252.161.180:2380
initial-cluster-state: new
initial-cluster-token: etcd-cluster
advertise-client-urls: http://10.252.161.179:443


192.168.47.11增加启动脚/opt/etcd/etcdClusterStart.sh

/opt/etcd/etcd  --name node11 --data-dir /var/lib/etcd  --listen-peer-urls http://192.168.47.11:2380 --listen-client-urls http://192.168.47.11:2379,http://127.0.0.1:2379 --snapshot-count 5 --initial-advertise-peer-urls http://192.168.47.11:2380 --initial-cluster node10=http://192.168.47.10:2380,node11=http://192.168.47.11:2380,node12=http://192.168.47.12:2380 --initial-cluster-state new  --initial-cluster-token etcd-cluster --advertise-client-urls http://192.168.47.11:2379

192.168.47.12增加启动脚/opt/etcd/etcdClusterStart.sh

/opt/etcd/etcd  --name node12 --data-dir /var/lib/etcd  --listen-peer-urls http://192.168.47.12:2380 --listen-client-urls http://192.168.47.12:2379,http://127.0.0.1:2379 --snapshot-count 5 --initial-advertise-peer-urls http://192.168.47.12:2380 --initial-cluster node10=http://192.168.47.10:2380,node11=http://192.168.47.11:2380,node12=http://192.168.47.12:2380 --initial-cluster-state new  --initial-cluster-token etcd-cluster --advertise-client-urls http://192.168.47.12:2379

修改脚本执行权限并启动etcd

chmod u+x /opt/etcd/etcdClusterStart.sh  --增加执行权限
/opt/etcd/etcdClusterStart.sh

启动日志可以看到三个节点都加到了 集群de2552097e6fd22a中

2021-04-07 23:16:01.963032 I | etcdserver: starting server... [version: 3.2.32, cluster version: to_be_decided]
2021-04-07 23:16:01.964646 I | etcdserver/membership: added member 3c3338c57d4cba41 [http://192.168.47.12:2380] to cluster de2552097e6fd22a
2021-04-07 23:16:01.964848 I | etcdserver/membership: added member 6d065fcb2738cb70 [http://192.168.47.10:2380] to cluster de2552097e6fd22a
2021-04-07 23:16:01.965021 I | etcdserver/membership: added member debef2b0c1cbfddf [http://192.168.47.11:2380] to cluster de2552097e6fd22a
2021-04-07 23:16:01.966992 I | rafthttp: peer 6d065fcb2738cb70 became active

通过客户端程序查看集群状态

[root@localhost ~]# /opt/etcd/etcdctl member list
3c3338c57d4cba41: name=node12 peerURLs=http://192.168.47.12:2380 clientURLs=http://192.168.47.12:2379 isLeader=false
6d065fcb2738cb70: name=node10 peerURLs=http://192.168.47.10:2380 clientURLs=http://192.168.47.10:2379 isLeader=false
debef2b0c1cbfddf: name=node11 peerURLs=http://192.168.47.11:2380 clientURLs=http://192.168.47.11:2379 isLeader=true

V2PAI基本操作

etcdctl是一个命令行的客户端,它提供了一下简洁的命令,可以方便我们在对服务进行测试或者手动修改数据库内容。建议刚刚接触etcd的同学可以先通过etcdctl来熟悉相关操作 这里默认使用的是etcdV2库 。这些操作跟etcd提供的HTTP API是对应的。

set
设置键的值
支持的选项

--ttl '0'            该键值的超时时间(单位为秒),不配置(默认为 0)则永不超时
--swap-with-value value 若该键现在的值是 value,则进行设置操作
--swap-with-index '0'    若该键现在的索引值是指定索引,则进行设置操作

get
获取指定键的值,键不存在时会报错
支持的选项

--sort    对结果进行排序
--consistent 将请求发给主节点,保证获取内容的一致性

update
更新给定键中存储的值,键不存在会报错
支持的选项

--ttl '0'    超时时间(单位为秒),不配置(默认为 0)则永不超时

rm
删除给定的键,如果命令参数中给定的键不存在则会报错
支持的选项

--dir        如果键是个空目录或者键值对则删除
--recursive        删除目录和所有子键
--with-value     检查现有的值是否匹配
--with-index '0'    检查现有的 index 是否匹配

setdir
创建一个目录,无论存在与否
选项

--ttl '0'    超时时间(单位为秒),不配置(默认为 0)则永不超时

ls
列出目录(默认为根目录)下的键或者子目录,默认不显示子目录中内容
支持的选项

--sort    将输出结果排序
--recursive    如果目录下有子目录,则递归输出其中的内容
-p        对于输出为目录,在最后添加 `/` 进行区分

backup
备份 etcd 的数据
支持的选项

--data-dir         etcd 的数据目录
--backup-dir     备份到指定路径

watch
监测一个键值的变化,一旦键值发生更新,就会输出最新的值并退出。

--forever        一直监测,直到用户按 `CTRL+C` 退出
--after-index '0'    在指定 index 之前一直监测
--recursive        返回所有的键值和子键值

exec-watch
监测一个键值的变化,一旦键值发生更新,就执行给定命令,如:etcdctl exec-watch testkey – sh -c ‘ls’
支持的选项

--after-index '0'    在指定 index 之前一直监测
--recursive        返回所有的键值和子键值

member
通过 list、add、remove 命令列出、添加、删除 etcd 实例到 etcd 集群中

示例操作

[root@localhost ~]# /opt/etcd/etcdctl set /root/test/key1 "hello world"
hello world
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key1 
hello world
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key2 
Error:  100: Key not found (/root/test/key2) [10]
[root@localhost ~]# /opt/etcd/etcdctl set /root/test/key1 "hello world" --ttl 10
hello world
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key1 
hello world
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key1 
hello world
[root@localhost ~]# /opt/etcd/etcdctl set /root/test/key2 "hello world2" --ttl 10
hello world2
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key2 
hello world2
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key2 
Error:  100: Key not found (/root/test/key2) [14]
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key1
Error:  100: Key not found (/root/test/key1) [14]
[root@localhost ~]# /opt/etcd/etcdctl set /root/test/key1 "hello world2" 
hello world2
[root@localhost ~]# /opt/etcd/etcdctl update /root/test/key1 "hello world23" 
hello world23
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key1
hello world23
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key1
hello world23
[root@localhost ~]# /opt/etcd/etcdctl rm /root/test/key1
PrevNode.Value: hello world23
[root@localhost ~]# /opt/etcd/etcdctl get /root/test/key1
Error:  100: Key not found (/root/test/key1) [17]
[root@localhost ~]# setdir /mycate/test
-bash: setdir: command not found
[root@localhost ~]# /opt/etcd/etcdctl setdir /my/test
[root@localhost ~]# /opt/etcd/etcdctl rm --dir /my/test
[root@localhost ~]# /opt/etcd/etcdctl get /root
/root: is a directory
[root@localhost ~]# /opt/etcd/etcdctl get /root
/root: is a directory
[root@localhost ~]# /opt/etcd/etcdctl setdir /root/cata2
[root@localhost ~]# /opt/etcd/etcdctl setdir /root/cata3
[root@localhost ~]# /opt/etcd/etcdctl ls /root/
/root/cata2
/root/cata3
/root/test

V3API基本操作

操作示例如下

   alias  etc=/root/etcd/etcdctl  为命令取别名
   export ETCDCTL_API=3  --使用v3API
   etc put test zhangsan    写入键值
   etc put test3 zhangsan3  写入键值
   etc get test3   读取键值
   etc get  test11  -w=json   json格式返回键值,内容比较全
   etc get test --prefix  读取键值 根据前缀
   etc get test --prefix  --limit=1 读取键值根据前缀并限制返回数量
   etc get test --prefix  --limit 1
   etc get test --rev=2  根据版本获取值
   etc del test3    删除键值
   etc del test test4  根据范围删除键值
   etc del --from-key a  删除key字节值大于或等 于 a 的键值 
   etc get --from-key a 读取key字节值大于或等 于 a 的键值 
   etc watch test4  监听键值变化
   etc watch test  test7  按范围监听键值变化
   etc watch -i       手工输入监视多个键值变化
   etc watch ttt --rev=2  从某版本开始监视键值变化
   etc watch ttt --prev-kv  监视键值变化变化时推送原值
   etc compact 5  按照某个版本号进行压缩  这个版本号不是某个key的版本号,是整个wal日志的左引号
    
   etc lease grant 10  创建一个租约 10s 有效
   etc put test12 test12-7 --lease=694d7c2919403153  为键值设置租约 
   etc put test12 test12-7 --lease=694d7c2919403157 
   etc get  test12  -w=json  
   etc lease revoke 7587857463148294487  释放某个租约
   etc lease grant 20   
   etc lease keep-alive 694d7c291940316e  自动续期某个租约
   [root@localhost ~]# etc --endpoints=127.0.0.1:2379,127.0.0.1:2479,127.0.0.1:2479  endpoint status --write-out=table        --查看集群状态
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|    ENDPOINT    |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 127.0.0.1:2379 | c085e6085ca1ec17 |   3.5.1 |   20 kB |      true |      false |         2 |          9 |                  9 |        |
| 127.0.0.1:2479 | bd20ac606784e77a |   3.5.1 |   20 kB |     false |      false |         2 |          9 |                  9 |        |
| 127.0.0.1:2479 | bd20ac606784e77a |   3.5.1 |   20 kB |     false |      false |         2 |          9 |                  9 |        |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

问题总结及处理

问题1 配置参数写入配置文件,启动时发现没有起作用
处理:将配置参数 直接添加到启动命令中,启动,成功解决。原来不起作用原因是配置文件引用方式不正确,可以在系统服务文件中 的启动命令直接追加配置文件参数,如下: ExecStart=/opt/etcd/etcd --config-file /etc/etcd/config/etcd.conf 同时配置文件内容必须是yml格式,具体参考上文示例
问题2 集群启动后 通过客户端 [root@localhost ~]# /opt/etcd/etcdctl member list 命令查看集群成员,提示错误:
etcd cluster is unavailable or misconfigured; error #0: dial tcp 127.0.0.1:2379
处理:启动脚本配置项listen-client-urls 内容由http://192.168.47.12:2379 修改为: --listen-client-urls http://192.168.47.12:2379,http://127.0.0.1:2379 成功解决
问题3 当集群配置修改后,如成员名称 地址修改后,可能导致集群状态不正常,启动不正常,需要删除集群中节点的 data wal 目录,然后重启集群。

etcd配置文件格式及内容

# This is the configuration file for the etcd server.
  
# Human-readable name for this member.
name: 'default'
# Path to the data directory.
data-dir:
  
# Path to the dedicated wal directory.
wal-dir:
  
# Number of committed transactions to trigger a snapshot to disk.
snapshot-count: 10000
  
# Time (in milliseconds) of a heartbeat interval.
heartbeat-interval: 100
  
# Time (in milliseconds) for an election to timeout.
election-timeout: 1000
  
# Raise alarms when backend size exceeds the given quota. 0 means use the
# default quota.
quota-backend-bytes: 0
  
# List of comma separated URLs to listen on for peer traffic.
listen-peer-urls: http://localhost:2380
  
# List of comma separated URLs to listen on for client traffic.
listen-client-urls: http://localhost:2379
  
# Maximum number of snapshot files to retain (0 is unlimited).
max-snapshots: 5
  
# Maximum number of wal files to retain (0 is unlimited).
max-wals: 5
  
# Comma-separated white list of origins for CORS (cross-origin resource sharing).
cors:
  
# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
initial-advertise-peer-urls: http://localhost:2380
  
# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
advertise-client-urls: http://localhost:2379
  
# Discovery URL used to bootstrap the cluster.
discovery:
  
# Valid values include 'exit', 'proxy'
discovery-fallback: 'proxy'
  
# HTTP proxy to use for traffic to discovery service.
discovery-proxy:
  
# DNS domain used to bootstrap initial cluster.
discovery-srv:
  
# Initial cluster configuration for bootstrapping.
initial-cluster:
  
# Initial cluster token for the etcd cluster during bootstrap.
initial-cluster-token: 'etcd-cluster'
  
# Initial cluster state ('new' or 'existing').
initial-cluster-state: 'new'
  
# Reject reconfiguration requests that would cause quorum loss.
strict-reconfig-check: false
  
# Accept etcd V2 client requests
enable-v2: true
  
# Enable runtime profiling data via HTTP server
enable-pprof: true
  
# Valid values include 'on', 'readonly', 'off'
proxy: 'off'
  
# Time (in milliseconds) an endpoint will be held in a failed state.
proxy-failure-wait: 5000
  
# Time (in milliseconds) of the endpoints refresh interval.
proxy-refresh-interval: 30000
  
# Time (in milliseconds) for a dial to timeout.
proxy-dial-timeout: 1000
  
# Time (in milliseconds) for a write to timeout.
proxy-write-timeout: 5000
  
# Time (in milliseconds) for a read to timeout.
proxy-read-timeout: 0
  
client-transport-security:
  # Path to the client server TLS cert file.
  cert-file:
  
  # Path to the client server TLS key file.
  key-file:
  
  # Enable client cert authentication.
  client-cert-auth: false
  
  # Path to the client server TLS trusted CA cert file.
  trusted-ca-file:
  
  # Client TLS using generated certificates
  auto-tls: false
  
peer-transport-security:
  # Path to the peer server TLS cert file.
  cert-file:
  
  # Path to the peer server TLS key file.
  key-file:
  
  # Enable peer client cert authentication.
  client-cert-auth: false
  
  # Path to the peer server TLS trusted CA cert file.
  trusted-ca-file:
  
  # Peer TLS using generated certificates.
  auto-tls: false
  
# Enable debug-level logging for etcd.
debug: false
  
logger: zap
  
# Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
log-outputs: [stderr]
  
# Force to create a new one member cluster.
force-new-cluster: false
  
auto-compaction-mode: periodic
auto-compaction-retention: "1"
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
当你想要在Docker中部署etcd时,可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Docker,并且Docker守护进程正在运行。 2. 下载etcd的Docker镜像。你可以使用以下命令从Docker Hub上获取官方的etcd镜像: ``` docker pull quay.io/coreos/etcd ``` 3. 创建一个etcd容器。使用以下命令创建一个新的etcd容器: ``` docker run -d --name my-etcd -p 2379:2379 -p 2380:2380 \ --volume=/path/to/data:/etcd-data \ quay.io/coreos/etcd:latest \ /usr/local/bin/etcd \ --name my-etcd \ --data-dir /etcd-data \ --advertise-client-urls http://0.0.0.0:2379 \ --listen-client-urls http://0.0.0.0:2379 \ --initial-advertise-peer-urls http://0.0.0.0:2380 \ --listen-peer-urls http://0.0.0.0:2380 \ --initial-cluster my-etcd=http://0.0.0.0:2380 \ --initial-cluster-token my-etcd-token \ --initial-cluster-state new ``` 这个命令会创建一个名为my-etcd的容器,并将容器的2379端口映射到主机的2379端口,以及将容器的2380端口映射到主机的2380端口。你可以根据需要修改这些端口映射。 4. 现在,你的etcd容器已经在Docker中运行起来了。你可以使用etcd客户端工具连接到容器并进行操作。例如,你可以使用以下命令连接到etcd容器: ``` docker exec -it my-etcd /bin/sh ``` 这将在容器内部启动一个shell会话,你可以在其中运行etcd客户端命令。 以上是在Docker中部署etcd的基本步骤。你可以根据自己的需求进行进一步的配置和操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catch that elf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值