下载安装包
选择不同系统的安装包,也可以自己编译
wget https://github.com/etcd-io/etcd/releases/download/v3.3.13/etcd-v3.3.13-linux-amd64.tar.gz
解压缩加入环境变量
-- 解压缩
tar -zxvf etcd-v3.3.13-linux-amd64.tar.gz
export ETCD_HOME=/opt/etcd/etcd-v3.3.13
export PATH=$PATH:$ETCD_HOME
-- 检查是否生效
etcd -version
启动单机版
etcd
etcd -listen-client-urls="http://0.0.0.0:2379" --advertise-client-urls="http://0.0.0.0:2379"
-- 查看是否生效
curl http://172.19.0.2:2379/version
配置单机多节点
配置node1.yml
name: node01
data-dir: /opt/etcd/data/node1
listen-client-urls: http://172.19.0.2:10001,http://127.0.0.1:10001
advertise-client-urls: http://172.19.0.2:10001
initial-advertise-peer-urls: http://172.19.0.2:9001
listen-peer-urls: http://172.19.0.2:9001
#初始化名称
#initial-cluster-token: token-test-cluster
#初始化群集列表
initial-cluster: node01=http://172.19.0.2:9001,node02=http://172.19.0.2:9002,node03=http://172.19.0.2:9003
#初始化状态(new|existing)
initial-cluster-state: new
配置node2.yml
name: node02
data-dir: /opt/etcd/data/node2
listen-client-urls: http://172.19.0.2:10002,http://127.0.0.1:10002
advertise-client-urls: http://172.19.0.2:10002
initial-advertise-peer-urls: http://172.19.0.2:9002
listen-peer-urls: http://172.19.0.2:9002
#初始化名称
#initial-cluster-token: token-test-cluster
#初始化群集列表
initial-cluster: node01=http://172.19.0.2:9001,node02=http://172.19.0.2:9002,node03=http://172.19.0.2:9003
#初始化状态(new|existing)
initial-cluster-state: new
配置node3.yml
name: node03
data-dir: /opt/etcd/data/node3
listen-client-urls: http://172.19.0.2:10003,http://127.0.0.1:10003
advertise-client-urls: http://172.19.0.2:10003
initial-advertise-peer-urls: http://172.19.0.2:9003
listen-peer-urls: http://172.19.0.2:9003
#初始化名称
#initial-cluster-token: token-test-cluster
#初始化群集列表
initial-cluster: node01=http://172.19.0.2:9001,node02=http://172.19.0.2:9002,node03=http://172.19.0.2:9003
#初始化状态(new|existing)
initial-cluster-state: new
启动服务
nohup etcd --config-file=/opt/etcd/node1.yml > /opt/etcd/node1.out &
nohup etcd --config-file=/opt/etcd/node2.yml > /opt/etcd/node2.out &
nohup etcd --config-file=/opt/etcd/node3.yml > /opt/etcd/node3.out &
-- 如果不需要日志,可以输出到/dev/null
nohup etcd --config-file=/opt/etcd/node1.yml > /dev/null &
检测成功与否
etcdctl --endpoints http://172.19.0.2:10001,http://172.19.0.2:10002,http://172.19.0.2:10003 member list
etcdctl --endpoints http://172.19.0.2:10001,http://172.19.0.2:10002,http://172.19.0.2:10003 set /cqh muscle