kratos 环境搭建

1.  环境变量:/etc/profile或其他文件

export GOROOT=/usr/local/go

export GOPATH=$HOME/golang

export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin:$HOME/bin/protoc

export GOPROXY=https://goproxy.cn,direct

export GO111MODULE=on

2. 建golang目录

mkdir $HOME/golang

mkdir $HOME/golang/src

mkdir $HOME/golang/pkg

mkdir $HOME/golang/bin

3. 下载golang

Go下载 - Go语言中文网 - Golang中文社区

# tar -xf xx -C /usr/local/

4. 安装protoc

源码地址:Releases · protocolbuffers/protobuf · GitHub

下载3.14版本

curl -L https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip -o protoc-3.14.0-linux-x86_64.zip

mkdir protoc

mv protoc-3.14.0-linux-x86_64.zip protoc/

yum install unzip -y

cd protoc

unzip protoc-3.14.0-linux-x86_64.zip

cp bin/protoc $GOPATH/bin/

cp -r include/google $GOPATH/src/

5. 需要gcc

yum install gcc -y

6. 快速开始

https://go-kratos.dev/#/quickstart

go get -u github.com/go-kratos/kratos/tool/kratos

不用到$GOPATH目录,使用go module,随便创建一个目录即可:

mkdir kratosL && cd kratos

新建app:

kratos new app01

初始化go module:

go mod init kratosL

自动获取依赖:

go mod tidy

运行:

cd app01/cmd 

go build 

./cmd -conf ../configs

如下地址:

http://172.20.42.54:8000/app01/start

浏览器返回:

{"code":0,"message":"0","ttl":1,"data":{"Hello":"Golang 大法好 !!!"}}

问题1:执行 kratos new app01

kratos tool protoc --grpc --bm api.proto

2020/12/29 16:07:29 protoc --proto_path=/root/golang/src --proto_path=/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.1-0.20201222142230-f9d8abbcc47a/third_party --proto_path=/root/kratosL/app01/api --bm_out=:. api.proto

api.proto: File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).

解决:protoc版本过低

问题2:安装gcc时报错

错误:软件包:glibc-2.17-292.el7.i686 (base)
          需要:glibc-common = 2.17-292.el7
          已安装: glibc-common-2.17-307.el7.1.x86_64 (@anaconda)
              glibc-common = 2.17-307.el7.1
          可用: glibc-common-2.17-292.el7.x86_64 (base)
              glibc-common = 2.17-292.el7
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest

yum downgrade glibc-common glibc -y

已安装版本过高,需要降级

问题3:grpc版本过高问题

go run main.go --conf ../configs


/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:34:5: cannot use &p2cPickerBuilder literal (type *p2cPickerBuilder) as type base.PickerBuilder in assignment:
	*p2cPickerBuilder does not implement base.PickerBuilder (wrong type for Build method)
		have Build(map[resolver.Address]balancer.SubConn) balancer.Picker
		want Build(base.PickerBuildInfo) balancer.Picker
/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:35:5: cannot use &p2cPicker literal (type *p2cPicker) as type balancer.Picker in assignment:
	*p2cPicker does not implement balancer.Picker (wrong type for Pick method)
		have Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error)
		want Pick(balancer.PickInfo) (balancer.PickResult, error)
/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:42:32: not enough arguments in call to base.NewBalancerBuilder
	have (string, *p2cPickerBuilder)
	want (string, base.PickerBuilder, base.Config)
/root/golang/pkg/mod/github.com/go-kratos/kratos@v0.6.0/pkg/net/rpc/warden/balancer/p2c/p2c.go:144:2: cannot use p (type *p2cPicker) as type balancer.Picker in return argument:
	*p2cPicker does not implement balancer.Picker (wrong type for Pick method)
		have Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error)
		want Pick(balancer.PickInfo) (balancer.PickResult, error)
修改go.mod,降为v1.29.1
google.golang.org/grpc v1.29.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值