etcd第二篇etcdctl详解

关于etcd的安装请参考etcd第一篇
本篇主要讲解etcdctl命令使用
查看集群状态
etcdctl --write-out=table --endpoints=$ENDPOINTS endpoint status
etcd第二篇etcdctl详解
我们看到node2成为leader
查看集群成员
etcdctl --endpoints=$ENDPOINTS member list
etcd第二篇etcdctl详解
删除成员:
MEMBER_ID=fa6333c794b010d8
etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 \
member remove ${MEMBER_ID}
我们看到如下结果
etcd第二篇etcdctl详解
同时node3的etcd已经停止工作
添加成员:
注意:添加已经删除的需要将node3的data.etcd必须删除
这里以添加node3为例
在节点上执行如下命令:
NAME_1=node1
NAME_2=node2
NAME_3=node3
HOST_1=172.16.80.201
HOST_2=172.16.80.202
HOST_3=172.16.80.203
etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379 member add ${NAME_3} --peer-urls=http://${HOST_3}:2380
启动新添加的节点,这里使用--initial-cluster-state existing
NAME_1=node1
NAME_2=node2
NAME_3=node3
HOST_1=172.16.80.201
HOST_2=172.16.80.202
HOST_3=172.16.80.203
TOKEN=token-01
CLUSTER_STATE=existing
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
THIS_NAME=${NAME_3}
THIS_IP=${HOST_3}
etcd --data-dir=data.etcd --name ${THIS_NAME} \

--initial-advertise-peer-urls http://${THIS_IP}:2380 \
--listen-peer-urls http://${THIS_IP}:2380 \
--advertise-client-urls http://${THIS_IP}:2379 \
--listen-client-urls http://${THIS_IP}:2379 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE} \
--initial-cluster-token ${TOKEN}
我们做一个测试,是否主节点写入或删除,其余两个节点也会写入或删除,结果如下(表示正确)
[root@node2 ~]# etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 put foo "a"
OK
[root@node2 ~]# etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 get foo
foo
a

[root@node3 ~]# etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 get foo
foo
a

[root@node2 ~]# etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 del foo
1
etcd第二篇etcdctl详解
创建snapshot
etcdctl --endpoints=$ENDPOINTS snapshot save my.db
etcdctl --write-out=table --endpoints=$ENDPOINTS snapshot status my.db
etcd第二篇etcdctl详解
数据迁移:(一般不用,因为etcd是集群,可以添加节点的方式来实现数据迁移,然后删除原有的节点)
etcdctl --endpoints=$ENDPOINT migrate --data-dir="default.etcd" --wal-dir="default.etcd/member/wal"
权限
etcdctl --endpoints=${ENDPOINTS} role add root
etcdctl --endpoints=${ENDPOINTS} role grant-permission root readwrite foo
etcdctl --endpoints=${ENDPOINTS} role get root

etcdctl --endpoints=${ENDPOINTS} user add root
etcdctl --endpoints=${ENDPOINTS} user grant-role root root
etcdctl --endpoints=${ENDPOINTS} user get root

etcdctl --endpoints=${ENDPOINTS} auth enable
#now all client requests go through auth

etcdctl --endpoints=${ENDPOINTS} --user=root:123 put foo bar
etcdctl --endpoints=${ENDPOINTS} get foo
etcdctl --endpoints=${ENDPOINTS} --user=root:123 get foo
etcdctl --endpoints=${ENDPOINTS} --user=root:123 get foo1

参考文章:https://coreos.com/etcd/docs/latest

转载于:https://blog.51cto.com/laodou/2160545

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值