安装etcd
# 安装etcd
本文介绍etcd的安装步骤。etcd是一个基于golang开发的分布式一致性键值存储系统,常用于微服务中,用于实现服务注册、服务发现、配置管理、分布式锁等。
注意: 目前只能本机的etcd客户端访问, 其他机器无法访问,可能和没配置证书有关,后续再做确认。
# 1. 安装etcd
从官网 (opens new window)下载对应程序
解压
unzip ./etcd-v3.2.32-darwin-amd64.zip -d ~/workspace/programs
解压后的文件结构如下:
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 % ls -l
total 106488
drwxr-xr-x@ 22 wangshibiao staff 704 3 29 06:30 Documentation
-rw-r--r--@ 1 wangshibiao staff 34246 3 29 06:30 README-etcdctl.md
-rw-r--r--@ 1 wangshibiao staff 5801 3 29 06:30 README.md
-rw-r--r--@ 1 wangshibiao staff 7855 3 29 06:30 READMEv2-etcdctl.md
-rwxr-xr-x@ 1 wangshibiao staff 29280592 3 29 06:30 etcd
-rwxr-xr-x@ 1 wangshibiao staff 25183440 3 29 06:30 etcdctl
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 % pwd
/Users/wangshibiao/workspace/programs/etcd-v3.2.32-darwin-amd64
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 %
运行,界面如下:
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 % ./etcd
2021-04-08 18:41:25.227703 I | etcdmain: etcd Version: 3.2.32
2021-04-08 18:41:25.227829 I | etcdmain: Git SHA: 7dc07f2a9
2021-04-08 18:41:25.227834 I | etcdmain: Go Version: go1.12.17
2021-04-08 18:41:25.227839 I | etcdmain: Go OS/Arch: darwin/amd64
2021-04-08 18:41:25.227843 I | etcdmain: setting maximum number of CPUs to 8, total number of available CPUs is 8
2021-04-08 18:41:25.227857 N | etcdmain: failed to detect default host (default host not supported on darwin_amd64)
2021-04-08 18:41:25.227866 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd
2021-04-08 18:41:25.237878 I | embed: listening for peers on http://localhost:2380
2021-04-08 18:41:25.244586 I | embed: listening for client requests on localhost:2379
2021-04-08 18:41:25.270126 I | etcdserver: name = default
2021-04-08 18:41:25.270167 I | etcdserver: data dir = default.etcd
2021-04-08 18:41:25.270178 I | etcdserver: member dir = default.etcd/member
2021-04-08 18:41:25.270186 I | etcdserver: heartbeat = 100ms
2021-04-08 18:41:25.270193 I | etcdserver: election = 1000ms
2021-04-08 18:41:25.270200 I | etcdserver: snapshot count = 100000
2021-04-08 18:41:25.270219 I | etcdserver: advertise client URLs = http://localhost:2379
2021-04-08 18:41:25.270228 I | etcdserver: initial advertise peer URLs = http://localhost:2380
2021-04-08 18:41:25.270255 I | etcdserver: initial cluster = default=http://localhost:2380
2021-04-08 18:41:25.349895 I | etcdserver: starting member 8e9e05c52164694d in cluster cdf818194e3a8c32
2021-04-08 18:41:25.350056 I | raft: 8e9e05c52164694d became follower at term 0
2021-04-08 18:41:25.350092 I | raft: newRaft 8e9e05c52164694d [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2021-04-08 18:41:25.350107 I | raft: 8e9e05c52164694d became follower at term 1
2021-04-08 18:41:25.469701 W | auth: simple token is not cryptographically signed
2021-04-08 18:41:25.564273 I | etcdserver: starting server... [version: 3.2.32, cluster version: to_be_decided]
2021-04-08 18:41:25.564710 E | etcdserver: cannot monitor file descriptor usage (cannot get FDUsage on darwin)
2021-04-08 18:41:25.565143 I | etcdserver: 8e9e05c52164694d as single-node; fast-forwarding 9 ticks (election ticks 10)
2021-04-08 18:41:25.565996 I | etcdserver/membership: added member 8e9e05c52164694d [http://localhost:2380] to cluster cdf818194e3a8c32
2021-04-08 18:41:26.356567 I | raft: 8e9e05c52164694d is starting a new election at term 1
2021-04-08 18:41:26.356834 I | raft: 8e9e05c52164694d became candidate at term 2
2021-04-08 18:41:26.356902 I | raft: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 2
2021-04-08 18:41:26.356960 I | raft: 8e9e05c52164694d became leader at term 2
2021-04-08 18:41:26.357009 I | raft: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 2
2021-04-08 18:41:26.357562 I | etcdserver: setting up the initial cluster version to 3.2
2021-04-08 18:41:26.357785 I | embed: ready to serve client requests
2021-04-08 18:41:26.358047 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32
2021-04-08 18:41:26.359226 N | embed: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
2021-04-08 18:41:26.381719 N | etcdserver/membership: set the initial cluster version to 3.2
2021-04-08 18:41:26.381926 I | etcdserver/api: enabled capabilities for version 3.2
设置环境变量 vi ~/.zshrc
#etcd
export ETCDCTL_API=3
# 2. 验证
# 2.1 写数据
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 % ./etcdctl put mykey "this is demo"
OK
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 %
# 2.2 读数据
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 % ./etcdctl get mykey
mykey
this is demo
wangshibiao@localhost etcd-v3.2.32-darwin-amd64 %
上次更新: 2021-04-18 23:32:50