etcd分布式集群搭建及高可用验证
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
目录
- 一.etcd概述
- 二.分布式集群搭建及高可用验证
- 1 下载etcd的软件包
- 2 解压etcd的二进制程序包到PATH环境变量路径
- 3 将软件包下发到所有节点
- 4.安装cfssl证书管理工具
- 5.创建证书存储目录
- 6.生成证书的CSR文件: 证书签发请求文件,配置了一些域名,公司,单位
- 7.生成etcd CA证书和CA证书的key
- 8.生成etcd证书的有效期为100年
- 9.生成证书的CSR文件: 证书签发请求文件,配置了一些域名,公司,单位
- 10.基于自建的ectd ca证书生成etcd的证书
- 11.将etcd证书拷贝到其他两个master节点
- 12.创建etcd集群各节点配置文件
- 13.所有节点编写etcd启动脚本
- 14.所有节点启动etcd集群
- 15.查看etcd集群状态
- 三.验证etcd高可用集群
一.etcd概述
1.什么是etcd
推荐阅读:
https://github.com/etcd-io/etcd
https://etcd.io/docs/
etcd是分布式系统中最关键数据的分布式可靠键值存储,重点是:
简单:定义明确、面向用户的API(gRPC)
安全:自动TLS,可选客户端证书身份验证
快速:以每秒10000次写入为基准
可靠:使用Raft正确分布
etcd是用Go编写的,并使用Raft共识算法来管理高可用的复制日志。
etcd被许多公司用于生产环境,开发团队在关键部署场景中支持它,其中etcd经常与Kubernetes、locksmith、vulcan、Doorman等应用程序合作。严格的稳健性测试进一步确保了可靠性。
etcd使用http协议工作,支持tls,生产环境中一般使用的是https访问。
etcdctl是一个用于与etcd服务器交互的命令行工具,用户大多通过输入或获取键的值与etcd进行交互。
etcdctl用来与etcd对话的API版本可以通过etcdctl_API环境变量设置为版本2或3。
默认情况下,"etcdctl 3.4+"的etcdctl使用v3 API,早期版本"etcdctl 3.3-"默认为v2 API。
值得注意的是,etcd v2版本写入的数据无法通过v3的版本进行查询,说白了,就是高版本不兼容低版本,相当于v3重写了etcd。
生产环境中,官方推荐使用v3版本。
2.etcd的双端口作用
- 2379: HTTP|HTTPS
对客户端使用。
- 2380: TCP
etcd集群内部使用。
3.安装etcd的方式
包管理方式安装: 安装简单,但是版本低
apt -y install etcd-client
二进制方式安装:可以安装任意版本(参考etcd相关的安装笔记即可)
https://www.cnblogs.com/yinzhengjie/p/18265994
二.分布式集群搭建及高可用验证
1 下载etcd的软件包
wget https://github.com/etcd-io/etcd/releases/download/v3.5.21/etcd-v3.5.21-linux-amd64.tar.gz
svip:
[root@node-exporter41 ~]# wget http://192.168.17.253/Resources/Prometheus/softwares/Etcd/etcd-v3.5.21-linux-amd64.tar.gz
2 解压etcd的二进制程序包到PATH环境变量路径
[root@node-exporter41 ~]# tar -xf etcd-v3.5.21-linux-amd64.tar.gz -C /usr/local/bin etcd-v3.5.21-linux-amd64/etcd{,ctl} --strip-components=1
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# ll /usr/local/bin/etcd*
-rwxr-xr-x 1 yinzhengjie yinzhengjie 24072344 Mar 28 06:58 /usr/local/bin/etcd*
-rwxr-xr-x 1 yinzhengjie yinzhengjie 18419864 Mar 28 06:58 /usr/local/bin/etcdctl*
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# etcdctl version
etcdctl version: 3.5.21
API version: 3.5
[root@node-exporter41 ~]#
3 将软件包下发到所有节点
[root@node-exporter41 ~]# scp /usr/local/bin/etcd* 10.0.0.42:/usr/local/bin
[root@node-exporter41 ~]# scp /usr/local/bin/etcd* 10.0.0.43:/usr/local/bin
4.安装cfssl证书管理工具
[root@node-exporter41 ~]# wget http://192.168.17.253/Resources/Prometheus/softwares/Etcd/yinzhengjie-cfssl-v1.6.5.zip
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# unzip yinzhengjie-cfssl-v1.6.5.zip
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# apt install rename
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# rename -v "s/_1.6.5_linux_amd64//g" cfssl*
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# mv cfssl* /usr/local/bin/
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# chmod +x /usr/local/bin/cfssl*
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# ll /usr/local/bin/cfssl*
-rwxr-xr-x 1 root root 11890840 Jun 15 11:56 /usr/local/bin/cfssl*
-rwxr-xr-x 1 root root 8413336 Jun 15 11:56 /usr/local/bin/cfssl-certinfo*
-rwxr-xr-x 1 root root 6205592 Jun 15 11:56 /usr/local/bin/cfssljson*
[root@node-exporter41 ~]#
5.创建证书存储目录
[root@node-exporter41 ~]# mkdir -pv /yinzhengjie/certs/etcd && cd /yinzhengjie/certs/etcd/
6.生成证书的CSR文件: 证书签发请求文件,配置了一些域名,公司,单位
[root@node-exporter41 etcd]# cat > etcd-ca-csr.json <<EOF
{
"CN": "etcd",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "Beijing",
"L": "Beijing",
"O": "etcd",
"OU": "Etcd Security"
}
],
"ca": {
"expiry": "876000h"
}
}
EOF
7.生成etcd CA证书和CA证书的key
[root@node-exporter41 etcd]# cfssl gencert -initca etcd-ca-csr.json | cfssljson -bare /yinzhengjie/certs/etcd/etcd-ca
[root@node-exporter41 etcd]#
[root@node-exporter41 etcd]# ll /yinzhengjie/certs/etcd/etcd-ca*
-rw-r--r-- 1 root root 1050 Nov 15 10:42 /yinzhengjie/certs/etcd/etcd-ca.csr
-rw-r--r-- 1 root root 249 Nov 15 10:42 /yinzhengjie/certs/etcd/etcd-ca-csr.json
-rw------- 1 root root 1675 Nov 15 10:42 /yinzhengjie/certs/etcd/etcd-ca-key.pem
-rw-r--r-- 1 root root 1318 Nov 15 10:42 /yinzhengjie/certs/etcd/etcd-ca.pem
[root@node-exporter41 etcd]#
8.生成etcd证书的有效期为100年
[root@node-exporter41 etcd]# cat > ca-config.json <<EOF
{
"signing": {
"default": {
"expiry": "876000h"
},
"profiles": {
"kubernetes": {
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
],
"expiry": "876000h"
}
}
}
}
EOF
9.生成证书的CSR文件: 证书签发请求文件,配置了一些域名,公司,单位
[root@node-exporter41 etcd]# cat > etcd-csr.json <<EOF
{
"CN": "etcd",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "Beijing",
"L": "Beijing",
"O": "etcd",
"OU": "Etcd Security"
}
]
}
EOF
10.基于自建的ectd ca证书生成etcd的证书
[root@node-exporter41 etcd]# cfssl gencert \
-ca=/yinzhengjie/certs/etcd/etcd-ca.pem \
-ca-key=/yinzhengjie/certs/etcd/etcd-ca-key.pem \
-config=ca-config.json \
--hostname=127.0.0.1,node-exporter41,node-exporter42,node-exporter43,10.0.0.41,10.0.0.42,10.0.0.43 \
--profile=kubernetes \
etcd-csr.json | cfssljson -bare /yinzhengjie/certs/etcd/etcd-server
[root@k8s-master01 pki]# ll /yinzhengjie/certs/etcd/etcd-server*
-rw-r--r-- 1 root root 1131 Jun 24 15:18 /yinzhengjie/certs/etcd/etcd-server.csr
-rw------- 1 root root 1679 Jun 24 15:18 /yinzhengjie/certs/etcd/etcd-server-key.pem
-rw-r--r-- 1 root root 1464 Jun 24 15:18 /yinzhengjie/certs/etcd/etcd-server.pem
[root@k8s-master01 pki]#
11.将etcd证书拷贝到其他两个master节点
[root@node-exporter41 etcd]# scp -r /yinzhengjie/certs/ 10.0.0.42:/yinzhengjie
[root@node-exporter41 etcd]# scp -r /yinzhengjie/certs/ 10.0.0.43:/yinzhengjie
[root@node-exporter42 ~]# ll /yinzhengjie/certs/etcd/
total 44
drwxr-xr-x 2 root root 4096 Nov 15 10:49 ./
drwxr-xr-x 3 root root 4096 Nov 15 10:49 ../
-rw-r--r-- 1 root root 294 Nov 15 10:49 ca-config.json
-rw-r--r-- 1 root root 1050 Nov 15 10:49 etcd-ca.csr
-rw-r--r-- 1 root root 249 Nov 15 10:49 etcd-ca-csr.json
-rw------- 1 root root 1675 Nov 15 10:49 etcd-ca-key.pem
-rw-r--r-- 1 root root 1318 Nov 15 10:49 etcd-ca.pem
-rw-r--r-- 1 root root 210 Nov 15 10:49 etcd-csr.json
-rw-r--r-- 1 root root 1143 Nov 15 10:49 etcd-server.csr
-rw------- 1 root root 1679 Nov 15 10:49 etcd-server-key.pem
-rw-r--r-- 1 root root 1476 Nov 15 10:49 etcd-server.pem
[root@node-exporter42 ~]#
[root@node-exporter43 ~]# ll /yinzhengjie/certs/etcd/
total 44
drwxr-xr-x 2 root root 4096 Nov 15 10:49 ./
drwxr-xr-x 3 root root 4096 Nov 15 10:49 ../
-rw-r--r-- 1 root root 294 Nov 15 10:49 ca-config.json
-rw-r--r-- 1 root root 1050 Nov 15 10:49 etcd-ca.csr
-rw-r--r-- 1 root root 249 Nov 15 10:49 etcd-ca-csr.json
-rw------- 1 root root 1675 Nov 15 10:49 etcd-ca-key.pem
-rw-r--r-- 1 root root 1318 Nov 15 10:49 etcd-ca.pem
-rw-r--r-- 1 root root 210 Nov 15 10:49 etcd-csr.json
-rw-r--r-- 1 root root 1143 Nov 15 10:49 etcd-server.csr
-rw------- 1 root root 1679 Nov 15 10:49 etcd-server-key.pem
-rw-r--r-- 1 root root 1476 Nov 15 10:49 etcd-server.pem
[root@node-exporter43 ~]#
12.创建etcd集群各节点配置文件
12.1 node-exporter41节点的配置文件
[root@node-exporter41 ~]# mkdir -pv /yinzhengjie/softwares/etcd
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# cat > /yinzhengjie/softwares/etcd/etcd.config.yml <<'EOF'
name: 'node-exporter41'
data-dir: /var/lib/etcd
wal-dir: /var/lib/etcd/wal
snapshot-count: 5000
heartbeat-interval: 100
election-timeout: 1000
quota-backend-bytes: 0
listen-peer-urls: 'https://10.0.0.41:2380'
listen-client-urls: 'https://10.0.0.41:2379,http://127.0.0.1:2379'
max-snapshots: 3
max-wals: 5
cors:
initial-advertise-peer-urls: 'https://10.0.0.41:2380'
advertise-client-urls: 'https://10.0.0.41:2379'
discovery:
discovery-fallback: 'proxy'
discovery-proxy:
discovery-srv:
initial-cluster: 'node-exporter41=https://10.0.0.41:2380,node-exporter42=https://10.0.0.42:2380,node-exporter43=https://10.0.0.43:2380'
initial-cluster-token: 'etcd-k8s-cluster'
initial-cluster-state: 'new'
strict-reconfig-check: false
enable-v2: true
enable-pprof: true
proxy: 'off'
proxy-failure-wait: 5000
proxy-refresh-interval: 30000
proxy-dial-timeout: 1000
proxy-write-timeout: 5000
proxy-read-timeout: 0
client-transport-security:
cert-file: '/yinzhengjie/certs/etcd/etcd-server.pem'
key-file: '/yinzhengjie/certs/etcd/etcd-server-key.pem'
client-cert-auth: true
trusted-ca-file: '/yinzhengjie/certs/etcd/etcd-ca.pem'
auto-tls: true
peer-transport-security:
cert-file: '/yinzhengjie/certs/etcd/etcd-server.pem'
key-file: '/yinzhengjie/certs/etcd/etcd-server-key.pem'
peer-client-cert-auth: true
trusted-ca-file: '/yinzhengjie/certs/etcd/etcd-ca.pem'
auto-tls: true
debug: false
log-package-levels:
log-outputs: [default]
force-new-cluster: false
EOF
12.2 node-exporter42节点的配置文件
[root@node-exporter42 ~]# mkdir -pv /yinzhengjie/softwares/etcd
[root@node-exporter42 ~]#
[root@node-exporter42 ~]# cat > /yinzhengjie/softwares/etcd/etcd.config.yml <<'EOF'
name: 'node-exporter42'
data-dir: /var/lib/etcd
wal-dir: /var/lib/etcd/wal
snapshot-count: 5000
heartbeat-interval: 100
election-timeout: 1000
quota-backend-bytes: 0
listen-peer-urls: 'https://10.0.0.42:2380'
listen-client-urls: 'https://10.0.0.42:2379,http://127.0.0.1:2379'
max-snapshots: 3
max-wals: 5
cors:
initial-advertise-peer-urls: 'https://10.0.0.42:2380'
advertise-client-urls: 'https://10.0.0.42:2379'
discovery:
discovery-fallback: 'proxy'
discovery-proxy:
discovery-srv:
initial-cluster: 'node-exporter41=https://10.0.0.41:2380,node-exporter42=https://10.0.0.42:2380,node-exporter43=https://10.0.0.43:2380'
initial-cluster-token: 'etcd-k8s-cluster'
initial-cluster-state: 'new'
strict-reconfig-check: false
enable-v2: true
enable-pprof: true
proxy: 'off'
proxy-failure-wait: 5000
proxy-refresh-interval: 30000
proxy-dial-timeout: 1000
proxy-write-timeout: 5000
proxy-read-timeout: 0
client-transport-security:
cert-file: '/yinzhengjie/certs/etcd/etcd-server.pem'
key-file: '/yinzhengjie/certs/etcd/etcd-server-key.pem'
client-cert-auth: true
trusted-ca-file: '/yinzhengjie/certs/etcd/etcd-ca.pem'
auto-tls: true
peer-transport-security:
cert-file: '/yinzhengjie/certs/etcd/etcd-server.pem'
key-file: '/yinzhengjie/certs/etcd/etcd-server-key.pem'
peer-client-cert-auth: true
trusted-ca-file: '/yinzhengjie/certs/etcd/etcd-ca.pem'
auto-tls: true
debug: false
log-package-levels:
log-outputs: [default]
force-new-cluster: false
EOF
12.3 node-exporter43节点的配置文件
[root@node-exporter43 ~]# mkdir -pv /yinzhengjie/softwares/etcd
[root@node-exporter43 ~]#
[root@node-exporter43 ~]# cat > /yinzhengjie/softwares/etcd/etcd.config.yml <<'EOF'
name: 'node-exporter43'
data-dir: /var/lib/etcd
wal-dir: /var/lib/etcd/wal
snapshot-count: 5000
heartbeat-interval: 100
election-timeout: 1000
quota-backend-bytes: 0
listen-peer-urls: 'https://10.0.0.43:2380'
listen-client-urls: 'https://10.0.0.43:2379,http://127.0.0.1:2379'
max-snapshots: 3
max-wals: 5
cors:
initial-advertise-peer-urls: 'https://10.0.0.43:2380'
advertise-client-urls: 'https://10.0.0.43:2379'
discovery:
discovery-fallback: 'proxy'
discovery-proxy:
discovery-srv:
initial-cluster: 'node-exporter41=https://10.0.0.41:2380,node-exporter42=https://10.0.0.42:2380,node-exporter43=https://10.0.0.43:2380'
initial-cluster-token: 'etcd-k8s-cluster'
initial-cluster-state: 'new'
strict-reconfig-check: false
enable-v2: true
enable-pprof: true
proxy: 'off'
proxy-failure-wait: 5000
proxy-refresh-interval: 30000
proxy-dial-timeout: 1000
proxy-write-timeout: 5000
proxy-read-timeout: 0
client-transport-security:
cert-file: '/yinzhengjie/certs/etcd/etcd-server.pem'
key-file: '/yinzhengjie/certs/etcd/etcd-server-key.pem'
client-cert-auth: true
trusted-ca-file: '/yinzhengjie/certs/etcd/etcd-ca.pem'
auto-tls: true
peer-transport-security:
cert-file: '/yinzhengjie/certs/etcd/etcd-server.pem'
key-file: '/yinzhengjie/certs/etcd/etcd-server-key.pem'
peer-client-cert-auth: true
trusted-ca-file: '/yinzhengjie/certs/etcd/etcd-ca.pem'
auto-tls: true
debug: false
log-package-levels:
log-outputs: [default]
force-new-cluster: false
EOF
13.所有节点编写etcd启动脚本
cat > /usr/lib/systemd/system/etcd.service <<'EOF'
[Unit]
Description=Jason Yin's Etcd Service
Documentation=https://coreos.com/etcd/docs/latest/
After=network.target
[Service]
Type=notify
ExecStart=/usr/local/bin/etcd --config-file=/yinzhengjie/softwares/etcd/etcd.config.yml
Restart=on-failure
RestartSec=10
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
Alias=etcd3.service
EOF
14.所有节点启动etcd集群
systemctl daemon-reload && systemctl enable --now etcd
systemctl status etcd
15.查看etcd集群状态
[root@node-exporter43 ~]# etcdctl --endpoints="https://10.0.0.41:2379,https://10.0.0.42:2379,https://10.0.0.43:2379" --cacert=/yinzhengjie/certs/etcd/etcd-ca.pem --cert=/yinzhengjie/certs/etcd/etcd-server.pem --key=/yinzhengjie/certs/etcd/etcd-server-key.pem endpoint status --write-out=table
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| https://10.0.0.41:2379 | 9378902f41df91e9 | 3.5.21 | 20 kB | false | false | 2 | 9 | 9 | |
| https://10.0.0.42:2379 | 18f972748ec1bd96 | 3.5.21 | 20 kB | true | false | 2 | 9 | 9 | |
| https://10.0.0.43:2379 | a3dfd2d37c461ee9 | 3.5.21 | 20 kB | false | false | 2 | 9 | 9 | |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@node-exporter43 ~]#
三.验证etcd高可用集群
1 停止leader节点
[root@node-exporter42 ~]# ss -ntl | egrep "2379|2380"
LISTEN 0 4096 127.0.0.1:2379 0.0.0.0:*
LISTEN 0 4096 10.0.0.42:2379 0.0.0.0:*
LISTEN 0 4096 10.0.0.42:2380 0.0.0.0:*
[root@node-exporter42 ~]#
[root@node-exporter42 ~]# systemctl stop etcd
[root@node-exporter42 ~]#
[root@node-exporter42 ~]# ss -ntl | egrep "2379|2380"
[root@node-exporter42 ~]#
2 查看现有集群环境,发现新leader诞生
[root@node-exporter43 ~]# etcdctl --endpoints="https://10.0.0.41:2379,https://10.0.0.42:2379,https://10.0.0.43:2379" --cacert=/yinzhengjie/certs/etcd/etcd-ca.pem --cert=/yinzhengjie/certs/etcd/etcd-server.pem --key=/yinzhengjie/certs/etcd/etcd-server-key.pem endpoint status --write-out=table
{"level":"warn","ts":"2025-05-15T11:54:52.261675+0800","logger":"etcd-client","caller":"v3@v3.5.21/retry_interceptor.go:63","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc00035a000/10.0.0.41:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: Error while dialing: dial tcp 10.0.0.42:2379: connect: connection refused\""}
Failed to get the status of endpoint https://10.0.0.42:2379 (context deadline exceeded)
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| https://10.0.0.41:2379 | 9378902f41df91e9 | 3.5.21 | 20 kB | true | false | 3 | 10 | 10 | |
| https://10.0.0.43:2379 | a3dfd2d37c461ee9 | 3.5.21 | 20 kB | false | false | 3 | 10 | 10 | |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@node-exporter43 ~]#
[root@node-exporter43 ~]#
[root@node-exporter43 ~]#
[root@node-exporter43 ~]# etcdctl --endpoints="https://10.0.0.41:2379,https://10.0.0.43:2379" --cacert=/yinzhengjie/certs/etcd/etcd-ca.pem --cert=/yinzhengjie/certs/etcd/etcd-server.pem --key=/yinzhengjie/certs/etcd/etcd-server-key.pem endpoint status --write-out=table
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| https://10.0.0.41:2379 | 9378902f41df91e9 | 3.5.21 | 20 kB | true | false | 3 | 10 | 10 | |
| https://10.0.0.43:2379 | a3dfd2d37c461ee9 | 3.5.21 | 20 kB | false | false | 3 | 10 | 10 | |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@node-exporter43 ~]#
3 再将之前的leader起来
[root@node-exporter42 ~]# ss -ntl | egrep "2379|2380"
[root@node-exporter42 ~]#
[root@node-exporter42 ~]#
[root@node-exporter42 ~]# systemctl start etcd
[root@node-exporter42 ~]#
[root@node-exporter42 ~]# ss -ntl | egrep "2379|2380"
LISTEN 0 4096 127.0.0.1:2379 0.0.0.0:*
LISTEN 0 4096 10.0.0.42:2379 0.0.0.0:*
LISTEN 0 4096 10.0.0.42:2380 0.0.0.0:*
[root@node-exporter42 ~]#
[root@node-exporter42 ~]#
[root@node-exporter42 ~]# etcdctl --endpoints="https://10.0.0.41:2379,https://10.0.0.42:2379,https://10.0.0.43:2379" --cacert=/yinzhengjie/certs/etcd/etcd-ca.pem --cert=/yinzhengjie/certs/etcd/etcd-server.pem --key=/yinzhengjie/certs/etcd/etcd-server-key.pem endpoint status --write-out=table
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| https://10.0.0.41:2379 | 9378902f41df91e9 | 3.5.21 | 20 kB | true | false | 3 | 11 | 11 | |
| https://10.0.0.42:2379 | 18f972748ec1bd96 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
| https://10.0.0.43:2379 | a3dfd2d37c461ee9 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
+------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@node-exporter42 ~]#
4.添加别名
4.1 添加别名
[root@node-exporter41 ~]# vim .bashrc
...
alias etcdctl='etcdctl --endpoints="10.0.0.41:2379,10.0.0.42:2379,10.0.0.43:2379" --cacert=/yinzhengjie/certs/etcd/etcd-ca.pem --cert=/yinzhengjie/certs/etcd/etcd-server.pem --key=/yinzhengjie/certs/etcd/etcd-server-key.pem '
...
[root@node-exporter41 ~]# source .bashrc
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# etcdctl endpoint status --write-out=table
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 10.0.0.41:2379 | 9378902f41df91e9 | 3.5.21 | 20 kB | true | false | 3 | 11 | 11 | |
| 10.0.0.42:2379 | 18f972748ec1bd96 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
| 10.0.0.43:2379 | a3dfd2d37c461ee9 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# scp .bashrc 10.0.0.42:~
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# scp .bashrc 10.0.0.43:~
4.2 测试验证 【需要断开重连】
[root@node-exporter42 ~]# etcdctl endpoint status --write-out=table
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 10.0.0.41:2379 | 9378902f41df91e9 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
| 10.0.0.42:2379 | 18f972748ec1bd96 | 3.5.21 | 20 kB | true | false | 3 | 11 | 11 | |
| 10.0.0.43:2379 | a3dfd2d37c461ee9 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@node-exporter42 ~]#
[root@node-exporter43 ~]# etcdctl endpoint status --write-out=table
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| 10.0.0.41:2379 | 9378902f41df91e9 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
| 10.0.0.42:2379 | 18f972748ec1bd96 | 3.5.21 | 20 kB | true | false | 3 | 11 | 11 | |
| 10.0.0.43:2379 | a3dfd2d37c461ee9 | 3.5.21 | 20 kB | false | false | 3 | 11 | 11 | |
+----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@node-exporter43 ~]#
本文来自博客园,作者:尹正杰,转载请注明原文链接:https://www.cnblogs.com/yinzhengjie/p/18850637,个人微信: "JasonYin2020"(添加时请备注来源及意图备注,有偿付费)
当你的才华还撑不起你的野心的时候,你就应该静下心来学习。当你的能力还驾驭不了你的目标的时候,你就应该沉下心来历练。问问自己,想要怎样的人生。