搭建日志收集系统时使用客户端连接etcd遇到的问题

问题: 在做日志收集系统时使用到etcd,其中server端在linux上,首先安装第三方包(windows)(安装过程可能会有问题,我遇到的是连接谷歌官网请求超时,如果已经出现下面的两个文件夹并且文件夹中都有内容则可以不理会错误):

go get -u -v github.com/coreos/etcd/clientv3

完成之后,在开发环境中会增加两个文件夹:

1. src\go.etcd.io
2. src\github.com\coreos

客户端测试程序(go语言,命名为main.go,注意etcd server端的ip地址换成你自己的):

 1 package main
 2 
 3 import (
 4     "fmt"
 5     etcd_client "github.com/coreos/etcd/clientv3"
 6     //etcd_client "go.etcd.io/etcd/clientv3"
 7     "time"
 8 )
 9 
10 func main() {
11 
12     cli, err := etcd_client.New(etcd_client.Config{
13         Endpoints:   []string{"192.168.30.136:2379", "192.168.30.136:22379", "192.168.30.136:32379"},
14         DialTimeout: 5 * time.Second,
15     })
16     if err != nil {
17         fmt.Println("connect failed, err:", err)
18         return
19     }
20 
21     fmt.Println("connect succ")
22     defer cli.Close()
23 }
测试程序

在该文件夹下执行,报错如下:

go run main.go
F:\Go\project\src\go_dev_yuanma\go_dev\day12\etcd_conn>go run main.go
# github.com/coreos/etcd/clientv3
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:116:72: cannot use auth.call Opts (type  []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthEnable
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:121:74: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthDisable
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:126:100: cannot use auth.cal lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
 as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserAdd
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:131:86: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserDelete
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:136:122: cannot use auth.cal
lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)  as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argumen
t to auth.remote.UserChangePassword
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:141:104: cannot use auth.cal lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
 as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argumen
t to auth.remote.UserGrantRole
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:146:80: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument
 to auth.remote.UserGet
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:151:72: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument
 to auth.remote.UserList
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:156:106: cannot use auth.cal lOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
 as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argumen
t to auth.remote.UserRevokeRole
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:161:80: cannot use auth.call Opts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption)
as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument
 to auth.remote.RoleAdd
..\..\..\..\github.com\coreos\etcd\clientv3\auth.go:161:80: too many errors

这样的错误原因可以参考:

https://blog.csdn.net/zhangyexinaisurui/article/details/87001028 

解决的办法:

1. 在 import 的时候,不要引用 "github.com/coreos/etcd/clientv3",而是 "go.etcd.io/etcd/clientv3",原因已在上面的链接有所说明:

//"github.com/coreos/etcd/clientv3"
"go.etcd.io/etcd/clientv3"

然后使用上面的测试程序测试,如果还有问题,再使用下面的 2 方法试下。

2. 可以到 github.com/coreos/etcd 地址下载所有的包,然后解压缩到 src\github.com\coreos 路径下,如果没有该目录则创建,并将解压后的文件夹命名为 etcd(原来为etcd-master),再将前面改名后的 etcd文件夹拷贝到 src\go.etcd.io 目录下,再使用测试程序测试下(测试前记着启动etcd的server端,同时测试程序 import "go.etcd.io/etcd/clientv3")。

参考文献:

  • https://blog.csdn.net/zhangyexinaisurui/article/details/87001028

猜你喜欢

转载自www.cnblogs.com/xuejiale/p/10665845.html
今日推荐