一、单机安装部署
etcd version:v3.5.2
1.二进制包脚本安装ETCD_VER=v3.5.2
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GITHUB_URL}
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
rm -rf /tmp/etcd-download
mkdir -p /tmp/etcd-download
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 --strip-components=1
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
/tmp/etcd-download/etcd --version
/tmp/etcd-download/etcdctl version
执行后,查看 etcd 版本的结果如下:
2.源码编译(1)安装 Go 语言环境
参考:Download and install - The Go Programming Language安装 Go 语言环境,版本为 1.13+。
(2)克隆etcd源码并编译
参考:etcd中文文档 | 下载并构建
3.docker安装 docker-compose.ymlversion: "3.5"
services:
etcd:
hostname: etcd
image: bitnami/etcd:3
deploy:
replicas: 1
restart_policy:
condition: on-failure
# ports:
# - "2379:2379"
# - "2380:2380"
# - "4001:4001"
# - "7001:7001"
privileged: true
volumes:
- "/etcd/data:/opt/bitnami/etcd/data"
environment:
- "ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379"
- "ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379"
- "ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380"
- "ETCD_INITIAL_ADVERTISE_PEER_URLS=http://0.0.0.0:2380"
- "ALLOW_NONE_AUTHENTICATION=yes"
- "ETCD_INITIAL_CLUSTER=node1=http://0.0.0.0:2380"
- "ETCD_NAME=node1"
- "ETCD_DATA_DIR=/opt/bitnami/etcd/data"
ports:
- 2379:2379
- 2380:2380
networks:
- etcdnet
networks:
etcdnet:
name: etcdnet
二、集群安装部署
引导 etcd 集群的启动有以下三种方式:
静态启动静态启动 etcd 集群的方式要求每个成员都知道集群中的其他成员。然而很多场景中,群集成员的 IP 可能未知。因此需要借助发现服务引导 etcd 群集启动。
etcd 动态发现DNS 发现docker部署集群docker-compose.yml
version: '3'
services:
etcd1:
image: "quay.io/coreos/etcd:v3.4.7"
container_name: etcd1
entrypoint: /usr/local/bin/etcd
networks:
- etcd-net
command:
- '--name=etcd1'
- '--data-dir=/etcd_data'
- '--initial-advertise-peer-urls=http://etcd1:2380'
- '--listen-peer-urls=http://0.0.0.0:2380'
- '--listen-client-urls=http://0.0.0.0:2379'
- '--advertise-client-urls=http://etcd1:2379'
- '--initial-cluster-token=mys1cr2tt1k7n'
- '--heartbeat-interval=250'
- '--election-timeout=1250'
- '--initial-cluster=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380'
- '--initial-cluster-state=new'
ports:
- "12379:2379"
- "20001:2380"
volumes:
- /usr/local/etcd-cluster/etcd1/data:/etcd_data
etcd2:
image: "quay.io/coreos/etcd:v3.4.7"
container_name: etcd2
entrypoint: /usr/local/bin/etcd
networks:
- etcd-net
command:
- '--name=etcd2'
- '--data-dir=/etcd_data'
- '--initial-advertise-peer-urls=http://etcd2:2380'
- '--listen-peer-urls=http://0.0.0.0:2380'
- '--listen-client-urls=http://0.0.0.0:2379'
- '--advertise-client-urls=http://etcd2:2379'
- '--initial-cluster-token=mys1cr2tt1k7n'
- '--heartbeat-interval=250'
- '--election-timeout=1250'
- '--initial-cluster=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380'
- '--initial-cluster-state=new'
ports:
- "22379:2379"
- "20003:2380"
volumes:
- /usr/local/etcd-cluster/etcd2/data:/etcd_data
etcd3:
image: "quay.io/coreos/etcd:v3.4.7"
container_name: etcd3
entrypoint: /usr/local/bin/etcd
networks:
- etcd-net
command:
- '--name=etcd3'
- '--data-dir=/etcd_data'
- '--initial-advertise-peer-urls=http://etcd3:2380'
- '--listen-peer-urls=http://0.0.0.0:2380'
- '--listen-client-urls=http://0.0.0.0:2379'
- '--advertise-client-urls=http://etcd3:2379'
- '--initial-cluster-token=mys1cr2tt1k7n'
- '--heartbeat-interval=250'
- '--election-timeout=1250'
- '--initial-cluster=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380'
- '--initial-cluster-state=new'
ports:
- "32379:2379"
- "20005:2380"
volumes:
- /usr/local/etcd-cluster/etcd3/data:/etcd_data
networks:
etcd-net: # 网络
driver: bridge # 桥接模式
验证集群信息:
三、etcd 通信安全
etcd 支持通过 TLS 协议进行的加密通信,TLS 通道可用于对等体(指 etcd 集群中的服务实例)之间的加密内部群集通信以及加密的客户端流量。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)