TRPC环境搭建

此文仅供参考,如需详细搭建信息,请访问地址

部署环境

Ubuntu环境安装

add-apt-repository ppa:openjdk-r/ppa  # enter 可能链接不上,需要多试几次
apt-get update
apt-get install openjdk-8-jdk
apt-get install software-properties-common  # enter
apt-get update
add-apt-repository ppa:openjdk-r/ppa
apt-get install openjdk-11-jdk
https://github.com/trpc-group/trpc-cpp/blob/main/docs/zh/setup_env.md

bazel 3.51版本安装

# bazel 安装依赖jdk,先安装jdk
apt install g++ unzip zip
apt-get install default-jdk

# 安装bazel
mkdir -p /root/env/bazel
# 方式一:通过wget获取,如果服务器下载过慢可是使用下面百度网盘
wget https://github.com/bazelbuild/bazel/releases/download/3.5.1/bazel-3.5.1-installer-linux-x86_64.sh -O /root/env/bazel/bazel.sh
chmod +x /root/env/bazel/bazel.sh
/root/env/bazel/bazel.sh > /dev/null
rm -rf /root/env

# 方式二:使用下面百度网盘链接
# 链接: https://pan.baidu.com/s/1eZK_EKmpgpyNDtFY8EXO0g?pwd=bvw8 提取码: bvw8 复制这段内容后打开百度网盘手机App,操作更方便哦
# 下载后将bazel-3.5.1-installer-linux-x86_64.sh放入 /root/env/bazel/
mv bazel-3.5.1-installer-linux-x86_64.sh bazel.sh
chmod +x /root/env/bazel/bazel.sh
/root/env/bazel/bazel.sh > /dev/null
rm -rf /root/env


# 查看版本
bazel --version 

注意:tRPC-Cpp 框架源码依赖所需的第三方库(如:protobuf、gflags、fmtlib、 GCC等)自行安装;

trpc源码编译

从github下载tRPC-Cpp框架源代码

git clone https://github.com/trpc-group/trpc-cpp

编译tRPC-Cpp框架代码

# 进入根目录trpc-cpp
cd trpc-cpp
# 编译框架
./build.sh
# 用bazel编译并运行框架提供的example示例
./run_examples.sh

显示结果

logging plugin configurations is not setted, log will be printed to the console.
response: msg: "Hello, fiber"

清空bazel缓存 bazel clean --expunge
常见问题链接

build.sh编译显示构建失败
1.原因需要链接github,网络问题导致编译失败;
本人查看链接nghttp2 和 civetweb ,腾讯源链接404,那就直接修改访问github.com,删除前面的/mirrors.tencent.com/,进行直连;

:~/trpc-cpp$ sudo grep -rn "mirrors.tencent.com/github.com/" *
trpc/workspace.bzl:257:        "https://mirrors.tencent.com/github.com/civetweb/civetweb/archive/v{ver}.tar.gz".format(ver = civetweb_ver),
trpc/workspace.bzl:296:        "https://mirrors.tencent.com/github.com/nghttp2/nghttp2/releases/download/v{ver}/nghttp2-{ver}.tar.gz".format(ver = nghttp2_ver),

2.修改.bazelrc 文件中改为C++17

#! /bin/bash
build --cxxopt="--std=c++17"
build --copt=-O2
#build --copt=-g --strip=never
build --jobs 16
#test --cache_test_results=no --test_output=errors

3.如果有如图错误
在这里插入图片描述
本人也不知道什么原因,建议执行清除脚本./clean.sh,再次编译,或删除trpc-cpp文件夹重新拉取;
5.在2核虚拟机上进行编译trpc会导致服务器卡死,请慢慢等待;
4.尝试使用root用户进行编译
以上就是本人所遇到的一系列问题,到最后终于呈现了!(这些回车是ssh客户端卡死,后台也不能登录的尝试)
在这里插入图片描述

run_examples.sh编译报错
1.如果在编译中出现了大量的‘未定义引用’和‘无此文件’;可能原因是bazel版本过高需要使用3.5.1版本bazel进行编译;

示例代码

编译 Hello World 示例代码。(build.sh没问题,这里也不会有问题)

cd trpc-cpp
bazel build //examples/helloworld/...

运行示例代码

运行服务端程序。

./bazel-bin/examples/helloworld/helloworld_svr --config=./examples/helloworld/conf/trpc_cpp_fiber.yaml

打开另外一个终端,运行客户端测试程序。

./bazel-bin/examples/helloworld/test/fiber_client --client_config=./examples/helloworld/test/conf/trpc_cpp_fiber.yaml

成功输出。

FLAGS_service_name:trpc.test.helloworld.Greeter
FLAGS_client_config:./examples/helloworld/test/conf/trpc_cpp_fiber.yaml
get rsp msg: Hello, fiber

日志于helloworld_fiber.log

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值