标签:适合 get 窗口 cli 0.0.0.0 listen let 基本 3.3
下载,解压,进入目录,运行:[root@bogon etcd-v3.3.12-linux-amd64]# ./etcd --listen-client-urls ‘http://0.0.0.0:2379‘ --advertise-client-urls ‘http://0.0.0.0:2379‘
(本地etcd的端口)
etcd控制工具:
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl
(前面需要一个环境变量ETCDCTL_API=3)
put、get、del、--prefix:
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl put "name" "张三"
OK
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "name"
name
张三
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl del "name"
1
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "name"
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl put "/cron/jobs/job1" "{...json}"
OK
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl put "/cron/jobs/job2" "{...json}"
OK
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "/cron/jobs/job2"
/cron/jobs/job2
{...json}
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "/cron/jobs/job1"
/cron/jobs/job1
{...json}
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "/cron/jobs/" --prefix
/cron/jobs/job1
{...json}
/cron/jobs/job2
{...json}
[root@bogon etcd-v3.3.12-linux-amd64]#
(带上--prefix表示get以/cron/jobs/开头的)
watch监听k-v的变化:
[root@bogon etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl watch "/cron/jobs/" --prefix
PUT
/cron/jobs/job2
{...changed}
DELETE
/cron/jobs/job2
(如果watch后,其他窗口改变/删除等/cron/jobs/job2的值,会显示出来。etcd很适合做配置的分发,可以实时感受到变化)
标签:适合 get 窗口 cli 0.0.0.0 listen let 基本 3.3
原文地址:https://blog.51cto.com/5660061/2381702