ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ETCD 集群搭建-静态配置方式

2022-05-17 08:31:57  阅读:164  来源: 互联网

标签:etcd1 http ETCD -- 192.168 集群 etcd 节点 搭建


参考1:https://zhuanlan.zhihu.com/p/405811320

参考2:https://blog.csdn.net/liuhuayang/article/details/122834141

 

ETCD 启动相关参数:

  —data-dir 指定节点的数据存储目录,这些数据包括节点ID,集群ID,集群初始化配置,Snapshot文件,若未指定—wal-dir,还会存储WAL文件;

  —wal-dir 指定节点的was文件的存储目录,若指定了该参数,wal文件会和其他数据文件分开存储。

  —name 节点名称

  —initial-advertise-peer-urls 告知集群其他节点url.

  — listen-peer-urls 监听URL,用于与其他节点通讯

  — advertise-client-urls 告知客户端url, 也就是服务的url

  — initial-cluster-token 集群的ID

  — initial-cluster 集群中所有节点

 

ETCD下载:

  github: https://github.com/etcd-io/etcd/releases/tag/v3.5.4

  -rw-r--r--  1 root   root  19432359 May 17 07:05 etcd-v3.5.4-linux-amd64.tar.gz

 

集群安装:

  节点信息:

    hostname    ip

    etcd1      192.168.123.160

    etcd2      192.168.123.161

    etcd3      192.168.123.162

  测试环境避免带来不必要的困扰,请先关闭防火墙、SELinux、如果之前使用过 iptables 请检查 iptables 规则,如汝不懂 iptables 可直接跳过。关闭 防火墙、SELinux 具体操作请找隔壁老王。

  配置主机名和/etc/hosts: 非必须步骤,只是个人习惯,方便后续操作而已;  

# 设置主机名 三台主机均设置
hostnamectl set-hostname etcd1

  hosts文件配置 三台主机配置一致

[root@etcd1 etcd-v3.5.4-linux-amd64]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


192.168.123.160 etcd1
192.168.123.161 etcd2
192.168.123.162 etcd3

  在etcd1节点配置密钥,将其它两个节点设置密钥登录:非必须

    生成密钥:ssh-keygen

    将密钥拷贝其它节点:ssh-copy-id 

    具体操作,找隔壁老王。

  重点:任何集群在配置前,请一定先同步好集群节点的时间,避免入坑。

  操作节点 etcd1   解压安装包:

]# tar -xzvf etcd-v3.5.4-linux-amd64.tar.gz

  操作节点 etcd1 修改文件及文件夹的属主属组:此处不讨论权限最小安全运行,只是测试环境运行体验

]# chown -R root:root ./etcd-v3.5.4-linux-amd64

  操作节点 etcd1 安装:

]# cp -a ./etcd* /usr/bin/

  操作节点 etcd1 其它节点安装:

[root@etcd1 etcd-v3.5.4-linux-amd64]# scp ./etcd* etcd2:/usr/bin/
etcd                                                                   100%   22MB 110.4MB/s   00:00
etcdctl                                                                100%   17MB 132.4MB/s   00:00
etcdutl                                                                100%   15MB 121.8MB/s   00:00
[root@etcd1 etcd-v3.5.4-linux-amd64]# scp ./etcd* etcd3:/usr/bin/
etcd                                                                   100%   22MB 124.7MB/s   00:00
etcdctl                                                                100%   17MB 134.7MB/s   00:00
etcdutl                                                                100%   15MB 114.9MB/s   00:00
[root@etcd1 etcd-v3.5.4-linux-amd64]# ssh etcd2 "etcd --version"
etcd Version: 3.5.4
Git SHA: 08407ff76
Go Version: go1.16.15
Go OS/Arch: linux/amd64
[root@etcd1 etcd-v3.5.4-linux-amd64]# ssh etcd3 "etcd --version"
etcd Version: 3.5.4
Git SHA: 08407ff76
Go Version: go1.16.15
Go OS/Arch: linux/amd64

   创建ETCD数据存储目录:所有节点

]# mkdir -p /data/etcdData

  配置service文件:etcd1

[root@etcd1 system]# cat /usr/lib/systemd/system/etcd.service
[Unit]

Description=etcd service
Documentation=https://github.com/coreos/etcd

[Service]

User=root
Type=notify
ExecStart=/usr/bin/etcd \
 --name etcd1 \
 --data-dir /data/etcdData \
 --initial-advertise-peer-urls http://192.168.123.160:2380 \
 --listen-peer-urls http://192.168.123.160:2380 \
 --listen-client-urls http://192.168.123.160:2379,http://127.0.0.1:2379 \
 --advertise-client-urls http://192.168.123.160:2379 \
 --initial-cluster-token etcd-cluster \
 --initial-cluster etcd1=http://192.168.123.160:2380,etcd2=http://192.168.123.161:2380,etcd3=http://192.168.123.162:2380 \
 --initial-cluster-state new \
 --heartbeat-interval 1000 \
 --election-timeout 5000
Restart=on-failure
RestartSec=5

[Install]

WantedBy=multi-user.target

  etcd2:

[root@etcd2 ~]# cat /usr/lib/systemd/system/etcd.service
[Unit]

Description=etcd service
Documentation=https://github.com/coreos/etcd

[Service]

User=root
Type=notify
ExecStart=/usr/bin/etcd \
 --name etcd2 \
 --data-dir /data/etcdData \
 --initial-advertise-peer-urls http://192.168.123.161:2380 \
 --listen-peer-urls http://192.168.123.161:2380 \
 --listen-client-urls http://192.168.123.161:2379,http://127.0.0.1:2379 \
 --advertise-client-urls http://192.168.123.161:2379 \
 --initial-cluster-token etcd-cluster \
 --initial-cluster etcd1=http://192.168.123.160:2380,etcd2=http://192.168.123.161:2380,etcd3=http://192.168.123.162:2380 \
 --initial-cluster-state new \
 --heartbeat-interval 1000 \
 --election-timeout 5000
Restart=on-failure
RestartSec=5

[Install]

WantedBy=multi-user.target

  etcd3:

[root@etcd3 ~]# cat /usr/lib/systemd/system/etcd.service
[Unit]

Description=etcd service
Documentation=https://github.com/coreos/etcd

[Service]

User=root
Type=notify
ExecStart=/usr/bin/etcd \
 --name etcd3 \
 --data-dir /data/etcdData \
 --initial-advertise-peer-urls http://192.168.123.162:2380 \
 --listen-peer-urls http://192.168.123.162:2380 \
 --listen-client-urls http://192.168.123.162:2379,http://127.0.0.1:2379 \
 --advertise-client-urls http://192.168.123.162:2379 \
 --initial-cluster-token etcd-cluster \
 --initial-cluster etcd1=http://192.168.123.160:2380,etcd2=http://192.168.123.161:2380,etcd3=http://192.168.123.162:2380 \
 --initial-cluster-state new \
 --heartbeat-interval 1000 \
 --election-timeout 5000
Restart=on-failure
RestartSec=5

[Install]

WantedBy=multi-user.target

  注意:所有节点在修改、新建service文件后都需要执行 systemctl daemon-reload

  启动:

    先启动 etcd1:systemctl start etcd.service   注意:不用管状态,启动命令执行后会卡住一会,可以先不用管,接着启动第二个节点即可;

    启动 etcd2:systemctl start etcd.service

    启动 etcd3:systemctl start etcd.service

    如果 etcd1 报异常,执行 systemctl restart etcd.service 即可

  弊端:此种方式将集群配置信息写入service文件,在集群之启动一个节点的时候,etcd是已经启动了,但是集群相关信息则是失败的,导致 systemctl  返回是失败的,此时端口已经监听,可以继续启动其它节点,待其它节点启动成功后,则可以返回第一个节点,重启下第一个节点的服务即可。

 

  验证:  

[root@etcd1 system]# etcdctl member list --write-out=table
+------------------+---------+-------+-----------------------------+-----------------------------+------------+
|        ID        | STATUS  | NAME  |         PEER ADDRS          |        CLIENT ADDRS         | IS LEARNER |
+------------------+---------+-------+-----------------------------+-----------------------------+------------+
| 2f107ed12dcf060d | started | etcd2 | http://192.168.123.161:2380 | http://192.168.123.161:2379 |      false |
| 4f36d86f7d67fa14 | started | etcd1 | http://192.168.123.160:2380 | http://192.168.123.160:2379 |      false |
| 89d28152c949347f | started | etcd3 | http://192.168.123.162:2380 | http://192.168.123.162:2379 |      false |
+------------------+---------+-------+-----------------------------+-----------------------------+------------+

  

 

标签:etcd1,http,ETCD,--,192.168,集群,etcd,节点,搭建
来源: https://www.cnblogs.com/buray/p/16279436.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有