二进制部署etcd集群

kuberntes 系统使用 etcd 存储所有数据,本文档介绍部署一个三节点高可用 etcd 集群的步骤,这三个节点配置复用 ,我在这里没有做认证,如果有需要也可以做。

下载二进制文件

https://github.com/coreos/etcd/releases 页面下载最新版本的二进制文件

 

# wget https://github.com/etcd-io/etcd/releases/download/v3.2.24/etcd-v3.2.24-linux-amd64.tar.gz

# tar –xvf etcd-v3.2.24-linux-amd64.tar.gz

# mv etcd-v3.2.24-linux-amd64/* /usr/local/bin/

**********************************************************

这里也可以用yum方式安装

# yum install etcd –y
 
yum 安装的 Etcd 默认配置文件在 /etc/etcd/etcd.conf具体配置内容,以下*.*.*.*根据自己实际ip地址。
 
# 编辑配置文件 vim /etc/etcd/etcd.conf 
# 样例配置如下 
# 节点名称 ETCD_NAME=etcd0 
# 数据存放位置 ETCD_DATA_DIR="/var/lib/etcd/etcd0" 
# 监听其他 Etcd 实例的地址 ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" 
# 监听客户端地址 ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001" 
# 通知其他 Etcd 实例地址 ETCD_INITIAL_ADVERTISE_PEER_URLS="http://*.*.*.*:2380" 
# 初始化集群内节点地址 ETCD_INITIAL_CLUSTER="etcd0=http://*.*.*.*:2380,etcd1=http://*.*.*.*:2380,etcd2=http://*.*.*.*:2380" 
# 初始化集群状态,new 表示新建 ETCD_INITIAL_CLUSTER_STATE="new" 
# 初始化集群 token ETCD_INITIAL_CLUSTER_TOKEN="mritd-etcd-cluster" 
# 通知 客户端地址 ETCD_ADVERTISE_CLIENT_URLS="http://*.*.*.*:2379,http://*.*.*.*:4001"
 
************************************************************
 
在/usr/lib/systemd/system/目录下创建文件etcd.service,内容如下
 

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target
Documentation=https://github.com/coreos

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/usr/local/bin/etcd \
   --name ${ETCD_NAME} \
   --initial-advertise-peer-urls ${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
   --listen-peer-urls ${ETCD_LISTEN_PEER_URLS} \
   --listen-client-urls ${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
   --advertise-client-urls ${ETCD_ADVERTISE_CLIENT_URLS} \
   --initial-cluster-token ${ETCD_INITIAL_CLUSTER_TOKEN} \
   --initial-cluster etcd1=http://172.16.*.*:2380,etcd2=http://172.16.*.*:2380,etcd3=http://172.16.*.*:2380 \
   --initial-cluster-state new \
   --data-dir=${ETCD_DATA_DIR}
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

 


环境变量配置文件/etc/etcd/etcd.conf

# [member]
ETCD_NAME=etcd1
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_LISTEN_PEER_URLS=http://172.16.*.*:2380
ETCD_LISTEN_CLIENT_URLS=http://172.16.*.*:2379

#[cluster]
ETCD_INITIAL_ADVERTISE_PEER_URLS=http://172.16.*.*:2380
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_ADVERTISE_CLIENT_URLS=http://172.16.*.*:2379

启动etcd集群(这里的启动先启动etcd2和etcd3,最后启动etcd1)

systemctl daemon-reload
systemctl enable etcd
systemctl start etcd
systemctl status etcd
 
验证etcd集群是否正常

etcdctl cluster-health


member 295f11ee2eb4860f is healthy: got healthy result from http://172.16.*.*:2379
member 52e09c7ccb0e79aa is healthy: got healthy result from http://172.16.*.*:2379
member 58804fbff8cfcce0 is healthy: got healthy result from http://172.16.*.*:2379
cluster is healthy

etcdctl member list

295f11ee2eb4860f: name=etcd3 peerURLs=http://172.16.*.*:2380 clientURLs=http://172.16.*.*:2379 isLeader=false
52e09c7ccb0e79aa: name=etcd1 peerURLs=http://172.16.*.*:2380 clientURLs=http://172.16.*.*:2379 isLeader=false
58804fbff8cfcce0: name=etcd2 peerURLs=http://172.16.*.*:2380 clientURLs=http://172.16.*.*:2379 isLeader=true

可以看到etcd集群正常在etcd2上运行,可以停止etcd2查看etcd是否跳到别的机器上,具体自己测试一下就不过多说明

转载于:https://www.cnblogs.com/only-me/p/10173850.html

你可能感兴趣的:(二进制部署etcd集群)