最近转行当go的小弟,然后开始尝试 golang微服务框架 go-mrico ,结果才发现这东西真的鸡儿难装,搞了几天终于成功之后,好好总结下。

测试项目地址 https://github.com/oldguys/My...

安装步骤:

安装配置 golang 运行环境

配置 运行时需要的 protoc

安装 go-mrico 通讯依赖 grpc

安装 go-mrico 以及相关依赖

安装 *.mrico.go 和 *.pb.go 代码生成工具

安装微服务注册中心 consul

安装centos

使用 ip addr 查看ip

1. 配置 golang 运行环境

下载安装包 go1.12.7.linux-amd64.tar.gz

cd 到安装包位置

tar -C /usr/local -xzf go1.12.7.linux-amd64.tar.gz

配置 golang 环境变量

PS:使用 export PATH=$PATH:/usr/local/go/bin 重启系统会失效,所以需要使用以下环境变量配置的方式

cd /etc/profile.d

使用 vim golang.sh 创建 golang.sh

export GOROOT=/usr/local/go

export GOPATH=/root/go

export GOBIN=$GOPATH/bin

export PATH=$PATH:$GOROOT/bin:$GOBIN

重启系统 (不要忘了!)

2. 配置 运行时需要的 protoc

安装 unzip 工具

yum install -y unzip

将压缩包移动到 /usr/local/ ,并解压

将名称更改为protobuf

mv /usr/temp/protobuf-all-3.9.1.zip /usr/local/

unzip protobuf-all-3.9.1.zip

mv protobuf-3.9.1/ protobuf

安装 make

yum -y install gcc automake autoconf libtool make

yum install gcc gcc-c++

配置make

cd protobuf

./configure --prefix=/usr/local/protobuf

make

# 测试,这一步很耗时间

make check

make install

同上配置环境变量

cd /etc/profile.d

创建proto.sh

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib

export PATH=$PATH:/usr/local/protobuf/bin

__重启系统 (不要忘了!)__,验证是否安装成功

3. 安装go-mrico 通讯依赖 grpc

默认使用,可以下载相关的依赖,但是实际特别漫长,而且网络经常出问题

go get -u google.golang.org/grpc

所以可以使用 git下载替代(以下直使用git下载方式)

## 初始化 git 安装工具,已有可缺省

yum install -y git

## download go-mrico相关依赖

git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc

## 代码生成器

git clone https://github.com/golang/protobuf.git /root/go/src/github.com/golang/protobuf

验证效果

## 测试用例位置

cd $GOPATH/src/google.golang.org/grpc/examples/helloworld

### 服务端

go run greeter_server/main.go

### 客户机端

go run greeter_client/main.go

如果抛出异常,如图

原因是缺少依赖,补全依赖即可

git clone https://github.com/golang/net.git $GOPATH/src/golang.org/x/net

git clone https://github.com/golang/sys.git $GOPATH/src/golang.org/x/sys

git clone https://github.com/golang/text.git $GOPATH/src/golang.org/x/text

git clone https://github.com/googleapis/go-genproto.git $GOPATH/src/google.golang.org/genproto

运行结果:

4. 安装go-mrico 以及相关依赖

默认使用,可以下载相关的依赖,但是实际特别漫长,而且网络经常出问题

go get -u -v github.com/micro/micro

同样的,还是使用git下载快稳一些

yum install -y git

## download go-mrico相关依赖

git clone https://github.com/micro/micro.git $GOPATH/src/github.com/micro/micro

尝试安装

go install github.com/micro/micro

同样出现上面的结果

同理,从git上一个个下载下来(这边就比maven不人性化多了,当然也可能因为有阿里镜像,这边没有)规模有点浩大

git clone https://github.com/google/btree.git $GOPATH/src/github.com/google/btree

git clone https://github.com/pkg/errors.git $GOPATH/src/github.com/pkg/errors

git clone https://github.com/armon/go-metrics.git $GOPATH/src/github.com/armon/go-metrics

git clone https://github.com/gorilla/handlers.git $GOPATH/src/github.com/gorilla/handlers

git clone https://github.com/gorilla/mux.git $GOPATH/src/github.com/gorilla/mux

git clone https://github.com/hashicorp/go-immutable-radix.git $GOPATH/src/github.com/hashicorp/go-immutable-radix

git clone https://github.com/hashicorp/go-msgpack.git $GOPATH/src/github.com/hashicorp/go-msgpack

git clone https://github.com/hashicorp/go-multierror.git $GOPATH/src/github.com/hashicorp/go-multierror

git clone https://github.com/hashicorp/golang-lru.git $GOPATH/src/github.com/hashicorp/golang-lru

git clone https://github.com/hashicorp/errwrap.git $GOPATH/src/github.com/hashicorp/errwrap

git clone https://github.com/hashicorp/go-sockaddr.git $GOPATH/src/github.com/hashicorp/go-sockaddr

git clone https://github.com/joncalhoun/qson.git $GOPATH/src/github.com/joncalhoun/qson

git clone https://github.com/lucas-clemente/quic-go.git $GOPATH/src/github.com/lucas-clemente/quic-go

git clone https://github.com/cheekybits/genny.git $GOPATH/src/github.com/cheekybits/genny

git clone https://github.com/marten-seemann/qtls.git $GOPATH/src/github.com/marten-seemann/qtls

git clone https://github.com/nlopes/slack.git $GOPATH/src/github.com/nlopes/slack

git clone https://github.com/sean-/seed.git $GOPATH/src/github.com/sean-/seed

git clone https://github.com/serenize/snaker.git $GOPATH/src/github.com/serenize/snaker

git clone https://github.com/xlab/treeprint.git $GOPATH/src/github.com/xlab/treeprint

git clone http://www.github.com/go-telegram-bot-api/telegram-bot-api $GOPATH/src/gopkg.in/telegram-bot-api.v4

git clone https://github.com/technoweenie/multipartstreamer.git $GOPATH/src/github.com/technoweenie/multipartstreamer

git clone https://github.com/micro/go-micro.git $GOPATH/src/github.com/micro/go-micro

git clone https://github.com/go-log/log.git $GOPATH/src/github.com/go-log/log

git clone https://github.com/google/uuid.git $GOPATH/src/github.com/google/uuid

git clone https://github.com/hashicorp/consul.git $GOPATH/src/github.com/hashicorp/consul

git clone https://github.com/hashicorp/memberlist.git $GOPATH/src/github.com/hashicorp/memberlist

git clone https://github.com/golang/crypto.git $GOPATH/src/golang.org/x/crypto

git clone https://github.com/micro/mdns.git $GOPATH/src/github.com/micro/mdns

git clone https://github.com/micro/cli.git $GOPATH/src/github.com/micro/cli

git clone https://github.com/json-iterator/go.git $GOPATH/src/github.com/json-iterator/go

git clone https://github.com/miekg/dns.git $GOPATH/src/github.com/miekg/dns

git clone https://github.com/mitchellh/hashstructure.git $GOPATH/src/github.com/mitchellh/hashstructure

git clone https://github.com/modern-go/concurrent.git $GOPATH/src/github.com/modern-go/concurrent

git clone https://github.com/modern-go/reflect2.git $GOPATH/src/github.com/modern-go/reflect2

git clone https://github.com/nats-io/nats.go.git $GOPATH/src/github.com/nats-io/nats.go

git clone https://github.com/nats-io/jwt.git $GOPATH/src/github.com/nats-io/jwt

git clone https://github.com/nats-io/nkeys.git $GOPATH/src/github.com/nats-io/nkeys

git clone https://github.com/nats-io/nuid.git $GOPATH/src/github.com/nats-io/nuid

git clone https://github.com/bwmarrin/discordgo.git $GOPATH/src/github.com/bwmarrin/discordgo

git clone https://github.com/chzyer/readline.git $GOPATH/src/github.com/chzyer/readline

git clone https://github.com/forestgiant/sliceutil.git $GOPATH/src/github.com/forestgiant/sliceutil

git clone https://github.com/gorilla/websocket.git $GOPATH/src/github.com/gorilla/websocket

安装成功,验证版本

micro --version

## 查看是否在bin目录下 生成可执行文件

ls $GOPATH/bin/

5. 安装go-mrico 代码生成工具

git clone https://github.com/micro/protoc-gen-micro.git $GOPATH/src/github.com/micro/protoc-gen-micro

go install github.com/micro/protoc-gen-micro

go install github.com/golang/protobuf/protoc-gen-go

## 验证安装成功

ls $GOPATH/bin/

进行测试

cd $GOPATH/src/github.com/micro/protoc-gen-micro/examples/greeter

# 编译生成

protoc --proto_path=$GOPATH/src:. --micro_out=. --go_out=. greeter.proto

效果图

6. 安装微服务注册中心 consul

会出现缺少 依赖,补充依赖,提前补充下

!

git clone https://github.com/golang/tools.git $GOPATH/src/golang.org/x/tools

正式安装

cd $GOPATH/src/github.com/hashicorp

### 如果已经存在 可以缺省

git clone https://github.com/hashicorp/consul.git

cd consul/

## 开始安装,特别漫长

make tools

make dev

consul -v

效果图:

以上基本完成安装 ( 撒花 ~)

最后开始最终测试 :

git clone https://github.com/micro/examples.git $GOPATH/src/github.com/micro/examples

## 启动

consul agent -dev

#进入 测试代码目录

cd $GOPATH/src/github.com/micro/examples/service

## 启动服务端

go run main.go --registry=consul

## 启动客户端

go run main.go --run_client --registry=consul

效果图

同样的 window 也可以这样配置,可以直接把这边下载好的 依赖直接复制到window环境中,可以省超级多时间,具体操作就省略了。

直接贴效果图

注意运行时配置 运行时参数

automake 框架_centos 配置go-mrico框架相关推荐

  1. JAVA基础加强(张孝祥)_类加载器、分析代理类的作用与原理及AOP概念、分析JVM动态生成的类、实现类似Spring的可配置的AOP框架...

    1.类加载器 ·简要介绍什么是类加载器,和类加载器的作用 ·Java虚拟机中可以安装多个类加载器,系统默认三个主要类加载器,每个类负责加载特定位置的类:BootStrap,ExtClassLoader ...

  2. 如果要用thinkphp框架_php需要改哪些配置,thinkPHP框架动态配置用法实例分析

    本文实例讲述了thinkPHP框架动态配置用法.分享给大家供大家参考,具体如下: 最近在用@ThinkPHP 做系统的时候,要用到一个功能,就要动态的将系统的配置参数保存到Config文件中.以往,我 ...

  3. pycharm python部署_使用PyCharm配合部署Python的Django框架的配置纪实

    安装软件安装 Python 2.7.PyCharm.pip(Python包管理工具).Django ( pip install Django) 部署PyCharm 新建Django工程 完成后,其目录 ...

  4. 小程序 | 使用 npm 模块配置 Vant Weapp 框架

    之前体验了 iView 的UI框架,感觉还可以主要是因为在开发体验上比原生敲代码好很多,不过 iView 框架可利用的组件较少,比如搜索框的组件等并未涉及,而且已有的组件也存在一些需要自行生硬的修改才 ...

  5. 使用代码形式配置Log4J日志框架

    2019独角兽企业重金招聘Python工程师标准>>> 一.使用代码形式配置Log4J日志框架 一般情况下,我们都是使用配置文件形式来配置Log4J日志框架,比如使用"lo ...

  6. shiro框架---shiro配置介绍(一)

    接上一篇文章shiro框架-通过系统介绍shiro框架中的实现逻辑   项目已分享到GitHub上,如果需要的可以看下,springboot+shiro项目Git下载地址. shiro在springb ...

  7. C# EF框架(一)配置

    目录 EF EF简介 相关知识复习 lambda表达式 集合常用扩展方法 高级集合扩展方法 EF 的安装 EF 简单DataAnnotations 实体配置 EF 模型的两种配置方式 FluentAP ...

  8. 基于antd pro框架,配置接口apiUrl前缀

    基于antd-pro框架,配置package.json中的打包命令,实现不同环境使用不同的接口apiUrl前缀,避免人肉修改,保证各环境对应各自的api地址. 背景 这阵子,在玩antd-pro,感觉 ...

  9. IDEA中引入框架并配置artifact后,启动tomcat无法访问项目

    事情的起因是在一家软件公司实习的时候需要学习公司封装的TaCloud框架,在实习的过程中需要学习两个相关的框架,看两套相关的岗培视频,分别是TaCloud V4.0.1 和TaCloud V4.1.0 ...

最新文章

  1. linux基础篇-10,权限管理chown chgrp chmod umask
  2. 目标检测之线段检测---lsd line segment detector
  3. sourceinsight如何显示完整文件路径
  4. 无法加载登录用户界面DLL MyGina.dll 解决
  5. 基于numpy实现线性回归问题分析
  6. Go语言web框架 gin
  7. mysql触发器调用存储过程出错_mysql 触发器中调用存储过程
  8. [转]关于支付宝API开发的一点心得
  9. mongoDB mac 安装 小白必备
  10. MsSql 生成数据文档
  11. DSAPI.网络.网卡信息属性表
  12. python怎么把数据存在本地_将Python中的数据存储到系统本地的简单方法
  13. python爬虫课程设计摘要_爬虫课程设计(爬虫代码)
  14. Java菜鸟基础(一)
  15. PHP如何使用IPFS API用法
  16. 238.除自身以外数组的乘积 (力扣leetcode) 博主可答疑该问题
  17. 工作中使用到的单词(软件开发)_20210402备份
  18. linux开机出现repaire filesystem
  19. 大学生了没-20120709迅雷下载
  20. pre-trained模型的使用

热门文章

  1. node.js学习笔记之简洁聊天室
  2. 90%的android开发者都会遇到的问题,当sjk_daemon遇见ADB server didn't ACK
  3. java 求pi_计算PI(π)的几种方法
  4. 牛散NO.2:MACD西施说风情,柳下惠高位勿迷情
  5. TaoFramework
  6. 进阶版的Pandas数据分析神器:Polars
  7. 这么糟糕的代码,真的是我以前写的吗?
  8. 上汽赛可携手几维安全 赋能移动出行安全新业态
  9. ls算法java实现_Java API之算法 | 学步园
  10. 图解事件坐标screenX、clientX、pageX, offsetX的区别