etcd 集群部署

181 阅读1分钟

一、环境

角色说明
CentOS7192.168.90.71
CentOS7192.168.90.72
CentOS7192.168.90.73
etcdv3.5.0

二、etcd 安装

1、192.168.90.71 操作

1)、下载二进制文件
#下载二进制文件
$ curl -L https://github.com/etcd-io/etcd/releases/download/3.5.0/etcd-3.5.0-linux-amd64.tar.gz -o etcd-3.5.0-linux-amd64.tar.gz

#解压文件
$ tar -xvf etcd-v3.5.0-linux-amd64.tar.gz

#检查版本
$ cd etcd-v3.5.0-linux-amd64
$ ./etcd --version

输出:

etcd Version: 3.5.0
Git SHA: 946a5a6f2
Go Version: go1.16.3
Go OS/Arch: linux/amd64

其余两台机器执行相同操作

2、配置

1)、创建数据目录
#数据目录
$ mkdir -p /opt/etcd/data
$ mkdir -p /opt/etcd/bin
$ mkdir -p /opt/etcd/conf
2、生成配置文件
#1、生成token
$ uuidgen
359ad234-ed7a-46de-91e9-2a6a07a5026a

#2、复制文件
$ cp etcd etcdctl  etcdutl /opt/etcd/bin/

#3、创建配置文件
$ cd /opt/etcd/conf/
$ vim etcd.yaml

192.168.90.71 内容如下: 注意:

name: "etcd1"
initial-cluster: "etcd1=http://192.168.90.71:2380,etcd2=http://192.168.90.72:2380,etcd3=http://192.168.90.73:2380"
data-dir: "/opt/etcd/data"
listen-client-urls: "http://0.0.0.0:2379"
listen-peer-urls: "http://0.0.0.0:2380"
initial-advertise-peer-urls: "http://192.168.90.71:2380"
advertise-client-urls: "http://192.168.90.71:2379"
initial-cluster_token: "359ad234-ed7a-46de-91e9-2a6a07a5026a"
initial-cluster_state: "new"
3、生成 etcd.service 文件

vim /etc/systemd/system/etcd.service

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/opt/etcd/bin/
EnvironmentFile=/opt/etcd/conf/etcd.yaml
User=root
ExecStart=/opt/etcd/bin/etcd --config-file=/opt/etcd/conf/etcd.yaml

Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

其余两台执行相同操作,注意配置文件中的IP更改

三、检查状态

#三台节点启动服务
$ systemctl start etcd

$ cd /opt/etcd/bin/
././etcdctl --endpoints=http://192.168.90.71:2379,http://192.168.90.72:2379,http://192.168.90.73: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.90.71:2379 | 13c2a075058b8b28 |   3.5.0 |   20 kB |     false |      false |         3 |         14 |                 14 |        |
| http://192.168.90.72:2379 |  c093dbe4040ce0c |   3.5.0 |   29 kB |      true |      false |         3 |         14 |                 14 |        |
| http://192.168.90.73:2379 | 72a90dc7c4a53e40 |   3.5.0 |   20 kB |     false |      false |         3 |         14 |                 14 |        |
+---------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+

完成