首页 > 系统相关 >CENTOS7下安装GRPC FOR CPP

CENTOS7下安装GRPC FOR CPP

时间:2023-08-01 15:37:27浏览次数:36  
标签:Shell protobuf GRPC CENTOS7 grpc DIR CPP root localhost

gRPC 是一个高性能、开源和通用的 RPC 框架,面向移动和 HTTP/2 设计。目前提供 C、Java 和 Go 语言版本,分别是:grpc, grpc-java, grpc-go. 其中 C 版本支持 C, C++, Node.js, Python, Ruby, Objective-C, PHP 和 C#。


gRPC 基于 HTTP/2 标准设计,带来诸如双向流、流控、头部压缩、单 TCP 连接上的多复用请求等特。这些特性使得其在移动设备上表现更好,更省电和节省空间占用。


官方网站:http://www.grpc.io/

官方文档:http://www.grpc.io/docs/

中文翻译:http://doc.oschina.net/grpc


测试环境:

系统是新安装的CentOS 7.2


Shell


[ root @ localhost ~ ] # cat /etc/redhat-release
CentOS Linux release 7.2.1511 ( Core )


一、YUM安装相关工具


Shell


yum install - y gcc - c ++ autoconf libtool
yum groupinstall - y "Development Tools"


二、下载gRPC源码和相关子模块

这步可能出现失败或者网速慢的情况(原因你懂的),多执行几次直到完全下载完毕为止。


Shell


git clone https : / / github .com / grpc / grpc .git
cd grpc
git submodule update -- init


三、编译安装protobuf

这个步骤有个地方要下载googlecode的里面的代码,国内正常来说是下载不下来的(除非有梯子),所以要换个下载地址:


Shell


[ root @ localhost grpc ] # cd third_party/protobuf/
[ root @ localhost protobuf ] # vim autogen.sh

找到这行:


Shell

xxxxxxxxxx
 1

修改为:


Shell

xxxxxxxxxx
 1

然后编译安装即可:


Shell

[ root @ localhost protobuf ] # ./autogen
[ root @ localhost protobuf ] # ./configure
[ root @ localhost protobuf ] # make
[ root @ localhost protobuf ] # make install
[ root @ localhost protobuf ] # ldconfig # refresh shared library cache.
[ root @ localhost protobuf ] # which protoc
/ usr / local / bin / protoc
[ root @ localhost protobuf ] # protoc --version
libprotoc 3.0.0


四、编译安装gRPC



oot @ localhost protobuf ] # cd ../..
[ root @ localhost grpc ] # make
[ root @ localhost grpc ] # make install

执行make install的时候,我这里有错误提示:



Warning : it looks like protoc 3.0.0 + isn 't installed on your system,
which means that you won' t be able to compile . proto files for use
with gRPC .
 
If you are just using pre - compiled protocol buffers , or you otherwise
have no need to compile . proto files , you can ignore this .
 
If you do need protobuf for some reason , you can download and install
it from :
 
   https : //github.com/google/protobuf/releases
 
Once you' ve done so , you can re - run this check by doing :
 
   make verify - install

明明是有安装protoc的,但是没检测到,网上找了资料说这个问题好像是不影响的。


五、Demo测试

官方自带有个HelloWorld的Demo,可以编译这个Demo看是否我们已经安装成功了。



[ root @ localhost grpc ] # cd examples/cpp/helloworld/
[ root @ localhost helloworld ] # make

结果报错了:



Package grpc ++ was not found in the pkg - config search path .
Perhaps you should add the directory containing ` grpc ++ . pc '
to the PKG_CONFIG_PATH environment variable
No package ' grpc ++ ' found
Package grpc was not found in the pkg-config search path.
Perhaps you should add the directory containing `grpc.pc'
to the PKG_CONFIG_PATH environment variable

意思是找不到环境变量PKG_CONFIG_PATH,解决方法是把环境变量加上去:


在gRPC目录下保存文件actviate.sh:



DIR = "$( cd " $ ( dirname "${BASH_SOURCE[0]}" ) " && pwd )"
export PATH = $ PATH : $ DIR / bins / opt : $ DIR / bins / opt / protobuf
export CPATH = $ DIR / include : $ DIR / third_party / protobuf / src
export LIBRARY_PATH = $ DIR / libs / opt : $ DIR / libs / opt / protobuf
export PKG_CONFIG_PATH = $ DIR / libs / opt / pkgconfig : $ DIR / third_party / protobuf
export LD_LIBRARY_PATH = $ DIR / libs / opt

然后执行:


Shell

[ root @ localhost grpc ] # source actviate.sh
[ root @ localhost grpc ] # cd examples/cpp/helloworld/
[ root @ localhost helloworld ] # make

编译成功。(注意,每次新开终端编译或运行程序,都要执行actviate.sh,除非把环境变量设成永久有效)


然后运行服务端,监听的是50051端口:


Shell

[ root @ localhost helloworld ] # ./greeter_server
I0719 09 : 09 : 11.798702503      5076 ev_epoll_linux .c : 85 ]          epoll engine will be using signal : 36
D0719 09 : 09 : 11.798857929      5076 ev_posix .c : 106 ]              Using polling engine : epoll
Server listening on 0.0.0.0 : 50051

在另外一个终端执行客户端程序:



[ root @ localhost helloworld ] # ./greeter_client
I0719 09 : 10 : 04.431843293      5142 ev_epoll_linux . c : 85 ]          epoll engine will be using signal : 36
D0719 09 : 10 : 04.432006262      5142 ev_posix . c : 106 ]              Using polling engine : epoll
Greeter received : Hello world


成功!





标签:Shell,protobuf,GRPC,CENTOS7,grpc,DIR,CPP,root,localhost
From: https://blog.51cto.com/u_2700990/6922652

相关文章

  • centos7系统的初始环境配置
    (centos7系统的初始环境配置)一、配置yum仓库1.配置阿里的仓库源[root@192~]#curl-o/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-7.repo2.检测yum仓库[[email protected]]#yumrepolistall|grepenablebase/7/x86_64......
  • CentOS7创建Python虚拟环境
    为python3创建软连接:ln-s/usr/local/anaconda3/bin/python/usr/bin/python3ln-s/usr/local/anaconda3/bin/pip/usr/bin/pip3查看版本:[root@centos-base~]#python3-VPython3.7.0[root@centos-base~]#pip3-Vpip10.0.1from/usr/local/anaconda3/lib/python......
  • ️Centos7下安装Oracle11GR2
    安装Oracle一直以来是比较头疼的事情,于是本文以图文并茂的方式进行安装步骤展示,参考知乎一位博主的安装:https://zhuanlan.zhihu.com/p/111710672,本文还额外提供了安装以及最后的一些数据库自启动配置操作。Oracle软件包地址:https://pan.baidu.com/s/1rQFXCsL44Nl-cXaLWVY9jQ?pwd......
  • centos7中 configure: error: zlib development files not found
     01、系统[liujiaxin01@PC1~]$cat/etc/redhat-release##centos7.6发行版CentOSLinuxrelease7.6.1810(Core) 002、问题[[email protected]]$./configure##出现如下报错 003、解决方法[root@PC1~]#yum-yinstallzlibzlib......
  • centos7下安装docker
    来源:https://www.cnblogs.com/qtzd/p/14679120.htmlDocker安装CentOS7使用Xshell连接远程进行服务器操作环境查看系统内核是3.10以上的[root@localhost~]#uname-r3.10.0-229.el7.x86_64系统版本[root@localhost~]#cat/etc/os-releaseNAME="CentOSLinux"VERSI......
  • centos7.9 时间相关整理
    1.date/timedatectl显示当前时间(秒):date/date+"%Y-%m-%d%H:%M:%S"(%Y等含义通过data--h查看)显示当前时间(毫秒):date/date+"%Y-%m-%d%H:%M:%S.%3N"当前时间戳(秒):date+%s当前时间戳(毫秒):date+%s%3N查看当前时区:timedatectl设置时区:timedatectl......
  • 初步体验 llama.cpp
    llama.cpp:PortofFacebook'sLLaMAmodelinC/C++github仓库:https://github.com/ggerganov/llama.cpp参考博文:High-SpeedInferencewithllama.cppandVicunaonCPU第1步,准备一台阿里云4核8G的服务器,操作系统用的是ubuntu22.04第2步,签出llama.cpp源码进行build......
  • centos7 k8s 三节点 全二进制部署 1.23.15
    主机名IP地址Pod网段Service网段master192.168.1.60172.16.0.0/1210.96.0.0/16node01192.168.1.70172.16.0.0/1210.96.0.0/16node02192.168.1.80172.16.0.0/1210.96.0.0/16[root@master~]#cat/etc/redhat-releaseCentOSLinuxrelease7.9.2......
  • Centos7.9版本安装collectd并开启写入rrd文件功能
    文章目录一、背景介绍二、为什么用这个三、安装Collectd3.1尝试docker安装3.2尝试执行linux命令一步一步安装安装collectd设置将数据写入日志文件设置将数据写入rrd文件。一、背景介绍Collectd官网:https://collectd.org/Collectd是一款开源的系统统计守护进程,用于收集、处理和存......
  • gi_engine.cpp
    GIEngine::GIEngine(GINSOptions&options){    //初始化系统噪声阵  autoimunoise=options_.imunoise;  Qc_.block(ARW_ID,ARW_ID,3,3)=imunoise.gyr_arw.cwiseProduct(imunoise.gyr_arw).asDiagonal();  Qc_.block(VRW_ID,VRW_ID,3,3)=imunoise.......