etcd 简介与单节点安装
简介
etcd是使用go语言编写的一种分布式键值存储,旨在可靠、快速地保存和提供对关键数据的访问。通过分布式锁、leader选举和写保障实现可靠的分布式协调。etcd集群用于高可用、持久化数据存储和检索,其重点在于
- 简单:良好定义的,面向用户的API (gRPC)
- 安全: 带有可选客户端证书认证的自动TLS
- 快速:测试验证,每秒10000写入
- 可靠:使用Raft适当分布
特性
- 简单的接口
- 基于HTTP+JSON的API让你用curl就可以轻松使用
- 键值存储
- watch改变
- 观察特定键或目录的更改,并对值的更改做出反应
应用场景
- 服务发现(Service Discovery)
- 消息发布与订阅
- 负载均衡
- 分布式通知与协调
- 分布式锁、分布式队列
- 集群监控与Leader竞选
单节点安装
-
安装go环境
[root@node1 ~]# yum install go
-
下载、解压软件包
[root@node1 ~]# wget https://github.com/etcd-io/etcd/releases/download/v3.3.13/etcd-v3.3.13-linux-amd64.tar.gz [root@node1 ~]# tar -zxvf etcd-v3.3.13-linux-amd64.tar.gz [root@node1 etcd-v3.3.13-linux-amd64]# ls Documentation etcd etcdctl README-etcdctl.md README.md READMEv2-etcdctl.md etcd 是server端 etcdctl是client端
-
创建软链
[root@node1 etcd-v3.3.13-linux-amd64]# ln -s /root/etcd-v3.3.13-linux-amd64/etcd /usr/local/sbin/etcd [root@node1 etcd-v3.3.13-linux-amd64]# ln -s /root/etcd-v3.3.13-linux-amd64/etcdctl /usr/local/sbin/etcdctl [root@node1 etcd-v3.3.13-linux-amd64]# ls -l /usr/local/sbin/ total 0 lrwxrwxrwx. 1 root root 35 Jun 4 03:00 etcd -> /root/etcd-v3.3.13-linux-amd64/etcd lrwxrwxrwx. 1 root root 38 Jun 4 03:01 etcdctl -> /root/etcd-v3.3.13-linux-amd64/etcdctl [root@node1 etcd-v3.3.13-linux-amd64]#
-
启动
[root@node1 ~]# etcd 2019-06-04 03:04:22.580594 I | etcdmain: etcd Version: 3.3.13 2019-06-04 03:04:22.580771 I | etcdmain: Git SHA: 98d3084 2019-06-04 03:04:22.580798 I | etcdmain: Go Version: go1.10.8 2019-06-04 03:04:22.580816 I | etcdmain: Go OS/Arch: linux/amd64 2019-06-04 03:04:22.580831 I | etcdmain: setting maximum number of CPUs to 1, total number of available CPUs is 1 2019-06-04 03:04:22.580872 W | etcdmain: no data-dir provided, using default data-dir ./default.etcd 2019-06-04 03:04:22.580990 N | etcdmain: the server is already initialized as member before, starting as etcd member... 2019-06-04 03:04:22.583838 I | embed: listening for peers on http://localhost:2380 2019-06-04 03:04:22.584468 I | embed: listening for client requests on localhost:2379 2019-06-04 03:04:22.586968 I | etcdserver: name = default 2019-06-04 03:04:22.587005 I | etcdserver: data dir = default.etcd 2019-06-04 03:04:22.587021 I | etcdserver: member dir = default.etcd/member 2019-06-04 03:04:22.587033 I | etcdserver: heartbeat = 100ms 2019-06-04 03:04:22.587045 I | etcdserver: election = 1000ms 2019-06-04 03:04:22.587057 I | etcdserver: snapshot count = 100000 2019-06-04 03:04:22.587095 I | etcdserver: advertise client URLs = http://localhost:2379 2019-06-04 03:04:22.843525 I | etcdserver: restarting member 8e9e05c52164694d in cluster cdf818194e3a8c32 at commit index 4 2019-06-04 03:04:22.843650 I | raft: 8e9e05c52164694d became follower at term 2 2019-06-04 03:04:22.843693 I | raft: newRaft 8e9e05c52164694d [peers: [], term: 2, commit: 4, applied: 0, lastindex: 4, lastterm: 2] 2019-06-04 03:04:23.634579 W | auth: simple token is not cryptographically signed 2019-06-04 03:04:24.436881 I | etcdserver: starting server... [version: 3.3.13, cluster version: to_be_decided] 2019-06-04 03:04:24.447324 I | etcdserver/membership: added member 8e9e05c52164694d [http://localhost:2380] to cluster cdf818194e3a8c32 2019-06-04 03:04:24.447635 N | etcdserver/membership: set the initial cluster version to 3.3 2019-06-04 03:04:24.447831 I | etcdserver/api: enabled capabilities for version 3.3 2019-06-04 03:04:26.545608 I | raft: 8e9e05c52164694d is starting a new election at term 2 2019-06-04 03:04:26.545685 I | raft: 8e9e05c52164694d became candidate at term 3 2019-06-04 03:04:26.545731 I | raft: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 3 2019-06-04 03:04:26.545767 I | raft: 8e9e05c52164694d became leader at term 3 2019-06-04 03:04:26.545785 I | raft: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 3 2019-06-04 03:04:26.548261 I | etcdserver: published {Name:default ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32 2019-06-04 03:04:26.548505 E | etcdmain: forgot to set Type=notify in systemd service file? 2019-06-04 03:04:26.548607 I | embed: ready to serve client requests 2019-06-04 03:04:26.550400 N | embed: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
-
端口介绍
- 端口2379: 向客户端提供服务
- 端口2380: 在各个节点间同步raft状态及数据
参考
https://www.cnblogs.com/softidea/p/6517959.html
https://blog.csdn.net/skh2015java/article/details/80714661
http://etcd.doczh.cn/documentation/dev-guide/local_cluster.html