etcd集群部署实战

文章目录

  • 前言
  • 安装
  • 集群环境
  • 添加配置文件
  • 启动etcd
  • 查看集群状态

前言

本文使用v3.5.4版本的etcd进行搭建集群演示,仅适用于学习etcd的基本使用。

安装

通过github网站下载etcd压缩包,解压后将etcd-v3.5.4-linux-amd64目录下的etcd,etcdctl,etcdutl可执行程序复制到/usr/local/bin目录下。

查看etcd版本信息:

[root@node3 ~]# etcd --version
etcd Version: 3.5.4
Git SHA: 08407ff76
Go Version: go1.16.15
Go OS/Arch: linux/amd64

集群环境

节点名称 IP地址
etcd01 192.168.1.201
etcd02 192.168.1.202
etcd03 192.168.1.203

添加配置文件

/etc/etcd/目录下新增etcd.yaml文件,文件内容如下:

name: etcd01

data-dir: /var/lib/etcd/
listen-peer-urls: http://192.168.1.201:2380
listen-client-urls: http://192.168.1.201:2379

initial-advertise-peer-urls: http://192.168.1.201:2380
advertise-client-urls: http://192.168.1.201:2379
initial-cluster: etcd01=http://192.168.1.201:2380,etcd02=http://192.168.1.202:2380,etcd03=http://192.168.1.203:2380
initial-cluster-token: etcd-cluster

注意每个节点的配置文件内容需要调整name参数和监听地址。

启动etcd

执行etcd程序并指定配置文件路径:

etcd --config-file /etc/etcd/etcd.yaml

查看集群状态

集群状态:

[root@node3 ~]# etcdctl --endpoints http://192.168.1.202:2379,192.168.1.201:2379,192.168.1.203:2379 endpoint status --write-out=table
+---------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|         ENDPOINT          |        ID        | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+---------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://192.168.1.202:2379 | 57f3ceb2d78cc272 |   3.5.4 |   20 kB |      true |      false |         3 |         19 |                 19 |        |
|        192.168.1.201:2379 | b4b07e4c725567ef |   3.5.4 |   25 kB |     false |      false |         3 |         19 |                 19 |        |
|        192.168.1.203:2379 | 5701e80d00d3778e |   3.5.4 |   20 kB |     false |      false |         3 |         19 |                 19 |        |
+---------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

集群健康状态:

[root@node3 ~]# etcdctl --endpoints http://192.168.1.202:2379,192.168.1.201:2379,192.168.1.203:2379 endpoint health --write-out=table                                      
+---------------------------+--------+-------------+-------+
|         ENDPOINT          | HEALTH |    TOOK     | ERROR |
+---------------------------+--------+-------------+-------+
|        192.168.1.203:2379 |   true |  62.72184ms |       |
|        192.168.1.201:2379 |   true | 64.695896ms |       |
| http://192.168.1.202:2379 |   true | 66.717064ms |       |
+---------------------------+--------+-------------+-------+

你可能感兴趣的:(etcd,etcd,linux,数据库)