1. 程式人生 > >go任務調度4(etcd安裝和基本使用)

go任務調度4(etcd安裝和基本使用)

chang 顯示 基本 控制 3.3 etcd inux 任務調度 str

下載,解壓,進入目錄,運行:

[[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安裝和基本使用)