安装
Centos 7 使用如下方式进行安装:
#/bin/bash
ETCD_VER=v3.4.4
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-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
单机部署
集群部署
在生产环境中,为了整个集群的高可用,etcd 正常都是集群部署,避免单点故障。引导etcd 集群启动有以下3种方式:
- 静态
静态启动的etcd 集群的方式需要每个成员都知道集群中的其他成员 - etcd 动态发现
- DNS 发现
静态方式启动
这里我们使用goreman 整个多进程管理工具来完成ectd集群搭建,首先安装 goreman 这个工具。
# go get github.com/mattn/goreman
然后新建 /opt/profile,加入如下内容:
etcdl: etcd --name infral --listen-client-urls http://127.0.0.1:12379 --advertise-client-urls http://127.0.0.1:12379 \
--listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token \
etcd-cluster-1 --initial-cluster 'infral=http://127.0.0.1:12380, infra2=http://127.0.0.1:22380, infra3=http://127.0.0.1:32380'
-initial -cluster-state new --enable-pprof --logger=zap --log-outputs=stderr
执行goreman -f /opt/profile
启动集群。
启动完成后,可使用命令查看集群内的成员:
# etcdctl --endpoint=http://localhost:22379 member list
动态方式启动
在上面的方式中,我们是以静态的方式指定集群成员,但在实际生产环境中,集群成员的IP可能不会提前知道。
网友评论