poorX

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
配置
node1
name: etcd-1

data-dir: /data/etcd/node1

listen-client-urls: http://127.0.0.1:6701

advertise-client-urls: http://127.0.0.1:6701

listen-peer-urls: http://127.0.0.1:16701

initial-advertise-peer-urls: http://127.0.0.1:16701

initial-cluster: etcd-1=http://127.0.0.1:16701,etcd-2=http://127.0.0.1:16702,etcd-3=http://127.0.0.1:16703

initial-cluster-token: etcd-cluster-token

initial-cluster-state: new
cd /data/packages/etcd-v3.5.4-linux-amd64;./etcd --config-file=/data/etcd/node1/conf.yml
node2
name: etcd-2

data-dir: /data/etcd/node2

listen-client-urls: http://127.0.0.1:6702

advertise-client-urls: http://127.0.0.1:6702

listen-peer-urls: http://127.0.0.1:16702

initial-advertise-peer-urls: http://127.0.0.1:16702

initial-cluster: etcd-1=http://127.0.0.1:16701,etcd-2=http://127.0.0.1:16702,etcd-3=http://127.0.0.1:16703

initial-cluster-token: etcd-cluster-token

initial-cluster-state: new
cd /data/packages/etcd-v3.5.4-linux-amd64;./etcd --config-file=/data/etcd/node2/conf.yml
node3
name: etcd-3

data-dir: /data/etcd/node3

listen-client-urls: http://127.0.0.1:6703

advertise-client-urls: http://127.0.0.1:6703

listen-peer-urls: http://127.0.0.1:16703

initial-advertise-peer-urls: http://127.0.0.1:16703

initial-cluster: etcd-1=http://127.0.0.1:16701,etcd-2=http://127.0.0.1:16702,etcd-3=http://127.0.0.1:16703

initial-cluster-token: etcd-cluster-token

initial-cluster-state: new
cd /data/packages/etcd-v3.5.4-linux-amd64;./etcd --config-file=/data/etcd/node3/conf.yml
集群状态命令
# 查看节点状态
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' --write-out=table endpoint status

# 查看节点信息
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' --write-out=table member list
数据操作命令
# 写数据
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' put user 'user'
OK

# 获取数据
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' get user
user
user

# json形式获取数据
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' --write-out='json' get user
{"header":{"cluster_id":14495651392122646756,"member_id":9121633945989494648,"revision":3,"raft_term":7},"kvs":[{"key":"dXNlcg==","create_revision":2,"mod_revision":3,"version":2,"value":"amlhbmd4dQ=="}],"count":1}

# 前缀方式获取数据
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' --write-out='json' get user --prefix
{"header":{"cluster_id":14495651392122646756,"member_id":2265291478623953179,"revision":6,"raft_term":7},"kvs":[{"key":"dXNlcjE=","create_revision":5,"mod_revision":5,"version":1,"value":"amlhbmd4dQ=="},{"key":"dXNlcjI=","create_revision":6,"mod_revision":6,"version":1,"value":"aGFoYQ=="}],"count":2}

# 删除数据
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' del user
1
监视数据
# 监视数据可以看到相关key的事件
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' watch user --prefix
租约
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' lease list
found 0 leases
# lease创建后会分配ID
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' lease grant 30
lease 211b80fe02999707 granted with TTL(30s)
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' lease list
found 1 leases
211b80fe02999707
# 使用key并给key分配lease
# 如果lease在grant超时,lease和lease对应的key都会删除
./etcdctl --endpoints='127.0.0.1:6701,127.0.0.1:6702,127.0.0.1:6703' put user3 'test' --lease=211b80fe02999707
posted on 2022-05-26 17:17  poorX  阅读(22)  评论(0编辑  收藏  举报