etcd 单节点在线扩容

发布 : 2019-01-30 分类 : 运维 浏览 :

etcd单节点在线扩容

环境说明

主机
hostname | ip |commit
—|—|—
master190 | 10.60.0.190 |目录为单实例,添加以下两个节点为集群
master191 | 10.60.0.191 |
master192 | 10.60.0.192 |

版本

1
2
3
4
5
# etcd -version
etcd Version: 3.1.6
Git SHA: e5b7ee2
Go Version: go1.7.5
Go OS/Arch: linux/amd64

1.修改配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
vim /etc/sysconfig/etcd
[Unit]
Description=etcd server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/usr/bin/etcd --name master190 --initial-advertise-peer-urls http://10.60.0.190:2380 --listen-peer-urls http://10.60.0.190:2380 --listen-client-urls http://10.60.0.190:2379,http://127.0.0.1:2379 --advertise-client-urls http://10.60.0.190:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster master190=http://10.60.0.190:2380 --initial-cluster-state new --data-dir=/xdfapp/data/etcd2
Restart=on-failure
RestartSec=5
LimitNOFILE=65536


[Install]
WantedBy=multi-user.target


# 修改ExecStart=从 --initial-cluster-token etcd-cluster-1 之后为新增行
# --initial-cluster-token 每个集群单独配置一个token认证
# -initial-cluster 参数中配置的url地址必须与各个节点启动时设置的initial-advertise-peer-urls参数相同。(initial-advertise-peer-urls参数表示节点监听其他节点同步信号的地址),暂时先只写一个节点,后续在添加,不然会无法启动etcd
# --initial-cluster-state new 参数为new的话为新集群否则existing
# --data-dir 数据存储目录
# 其它etcd参数说明可参考 http://blog.csdn.net/kmhysoft/article/details/71106995

2.注册新节点

1
2
3
4
5

$ curl http://127.0.0.1:2379/v2/members -XPOST -H "Content-Type: application/json" -d '{"peerURLs":["http://10.60.0.191:2380"]}.'
{"id":"bfdca515712d1805","name":"","peerURLs":["http://10.60.0.191:2380"],"clientURLs":[]}

# 这里输入的为新增加的节点:peerURLs":["http://10.60.0.191:2380"]

3.查看节点,注册后未启动节点,状态会是不健康的

1
2
3
4
5
6
7
8
9
$ curl  http://10.60.0.190:2379/v2/members
{"members":[{"id":"4aea52ebe6d79782","name":"master190","peerURLs":["http://10.60.0.190:2380"],"clientURLs":["http://10.60.0.190:2379"]},{"id":"bfdca515712d1805","name":"ma
ster191","peerURLs":["http://10.60.0.191:2380"],"clientURLs":["http://10.60.0.191:2379"]}]}

$ etcdctl cluster-health
member 4aea52ebe6d79782 is unhealthy: got unhealthy result from http://10.60.0.190:2379
failed to check the health of member bfdca515712d1805 on http://10.60.0.191:2379: Get http://10.60.0.191:2379/health: dial tcp 10.60.0.191:2379: getsockopt: connection refu
sedmember bfdca515712d1805 is unreachable: [http://10.60.0.191:2379] are all unreachable
cluster is unhealthy

4.修改节点配置

1
2
3
4
5
6
7
8
9
10
cat /usr/lib/systemd/system/etcd.service 
[Unit]
Description=ETCD
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/etcd
ExecStart=/usr/local/bin/etcd --name master191 --initial-advertise-peer-urls http://10.60.0.191:2380 --listen-peer-urls http://10.60.0.191:2380 --listen-client-urls http://10.60.0.191:2379,http://127.0.0.1:2379 --advertise-client-urls http://10.60.0.191:2379 --initial-cluster-token etcd-cluster-1 --initial-cluster master190=http://10.60.0.190:2380,master191=http://10.60.0.191:2380 --initial-cluster-state existing --data-dir=/xdfapp/data/etcdRestart=always

# 在--initial-cluster 增加了master191=http://10.60.0.191:2380
# 修改--initial-cluster-state 状态为 existing

5.修改完后启动etcd,并查看集群状态

1
2
3
4
5
$ systemctl start etcd
$ etcdctl cluster-health
member 4aea52ebe6d79782 is healthy: got healthy result from http://10.60.0.190:2379
member bfdca515712d1805 is healthy: got healthy result from http://10.60.0.191:2379
cluster is healthy

添加其它节点重复2-5步骤即可,注意第4步配置文件的修改

删除一个节点:etcdctl member remove <etcd_id>

本文作者 : WGY
原文链接 : http://geeklive.cn/2019/01/30/etcd/undefined/etcd/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
留下足迹