欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

etcd集群搭建

程序员文章站 2022-07-13 22:20:10
...

etcd集群搭建

  • 环境
 -  centos  192.168.3.65  node-1
 -  centos  192.168.3.66  node-2
  • 关闭防火墙
systemctl stop firewalld
  • etcd使用yum安装
yum install etcd
cp /etc/etcd/etcd.conf   /etc/etcd/etcd.conf.bak
  • 集群配置

192.168.3.65 node-1 配置

vim /etc/etcd/etcd.conf

#[Member]
#ETCD_CORS=""
#ETCD_WAL_DIR=""
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"  #到数据目录的路径.
ETCD_LISTEN_PEER_URLS="http://192.168.3.65:2380" #用于监听伙伴通讯的URL列表
ETCD_LISTEN_CLIENT_URLS="http://192.168.3.65:2379, http://127.0.0.1:2379" #用于监听客户端通讯的URL列表
ETCD_NAME=node-1 #成员的可读性的名字
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"
#ETCD_SNAPSHOT_COUNT="100000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
#ETCD_QUOTA_BACKEND_BYTES="0"
#ETCD_MAX_REQUEST_BYTES="1572864"
#ETCD_GRPC_KEEPALIVE_MIN_TIME="5s"
#ETCD_GRPC_KEEPALIVE_INTERVAL="2h0m0s"
#ETCD_GRPC_KEEPALIVE_TIMEOUT="20s"
#
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.3.65:2380" #列出这个成员的伙伴 URL 以便通告给集群的其他成员
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.3.65:2379" #列出这个成员的客户端URL,通告给集群中的其他成员
ETCD_INITIAL_CLUSTER="node-1=http://192.168.3.65:2380,node-2=http://192.168.3.66:2380" #为启动初始化集群配置
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #在启动期间用于 etcd 集群的初始化集群记号(cluster token)
ETCD_INITIAL_CLUSTER_STATE="new" #初始化集群状态(“new” or “existing”)
#ETCD_DISCOVERY=""
#ETCD_DISCOVERY_FALLBACK="proxy"
#ETCD_DISCOVERY_PROXY=""
#ETCD_DISCOVERY_SRV=""
#ETCD_STRICT_RECONFIG_CHECK="true"
#ETCD_ENABLE_V2="true"

192.168.3.66 node-2 配置

vim /etc/etcd/etcd.conf

#[Member]
#ETCD_CORS=""
#ETCD_WAL_DIR=""
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.3.66:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.3.66:2379,http://127.0.0.1:2379"
ETCD_NAME=node-2
#ETCD_MAX_SNAPSHOTS="5"
#ETCD_MAX_WALS="5"

#ETCD_SNAPSHOT_COUNT="100000"
#ETCD_HEARTBEAT_INTERVAL="100"
#ETCD_ELECTION_TIMEOUT="1000"
#ETCD_QUOTA_BACKEND_BYTES="0"
#ETCD_MAX_REQUEST_BYTES="1572864"
#ETCD_GRPC_KEEPALIVE_MIN_TIME="5s"
#ETCD_GRPC_KEEPALIVE_INTERVAL="2h0m0s"
#ETCD_GRPC_KEEPALIVE_TIMEOUT="20s"
#
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.3.66:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.3.66:2379"
ETCD_INITIAL_CLUSTER="node-1=http://192.168.3.65:2380,node-2=http://192.168.3.66:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
#ETCD_DISCOVERY=""
#ETCD_DISCOVERY_FALLBACK="proxy"
#ETCD_DISCOVERY_PROXY=""
#ETCD_DISCOVERY_SRV=""
#ETCD_STRICT_RECONFIG_CHECK="true"
#ETCD_ENABLE_V2="true"

  • 启动ectd
systemctl start etcd
  • 验证集群
[[email protected] default.etcd]# etcdctl cluster-health
member c7e28f19b18e5b07 is healthy: got healthy result from http://192.168.3.66:2379
member dabb45fbb8cd1a2b is healthy: got healthy result from http://192.168.3.65:2379
cluster is healthy

[[email protected] default.etcd]# etcdctl member list
c7e28f19b18e5b07: name=node-2 peerURLs=http://192.168.3.66:2380 clientURLs=http://192.168.3.66:2379 isLeader=false
dabb45fbb8cd1a2b: name=node-1 peerURLs=http://192.168.3.65:2380 clientURLs=http://192.168.3.65:2379 isLeader=true