1. etcd单机安装
配置地址:https://github.com/etcd-io/etcd/releases
创建脚本,执行脚本
ETCD_VER=v3.5.0
# choose either URL
GOOGLE_URL=https://storage.googleapis.com/etcd
GITHUB_URL=https://github.com/etcd-io/etcd/releases/download
DOWNLOAD_URL=${GOOGLE_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
/tmp/etcd-download-test/etcdutl version
启动etcd,测试单机的etcd
# start a local etcd server
/tmp/etcd-download-test/etcd
# write,read to etcd
/tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 put foo bar
/tmp/etcd-download-test/etcdctl --endpoints=localhost:2379 get foo
2. etcd集群搭建
准备:三台服务器
10.20.11.209;10.20.13.123;10.20.15.154
etcd安装包:https://github.com/etcd-io/etcd/releases/download/v3.4.16/etcd-v3.4.16-linux-amd64.tar.gz
在三台机器上分别执行下述命令:
mkdir -p /data/app/etcd3.4
mkdir /data/app/etcd3.4/etcdData
#下载 对应的版本安装包
tar xzvf etcd-v3.4.16-linux-amd64.tar.gz
在三台服务器上分别创建etcd.yaml文件:
#10.20.11.209
##etcd实例名称/10.20.11.209
name: etcd03
#etcd数据保存目录
data-dir: /data/app/etcd3.4/etcdData
#供外部客户端使用的url
listen-client-urls: 'http://0.0.0.0:2379'
advertise-client-urls: 'http://0.0.0.0:2379'
#集群内部通信使用的URL
listen-peer-urls: 'http://10.20.11.209:2380'
#广播给集群内其他成员访问的URL
initial-advertise-peer-urls: 'http://10.20.11.209:2380'
#初始集群成员列表
initial-cluster:
etcd01=http://10.20.15.154:2380,etcd02=http://10.20.13.123:2380,etcd03=http://10.20.11.209:2380
#集群的名称
initial-cluster-token: etcd-cluster
#初始集群状态,new为新建集群
initial-cluster-state: new
同理:#etcd实例名称/10.20.15.154
name: etcd01
data-dir: /data/app/etcd3.4/etcdData
listen-client-urls: 'http://0.0.0.0:2379'
advertise-client-urls: 'http://0.0.0.0:2379'
listen-peer-urls: 'http://10.20.15.154:2380'
initial-advertise-peer-urls: 'http://10.20.15.154:2380'
initial-cluster: etcd01=http://10.20.15.154:2380,etcd02=http://10.20.13.123:2380,etcd03=http://10.20.11.209:2380
initial-cluster-token: ycch-etcd-cluster
initial-cluster-state: new
name: etcd02
data-dir: /data/app/etcd3.4/etcdData
listen-client-urls: 'http://0.0.0.0:2379'
advertise-client-urls: 'http://0.0.0.0:2379'
listen-peer-urls: 'http://10.20.13.123:2380'
initial-advertise-peer-urls: 'http://10.20.13.123:2380'
initial-cluster: etcd01=http://10.20.15.154:2380,etcd02=http://10.20.13.123:2380,etcd03=http://10.20.11.209:2380
initial-cluster-token: ycch-etcd-cluster
initial-cluster-state: new
启动命令:/data/app/etcd3.4/etcd-v3.4.16-linux-amd64/etcd —config-file=/data/app/etcd3.4/etcd.yaml &
3. 验证集群:
./etcdctl --endpoints http://10.20.15.154:2379,http://10.20.13.123:2379,http://10.20.11.209:2379 member list
./etcdctl --endpoints http://10.20.15.154:2379,http://10.20.13.123:2379,http://10.20.11.209:2379 endpoint health
./etcdctl --write-out=table --endpoints=http://10.20.15.154:2379,http://10.20.13.123:2379,http://10.20.11.209:2379 member list
./etcdctl --write-out=table --endpoints=http://10.20.15.154:2379,http://10.20.13.123:2379,http://10.20.11.209:2379 endpoint status