etcd 3节点集群配置
时间: 2023-07-25 08:08:16 浏览: 61
redis cluster 集群节点配置
etcd 是一个高可用的分布式 key-value 存储系统,可以用于分布式锁、服务发现、共享配置等场景。在使用 etcd 时,为了保证其高可用性,通常需要使用多个节点组成 etcd 集群。以下是配置 etcd 3 节点集群的步骤:
1. 安装 etcd
在每个节点上安装 etcd。具体步骤可以参考 etcd 的官方文档。
2. 修改配置文件
在每个节点上修改 etcd 的配置文件,一般位于 /etc/etcd/etcd.conf:
```
# Node 1
name: "node1"
data-dir: "/var/lib/etcd"
listen-peer-urls: "https://192.168.0.1:2380"
listen-client-urls: "https://192.168.0.1:2379"
initial-advertise-peer-urls: "https://192.168.0.1:2380"
advertise-client-urls: "https://192.168.0.1:2379"
initial-cluster: "node1=https://192.168.0.1:2380,node2=https://192.168.0.2:2380,node3=https://192.168.0.3:2380"
initial-cluster-token: "my-etcd-cluster"
initial-cluster-state: "new"
client-transport-security:
cert-file: "/etc/ssl/etcd/etcd.pem"
key-file: "/etc/ssl/etcd/etcd-key.pem"
trusted-ca-file: "/etc/ssl/etcd/ca.pem"
peer-transport-security:
cert-file: "/etc/ssl/etcd/etcd.pem"
key-file: "/etc/ssl/etcd/etcd-key.pem"
trusted-ca-file: "/etc/ssl/etcd/ca.pem"
# Node 2
name: "node2"
data-dir: "/var/lib/etcd"
listen-peer-urls: "https://192.168.0.2:2380"
listen-client-urls: "https://192.168.0.2:2379"
initial-advertise-peer-urls: "https://192.168.0.2:2380"
advertise-client-urls: "https://192.168.0.2:2379"
initial-cluster: "node1=https://192.168.0.1:2380,node2=https://192.168.0.2:2380,node3=https://192.168.0.3:2380"
initial-cluster-token: "my-etcd-cluster"
initial-cluster-state: "new"
client-transport-security:
cert-file: "/etc/ssl/etcd/etcd.pem"
key-file: "/etc/ssl/etcd/etcd-key.pem"
trusted-ca-file: "/etc/ssl/etcd/ca.pem"
peer-transport-security:
cert-file: "/etc/ssl/etcd/etcd.pem"
key-file: "/etc/ssl/etcd/etcd-key.pem"
trusted-ca-file: "/etc/ssl/etcd/ca.pem"
# Node 3
name: "node3"
data-dir: "/var/lib/etcd"
listen-peer-urls: "https://192.168.0.3:2380"
listen-client-urls: "https://192.168.0.3:2379"
initial-advertise-peer-urls: "https://192.168.0.3:2380"
advertise-client-urls: "https://192.168.0.3:2379"
initial-cluster: "node1=https://192.168.0.1:2380,node2=https://192.168.0.2:2380,node3=https://192.168.0.3:2380"
initial-cluster-token: "my-etcd-cluster"
initial-cluster-state: "new"
client-transport-security:
cert-file: "/etc/ssl/etcd/etcd.pem"
key-file: "/etc/ssl/etcd/etcd-key.pem"
trusted-ca-file: "/etc/ssl/etcd/ca.pem"
peer-transport-security:
cert-file: "/etc/ssl/etcd/etcd.pem"
key-file: "/etc/ssl/etcd/etcd-key.pem"
trusted-ca-file: "/etc/ssl/etcd/ca.pem"
```
每个节点的配置文件需要修改以下参数:
- name:节点名称,需要在集群中唯一。
- data-dir:数据存储目录。
- listen-peer-urls:节点间通信的地址。需要指定 https 协议和端口号。
- listen-client-urls:客户端访问 etcd 的地址。需要指定 https 协议和端口号。
- initial-advertise-peer-urls:节点向其他节点宣告自己的地址。需要指定 https 协议和端口号。
- advertise-client-urls:节点向客户端宣告自己的地址。需要指定 https 协议和端口号。
- initial-cluster:集群中所有节点的信息。每个节点信息格式为 name=https://ip:port。需要注意,节点名称一定要与配置文件中的 name 参数一致。
- initial-cluster-token:集群令牌,需要在所有节点中保持一致。
- initial-cluster-state:集群状态。第一次启动时为 new,之后为 existing。
- client-transport-security:客户端访问 etcd 的安全配置。
- peer-transport-security:节点间通信的安全配置。
3. 启动 etcd
在每个节点上启动 etcd 服务:
```
$ systemctl start etcd
```
4. 验证集群状态
在任意一个节点上执行以下命令,可以查看集群状态:
```
$ etcdctl --endpoints=https://192.168.0.1:2379,https://192.168.0.2:2379,https://192.168.0.3:2379 --ca-file=/etc/ssl/etcd/ca.pem --cert-file=/etc/ssl/etcd/etcd.pem --key-file=/etc/ssl/etcd/etcd-key.pem cluster-health
```
输出结果为:
```
member 9c61b7b4b666f72 is healthy: got healthy result from https://192.168.0.1:2379
member d21cfc0987b4d8f is healthy: got healthy result from https://192.168.0.2:2379
member f4d7a7f4d2a5cee is healthy: got healthy result from https://192.168.0.3:2379
cluster is healthy
```
表示集群状态正常。
阅读全文