一、静态配置部署 etcd 集群

主机名私网 IP
etcd01172.17.86.250
etcd02172.17.86.251
etcd03172.17.86.252

二、下载并安装

  • GitHub 地址:https://github.com/etcd-io/etcd/releases/
  • 官网地址:https://etcd.io/docs/v3.5/install/
  • k8s地址:https://kubernetes.io/zh/docs/tasks/administer-cluster/configure-upgrade-etcd/

2.1 GitHub安装指导(此处参考)

ETCD_VER=v3.5.0

# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GOOGLE_URL}

rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
rm -rf /tmp/etcd-download-test && mkdir -p /tmp/etcd-download-test

curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download-test --strip-components=1
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz

/tmp/etcd-download-test/etcd --version
/tmp/etcd-download-test/etcdctl version
/tmp/etcd-download-test/etcdutl version

# start a local etcd server
/tmp/etcd-download-test/etcd

# write,read to etcd
/tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 put foo bar
/tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 get foo
2.2 下载并安装
cat get_etcd_package.sh
ETCD_VER=v3.5.0

GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GITHUB_URL}  #下载地址,二选一,此处选 GITHUB_URL

mkdir -p /usr/local/etcd # 创建安装目录

curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /usr/local/etcd-${ETCD_VER}-linux-amd64.tar.gz
tar xzvf /usr/local/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /usr/local/etcd/ --strip-components=1  # 解压并指定解压路径 usr/local/etcd/

#/usr/local/etcd/etcd --version
#/usr/local/etcd/etcdctl version
chmod +x get_etcd_package.sh
sh get_etcd_package.sh
3、创建数据存储目录
mkdir /usr/local/etcd/data
4、设置配置文件
      创建配置文件 /usr/local/etcd/conf.yml,三个节点配置文件内容分别如下:

(1)etcd01:172.17.86.250
name: etcd01
data-dir: /usr/local/etcd/data
initial-advertise-peer-urls: http://172.17.86.250:2380
listen-peer-urls: http://172.17.86.250:2380
listen-client-urls: http://172.17.86.250:2379,http://127.0.0.1:2379
advertise-client-urls: http://172.17.86.250:2379
initial-cluster-token: my-etcd-cluster
initial-cluster: etcd01=http://172.17.86.250:2380,etcd02=http://172.17.86.251:2380,etcd03=http://172.17.86.252:2380
initial-cluster-state: new
(2)etcd02:172.17.86.251
name: etcd02
data-dir: /usr/local/etcd/data
initial-advertise-peer-urls: http://172.17.86.251:2380
listen-peer-urls: http://172.17.86.251:2380
listen-client-urls: http://172.17.86.251:2379,http://127.0.0.1:2379
advertise-client-urls: http://172.17.86.251:2379
initial-cluster-token: my-etcd-cluster
initial-cluster: etcd01=http://172.17.86.250:2380,etcd02=http://172.17.86.251:2380,etcd03=http://172.17.86.252:2380
initial-cluster-state: new
(3)etcd03:172.17.86.252
name: etcd03
data-dir: /usr/local/etcd/data
initial-advertise-peer-urls: http://172.17.86.252:2380
listen-peer-urls: http://172.17.86.252:2380
listen-client-urls: http://172.17.86.252:2379,http://127.0.0.1:2379
advertise-client-urls: http://172.17.86.252:2379
initial-cluster-token: my-etcd-cluster
initial-cluster: etcd01=http://172.17.86.250:2380,etcd02=http://172.17.86.251:2380,etcd03=http://172.17.86.252:2380
initial-cluster-state: new
(4)配置参数说明:
	name:当前etcd节点名称。
	data-dir:数据存储目录。
	initial-advertise-peer-urls:集群的其他节点通过该地址与当前节点通信。
	listen-peer-urls:当前节点通过该地址监听集群其他节点发送的信息。
	listen-client-urls:当前节点通过该地址监听客户端发送的信息。
	advertise-client-urls:客户端通过该地址与当前节点通信
	initial-cluster-token:用于区分不同的集群,同一集群的所有节点配置相同的值。
	initial-cluster:当前集群的所有节点信息,当前节点根据此信息与其他节点取得联系。
	initial-cluster-state: 本次是否为新建集群,有两个取值:new和existing。

三、开放端口(此处不执行,仅供参考)

etcd server默认使用2379端口监听客户端的请求,使用2380端口监听其他server的请求。本文配置使用的也是2379和2380两个端口。

(1)开放 2379 和 2380 两个端口:
firewall-cmd --zone=public --add-port=2379/tcp --permanent
firewall-cmd --zone=public --add-port=2380/tcp --permanent
(2)重启防火墙:
firewall-cmd --reload
(3)验证端口是否开放成功:
firewall-cmd --zone=public --query-port=2379/tcp
firewall-cmd --zone=public --query-port=2380/tcp

四、配置服务

(1)创建服务配置文件 /usr/lib/systemd/system/etcd.service,内容如下:
[Unit]
Description=etcd
After=network.target
 
[Service]
Type=notify
ExecStart=/usr/local/etcd/etcd --config-file=/usr/local/etcd/conf.yml
 
[Install]
WantedBy=multi-user.target
(2)启动服务:
systemctl daemon-reload
systemctl start etcd.service
(3)查看服务是否启动成功:
systemctl status etcd.service
(4)设置服务为开机自启动:
systemctl enable etcd.service

五、验证

(1)将 etcdctl 二进制文件复制到 /usr/local/bin/ 目录下,方便执行命令:

cp /usr/local/etcd/etcdctl /usr/local/bin/

(2)查看集群成员列表:

[root@etcd02 etcd]# etcdctl member list

6af7376e529f02f, started, etcd03, http://172.17.86.252:2380, http://172.17.86.252:2379, false
6e7aa2f6e450a1e7, started, etcd02, http://172.17.86.251:2380, http://172.17.86.251:2379, false
f9509c61761f7beb, started, etcd01, http://172.17.86.250:2380, http://172.17.86.250:2379, false

(3)查看集群LEADER:

etcdctl --endpoints=http://172.17.86.250:2380,http://172.17.86.251:2380,http://172.17.86.252:2380 endpoint status  -w table

在这里插入图片描述
(4)查看集群健康状况:

[root@etcd02 etcd]# etcdctl --endpoints=http://172.17.86.250:2380,http://172.17.86.251:2380,http://172.17.86.252:2380 endpoint health
http://172.17.86.252:2380 is healthy: successfully committed proposal: took = 2.120406ms
http://172.17.86.251:2380 is healthy: successfully committed proposal: took = 2.086449ms
http://172.17.86.250:2380 is healthy: successfully committed proposal: took = 2.090922ms
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐