其他分享
首页 > 其他分享> > etcd集群部署

etcd集群部署

作者:互联网

版本选择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.58
sht-sgmhadoopdn-03 172.16.101.58

各节点添加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 |
+------------------+---------+--------------------+--------------------------------+-----------------------------------------------------+------------+

 

标签:sht,ETCD,部署,sgmhadoopdn,集群,2379,etcd,http
来源: https://www.cnblogs.com/ilifeilong/p/11622107.html