版本选择v3.4.1
https://github.com/etcd-io/etcd/releases/download/v3.4.1/etcd-v3.4.1-linux-amd64.tar.gz
三节点信息
主机名 | IP地址 |
sht-sgmhadoopdn-01 | 172.16.101.58 |
sht-sgmhadoopdn-02 | 172.16.101.59 |
sht-sgmhadoopdn-03 | 172.16.101.60 |
各节点添加hosts文件解析
# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.101.58 sht-sgmhadoopdn-01 172.16.101.59 sht-sgmhadoopdn-02 172.16.101.60 sht-sgmhadoopdn-03
创建运行etcd的用户和组
# groupadd -r dba
# useradd -r -g dba -G root tnuser
下载解压etcd
# cd /usr/local/ # wget https://github.com/etcd-io/etcd/releases/download/v3.4.1/etcd-v3.4.1-linux-amd64.tar.gz # tar -zxf etcd-v3.4.1-linux-amd64.tar.gz # ln -s etcd-v3.4.1-linux-amd64 etcd # mkdir /usr/local/etcd/data # chown -R tnuser.dba /usr/local/etcd-v3.4.1-linux-amd64
新建etcd配置文件etcd.conf,各节点配置文件内容如下
sht-sgmhadoopdn-01
# cat /usr/local/etcd/etcd.conf ETCD_NAME="sht-sgmhadoopdn-01" ETCD_DATA_DIR="/usr/local/etcd/data" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://sht-sgmhadoopdn-01:2379,http://10.0.0.1:2379" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://sht-sgmhadoopdn-01:2380" ETCD_INITIAL_CLUSTER="sht-sgmhadoopdn-01=http://sht-sgmhadoopdn-01:2380,sht-sgmhadoopdn-02=http://sht-sgmhadoopdn-02:2380,sht-sgmhadoopdn-03=http://sht-sgmhadoopdn-03:2380" ETCD_ENABLE_V2="true"
sht-sgmhadoopdn-02
# cat /usr/local/etcd/etcd.conf ETCD_NAME="sht-sgmhadoopdn-02" ETCD_DATA_DIR="/usr/local/etcd/data" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://sht-sgmhadoopdn-02:2379,http://10.0.0.1:2379" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://sht-sgmhadoopdn-02:2380" ETCD_INITIAL_CLUSTER="sht-sgmhadoopdn-01=http://sht-sgmhadoopdn-01:2380,sht-sgmhadoopdn-02=http://sht-sgmhadoopdn-02:2380,sht-sgmhadoopdn-03=http://sht-sgmhadoopdn-03:2380"
sht-sgmhadoopdn-03
# cat /usr/local/etcd/etcd.conf ETCD_NAME="sht-sgmhadoopdn-03" ETCD_DATA_DIR="/usr/local/etcd/data" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01" ETCD_INITIAL_CLUSTER_STATE="new" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://sht-sgmhadoopdn-02:2379,http://10.0.0.1:2379" ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380" ETCD_INITIAL_ADVERTISE_PEER_URLS="http://sht-sgmhadoopdn-03:2380" ETCD_INITIAL_CLUSTER="sht-sgmhadoopdn-01=http://sht-sgmhadoopdn-01:2380,sht-sgmhadoopdn-02=http://sht-sgmhadoopdn-02:2380,sht-sgmhadoopdn-03=http://sht-sgmhadoopdn-03:2380"
为etcd配置系统服务,各节点的etcd.service文件内容如下
# cat /usr/lib/systemd/system/etcd.service [Unit] Description=etcd service Documentation=https://github.com/etcd-io/etcd After=network.target After=network-online.target Wants=network-online.target [Service] User=tnuser Type=notify EnvironmentFile=/usr/local/etcd/etcd.conf WorkingDirectory=/usr/local/etcd ExecStart=/usr/local/etcd/etcd Restart=always RestartSec=10s LimitNOFILE=65536 [Install] WantedBy=multi-user.target
各节点启动etcd服务
# systemctl daemon-reload
# systemctl start etcd
查看集群信息
# etcdctl endpoint status --endpoints http://sht-sgmhadoopdn-01:2379,http://sht-sgmhadoopdn-02:2379,http://sht-sgmhadoopdn-03:2379 --write-out=table +--------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +--------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | http://sht-sgmhadoopdn-01:2379 | 44d8bc3300880bcd | 3.4.1 | 16 kB | true | false | 8 | 11 | 11 | | | http://sht-sgmhadoopdn-02:2379 | e9136c1ad1754783 | 3.4.1 | 16 kB | false | false | 8 | 11 | 11 | | | http://sht-sgmhadoopdn-03:2379 | d446fbe3296eb85a | 3.4.1 | 16 kB | false | false | 8 | 11 | 11 | | +--------------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ # etcdctl endpoint health --endpoints http://sht-sgmhadoopdn-01:2379,http://sht-sgmhadoopdn-02:2379,http://sht-sgmhadoopdn-03:2379 --write-out=table +--------------------------------+--------+------------+-------+ | ENDPOINT | HEALTH | TOOK | ERROR | +--------------------------------+--------+------------+-------+ | http://sht-sgmhadoopdn-02:2379 | true | 5.23352ms | | | http://sht-sgmhadoopdn-01:2379 | true | 5.832925ms | | | http://sht-sgmhadoopdn-03:2379 | true | 6.431018ms | | +--------------------------------+--------+------------+-------+ # etcdctl member list --write-out=table +------------------+---------+--------------------+--------------------------------+-----------------------------------------------------+------------+ | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER | +------------------+---------+--------------------+--------------------------------+-----------------------------------------------------+------------+ | 44d8bc3300880bcd | started | sht-sgmhadoopdn-01 | http://sht-sgmhadoopdn-01:2380 | http://10.0.0.1:2379,http://sht-sgmhadoopdn-01:2379 | false | | d446fbe3296eb85a | started | sht-sgmhadoopdn-03 | http://sht-sgmhadoopdn-03:2380 | http://10.0.0.1:2379,http://sht-sgmhadoopdn-02:2379 | false | | e9136c1ad1754783 | started | sht-sgmhadoopdn-02 | http://sht-sgmhadoopdn-02:2380 | http://10.0.0.1:2379,http://sht-sgmhadoopdn-02:2379 | false | +------------------+---------+--------------------+--------------------------------+-----------------------------------------------------+------------+
修改各节点etcd.conf配置文件如下参数
原
ETCD_INITIAL_CLUSTER_STATE="new"
修改为
ETCD_INITIAL_CLUSTER_STATE="existing"
重启各节点
# systemctl stop etcd
# systemctl start etcd
注:该修改步骤不是必须的,只是为了使后续进行节点增加时候保持各配置文件一致性,该参数只是在添加新节点进入集群中才会起作用,重启现有集群会忽略该参数。
===================来自一泽涟漪的博客,转载请标明出处 www.cnblogs.com/ilifeilong===================