etcd集群的搭建
程序员文章站
2022-07-13 22:19:40
...
Etcd构建自身高可用集群主要有三种形式:
静态发现: 预先已知 Etcd 集群中有哪些节点,在启动时直接指定好Etcd的各个node节点地址
Etcd动态发现: 通过已有的Etcd集群作为数据交互点,然后在扩展新的集群时实现通过已有集群进行服务发现的机制
DNS动态发现: 通过DNS查询方式获取其他节点地址信息
这里我们采用Static方式,准备三台机器,ip如下(都已经安装etcd)
node1 10.211.55.2
node2 10.211.55.25
node3 10.211.55.26
环境准备
1.在node1上执行
hostnamectl set-hostname node1
echo "10.211.55.2 node1">> /etc/hosts
echo 10.211.55.25 node2>> /etc/hosts
echo 10.211.55.26 node3>> /etc/hosts
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
2.在node2上执行
hostnamectl set-hostname node2
echo "10.211.55.2 node1">> /etc/hosts
echo 10.211.55.25 node2>> /etc/hosts
echo 10.211.55.26 node3>> /etc/hosts
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
3.在node3上执行
hostnamectl set-hostname node3
echo "10.211.55.2 node1">> /etc/hosts
echo 10.211.55.25 node2>> /etc/hosts
echo 10.211.55.26 node3>> /etc/hosts
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
1.1进入node1,创建并运行run.sh,脚本内容如下
yum remove etcd -y
yum install etcd -y
mkdir /etcd
cd /etcd
touch run.sh
cat>/etcd/run.sh<<EOF
#!/usr/bin/env bash
#节点名称
ETCD_NAME=node-1
#本机IP地址
LOCAL_IP=10.211.55.2
#ETCD存储目录
ETCD_DATA_DIR=/usr/local/etcd/data
#初始化名称
INITIAL_CLUSTER_TOKEN=etcd-cluster
#初始化群集列表
INITIAL_CLUSTER="node-1=http://10.211.55.2:2380,node-2=http://10.211.55.25:2380,node-3=http://10.211.55.26:2380"
#初始化状态
INITIAL_CLUSTER_STATE=new
#开始运行
etcd --name \${ETCD_NAME} --data-dir \${ETCD_DATA_DIR} \
--initial-advertise-peer-urls http://\${LOCAL_IP}:2380 \
--listen-peer-urls http://\${LOCAL_IP}:2380 \
--listen-client-urls http://\${LOCAL_IP}:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://\${LOCAL_IP}:2379 \
--initial-cluster-token \${INITIAL_CLUSTER_TOKEN} \
--initial-cluster \${INITIAL_CLUSTER} \
--initial-cluster-state \${INITIAL_CLUSTER_STATE}
EOF
nohup sh run.sh &
etcdctl member list
1.2进入node2,创建并运行run.sh,脚本内容如下
yum remove etcd -y
yum install etcd -y
mkdir /etcd
cd /etcd
touch run.sh
cat>/etcd/run.sh<<EOF
#!/usr/bin/env bash
#节点名称
ETCD_NAME=node-2
#本机IP地址
LOCAL_IP=10.211.55.25
#ETCD存储目录
ETCD_DATA_DIR=/usr/local/etcd/data
#初始化名称
INITIAL_CLUSTER_TOKEN=etcd-cluster
#初始化群集列表
INITIAL_CLUSTER="node-1=http://10.211.55.2:2380,node-2=http://10.211.55.25:2380,node-3=http://10.211.55.26:2380"
#初始化状态
INITIAL_CLUSTER_STATE=new
#开始运行
etcd --name \${ETCD_NAME} --data-dir \${ETCD_DATA_DIR} \
--initial-advertise-peer-urls http://\${LOCAL_IP}:2380 \
--listen-peer-urls http://\${LOCAL_IP}:2380 \
--listen-client-urls http://\${LOCAL_IP}:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://\${LOCAL_IP}:2379 \
--initial-cluster-token \${INITIAL_CLUSTER_TOKEN} \
--initial-cluster \${INITIAL_CLUSTER} \
--initial-cluster-state \${INITIAL_CLUSTER_STATE}
EOF
nohup sh run.sh &
etcdctl member list
1.3进入node3,创建并运行run.sh,脚本内容如下
yum remove etcd -y
yum install etcd -y
mkdir /etcd
cd /etcd
touch run.sh
cat>/etcd/run.sh<<EOF
#!/usr/bin/env bash
#节点名称
ETCD_NAME=node-3
#本机IP地址
LOCAL_IP=10.211.55.26
#ETCD存储目录
ETCD_DATA_DIR=/usr/local/etcd/data
#初始化名称
INITIAL_CLUSTER_TOKEN=etcd-cluster
#初始化群集列表
INITIAL_CLUSTER="node-1=http://10.211.55.2:2380,node-2=http://10.211.55.25:2380,node-3=http://10.211.55.26:2380"
#初始化状态
INITIAL_CLUSTER_STATE=new
#开始运行
etcd --name \${ETCD_NAME} --data-dir \${ETCD_DATA_DIR} \
--initial-advertise-peer-urls http://\${LOCAL_IP}:2380 \
--listen-peer-urls http://\${LOCAL_IP}:2380 \
--listen-client-urls http://\${LOCAL_IP}:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://\${LOCAL_IP}:2379 \
--initial-cluster-token \${INITIAL_CLUSTER_TOKEN} \
--initial-cluster \${INITIAL_CLUSTER} \
--initial-cluster-state \${INITIAL_CLUSTER_STATE}
EOF
nohup sh run.sh &
etcdctl member list
通过以上步骤就完成了etcd的配置
2.1搭建etcd web管理端
docker run --rm -d --name etcd-browser \
-p 8000:8000 \
--env ETCD_HOST=10.211.55.25 \
--env ETCD_PORT=2379 \
buddho/etcd-browser
访问http://10.211.55.25:8080/etcdkeeper/,输入etcd的地址就成功了
2.2搭建etcdkeeper
docker run -it -d --name etcdkeeper \
-p 8080:8080 \
deltaprojects/etcdkeeper
访问http://10.211.55.25:8080/etcdkeeper/,输入etcd的地址就成功了
上一篇: 搭建 etcd 集群
下一篇: etcd集群搭建步骤