使用go初步调用etcd
使用go初步調用etcd
package main import ( "context" "go.etcd.io/etcd/clientv3" "time" ) func main() { config := clientv3.Config{ Endpoints: []string{"106.12.72.181:23791", "106.12.72.181:23792"}, DialTimeout: 10 * time.Second, } client, _ := clientv3.New(config) defer client.Close() kv := clientv3.NewKV(client) ctx := context.Background() //需要放入一个context,看自己需求选择合适的ctx kv.Put(ctx,"/services/user","user1") //插入一条数据 }
可以看到etcd集群中两个节点都可以查询到这个key
:~# docker exec -it etcd1 sh /go # etcdctl get /services/user /services/user user1 /go # exit :~# docker exec -it etcd2 sh /go # etcdctl get /services/user /services/user user1
相关推荐
CurrentJ 2020-08-18
JustHaveTry 2020-07-17
Dannyvon 2020-07-13
Dannyvon 2020-07-04
###host字段指定授权使用该证书的etcd节点IP或子网列表,需要将etcd集群的3个节点都添加其中。cp etcd-v3.3.13-linux-amd64/etcd* /opt/k8s/bin/
xiunai 2020-07-04
breezegao 2020-07-02
微微一笑 2020-06-14
微微一笑 2020-06-12
CurrentJ 2020-06-06
lenchio 2020-06-04
微微一笑 2020-06-03
工作中的点点滴滴 2020-06-01
Rcvisual 2020-05-28
Dannyvon 2020-05-28
微微一笑 2020-05-26
wishli 2020-05-19
工作中的点点滴滴 2020-05-14