go任务调度4(etcd安装和基本使用)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go任务调度4(etcd安装和基本使用)相关的知识,希望对你有一定的参考价值。
下载,解压,进入目录,运行:
[[email protected] 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控制工具:
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl
(前面需要一个环境变量ETCDCTL_API=3)
put、get、del、--prefix:
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl put "name" "张三"
OK
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "name"
name
张三
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl del "name"
1
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "name"
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl put "/cron/jobs/job1" "{...json}"
OK
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl put "/cron/jobs/job2" "{...json}"
OK
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "/cron/jobs/job2"
/cron/jobs/job2
{...json}
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "/cron/jobs/job1"
/cron/jobs/job1
{...json}
[[email protected] etcd-v3.3.12-linux-amd64]# ETCDCTL_API=3 ./etcdctl get "/cron/jobs/" --prefix
/cron/jobs/job1
{...json}
/cron/jobs/job2
{...json}
[[email protected] etcd-v3.3.12-linux-amd64]#
(带上--prefix表示get以/cron/jobs/开头的)
watch监听k-v的变化:
[[email protected] 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很适合做配置的分发,可以实时感受到变化)
以上是关于go任务调度4(etcd安装和基本使用)的主要内容,如果未能解决你的问题,请参考以下文章