我是靠谱客的博主 活泼盼望,最近开发中收集的这篇文章主要介绍etcd-http-搭建与节点添加删除,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

tar xf etcd-v3.5.0-linux-amd64.tar.gz
cp
etcd-v3.5.0-linux-amd64/etcd*
/usr/local/bin
mkdir -p /opt/etcd/log;cd /opt/etcd
vim etcd1.sh
etcd
--name etcd1 --data-dir
/opt/etcd/data 
--advertise-client-urls http://192.168.1.11:2379 
--listen-client-urls http://0.0.0.0:2379 
--initial-advertise-peer-urls http://192.168.1.11:2380 
--listen-peer-urls http://0.0.0.0:2380 
--initial-cluster-token etcd-cluster-1 
--initial-cluster etcd1=http://192.168.1.11:2380,etcd2=http://192.168.1.12:2380,etcd3=http://192.168.1.13:2380 --initial-cluster-state new > /opt/etcd/log/etcd.log 2>&1
chmod +x etcd1.sh
nohup ./etcd1.sh &
[root@etcd-1 etcd]# ETCDCTL_API=3 etcdctl --endpoints="http://192.168.1.11:2379,http://192.168.1.12:2379,http://192.168.1.13:2379" endpoint health --write-out=table
+--------------------------+--------+-------------+-------+
|
ENDPOINT
| HEALTH |
TOOK
| ERROR |
+--------------------------+--------+-------------+-------+
| http://192.168.1.11:2379 |
true |
4.368654ms |
|
| http://192.168.1.13:2379 |
true |
4.459495ms |
|
| http://192.168.1.12:2379 |
true | 25.159315ms |
|
+--------------------------+--------+-------------+-------+

查看LEADER

[root@etcd-1 etcd]# ETCDCTL_API=3 etcdctl --endpoints="http://192.168.1.11:2379,http://192.168.1.12:2379,http://192.168.1.13:2379" endpoint status --write-out=table
+--------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
|
ENDPOINT
|
ID
| VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS |
+--------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
| http://192.168.1.11:2379 | c58be7a3e19b0280 |
3.5.0 |
20 kB |
true |
false |
2 |
21 |
21 |
|
| http://192.168.1.12:2379 | 4f42573027e5bd71 |
3.5.0 |
29 kB |
false |
false |
2 |
21 |
21 |
|
| http://192.168.1.13:2379 | 73ddc3b0ec5d4cd7 |
3.5.0 |
25 kB |
false |
false |
2 |
21 |
21 |
|
+--------------------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
[root@etcd-1 etcd]# etcdctl
member
list
4f42573027e5bd71, started, etcd2, http://192.168.1.12:2380, http://192.168.1.12:2379, false
73ddc3b0ec5d4cd7, started, etcd3, http://192.168.1.13:2380, http://192.168.1.13:2379, false
c58be7a3e19b0280, started, etcd1, http://192.168.1.11:2380, http://192.168.1.11:2379, false
[root@etcd-1 etcd]# etcdctl version
etcdctl version: 3.5.0
API version: 3.5
[root@etcd-1 etcd]# etcdctl
put
foo
"bar"
OK
[root@etcd-1 etcd]# etcdctl
get foo
foo
bar

服务重启去掉初始化参数,否则报错

etcd
--name etcd1 --data-dir
/opt/etcd/data 
--advertise-client-urls http://192.168.1.11:2379 
--listen-client-urls http://0.0.0.0:2379 
--listen-peer-urls http://0.0.0.0:2380
> /opt/etcd/log/etcd.log 2>&1
[root@etcd-1 etcd]# etcdctl member add etcd4
--peer-urls=http://192.168.1.14:2380
Member 1c556ab2f6916a5d added to cluster 1b0ea56b6263b784
ETCD_NAME="etcd4"
ETCD_INITIAL_CLUSTER="etcd4=http://192.168.1.14:2380,etcd2=http://192.168.1.12:2380,etcd3=http://192.168.1.13:2380,etcd1=http://192.168.1.11:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.1.14:2380"
ETCD_INITIAL_CLUSTER_STATE="existing"
[root@node4 etcd]# cat etcd4.sh
etcd
--name etcd4 --data-dir
/opt/etcd/data 
--advertise-client-urls http://192.168.1.14:2379 
--listen-client-urls http://0.0.0.0:2379 
--initial-advertise-peer-urls http://192.168.1.14:2380 
--listen-peer-urls http://0.0.0.0:2380 
--initial-cluster-token etcd-cluster-1 
--initial-cluster etcd4=http://192.168.1.14:2380,etcd2=http://192.168.1.12:2380,etcd3=http://192.168.1.13:2380,etcd1=http://192.168.1.11:2380 
--initial-cluster-state existing > /opt/etcd/log/etcd.log 2>&1
[root@node4 etcd]# chmod +x etcd4.sh
[root@node4 etcd]# nohup ./etcd4.sh &
[root@etcd-1 etcd]# etcdctl
member
list
1c556ab2f6916a5d, started, etcd4, http://192.168.1.14:2380, http://192.168.1.14:2379, false
4f42573027e5bd71, started, etcd2, http://192.168.1.12:2380, http://192.168.1.12:2379, false
73ddc3b0ec5d4cd7, started, etcd3, http://192.168.1.13:2380, http://192.168.1.13:2379, false
c58be7a3e19b0280, started, etcd1, http://192.168.1.11:2380, http://192.168.1.11:2379, false
[root@etcd-1 etcd]# ETCDCTL_API=3 etcdctl --endpoints="http://192.168.1.11:2379,http://192.168.1.12:2379,http://192.168.1.13:2379,http://192.168.1.14:2380" endpoint health
http://192.168.1.12:2379 is healthy: successfully committed proposal: took = 11.671236ms
http://192.168.1.11:2379 is healthy: successfully committed proposal: took = 11.555305ms
http://192.168.1.13:2379 is healthy: successfully committed proposal: took = 45.127334ms
http://192.168.1.14:2380 is healthy: successfully committed proposal: took = 49.959045ms
[root@node4 ~]# etcdctl
get foo
foo
bar
[root@etcd-1 etcd]# etcdctl member remove 73ddc3b0ec5d4cd7
[root@node4 ~]# ls /opt/etcd/data/member/snap/
db

数据备份

[root@node4 ~]# ETCDCTL_APl=3 etcdctl snapshot save
/opt/etcd/data/member/snap/bak.db
...
Snapshot saved at /opt/etcd/data/member/snap/bak.db
[root@node4 ~]# ls /opt/etcd/data/member/snap/
db
bak.db
~]# ETCDCTL_APl=3 etcdctl snapshot restore
/opt/etcd/data/member/snap/bak.db

最后

以上就是活泼盼望为你收集整理的etcd-http-搭建与节点添加删除的全部内容,希望文章能够帮你解决etcd-http-搭建与节点添加删除所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部