wink

有的鸟是不会被关住的, 因为它们的羽毛太耀眼了.

  • main

wink

有的鸟是不会被关住的, 因为它们的羽毛太耀眼了.

  • main

etcd client DNS Discovery

2016-04-10

我们都知道etcd可以作为Discovery Service来使用, 详见, 但是作为etcd自身, 怎么被etcd client发现呢? 下面就介绍一下etcd client的做法.

(cluster启动的自我发现在这里就不介绍了, 一般用init-cluster就可以了, 详见)dns discovery 可以作为 client 发现etcd cluster的机制, -discovery-srv flag 可以用来指定找到etcd cluster的域名. 下面的 DNS SRV records 按列出顺序被查找(这里只介绍client的discover):

  • _etcd-client._tcp.example.com
  • _etcd-client-ssl._tcp.example.com

如果 _etcd-client-ssl._tcp.example.com , client会使用ssl来尝试连接etcd

etcd client configuration

DNS SRV records can also be used to help clients discover the etcd cluster.

The official etcd/client supports DNS Discovery.

etcdctl also supports DNS Discovery by specifying the --discovery-srvoption.

1
$ etcdctl --discovery-srv example.com set foo bar

这里注意, 只需要提供example.com 即可, 不需要提供完整的_etcd-client._tcp.example.com 或者 _etcd-client-ssl._tcp.example.com, 因为etcd/client会自动去搜寻这两个.

用etcd/client 使用DNS Discovery的代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
d := NewSRVDiscover()
endpoints, err := d.Discover("example.com")
if err != nil {
t.Fatalf("%d: err: %#v", i, err)
}
cfg := client.Config{
Endpoints: endpoints,
Transport: client.DefaultTransport,
HeaderTimeoutPerRequest: time.Second,
}
etcdClient, err := client.New(cfg)
if err != nil {
log.Fatal("Error: cannot connec to etcd:", err)
}
赏

thanks

  • etcd
  • tech

扫一扫,分享到微信

微信分享二维码
facebook图片存储之Haystack
golang vendor
© 2019 wink