下载,解压,进入目录,运行:
[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很适合做配置的分发,可以实时感受到变化)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。