CentOS 7 安装 gRPC

之前的文章曾经介绍过有关 protobuf 的安装使用,《Google Protocol Buffers 体验日志》,不过那篇文章针对的 MacOS 系统。最近在公司环境引入 gRPC 的使用,服务器都是 CentOS 7 系统,故写篇文章记录 CentOS 7 下如何安装 gRPC。

安装依赖的软件

首先是安装必要的软件,包括 git,make,gcc,等。

yum install epel-release -y
yum install -y git
yum install -y vim
yum install -y net-tools telnet
yum install -y which
yum install -y autoconf libtool
yum install -y make
yum install -y gcc gcc-c++ kernel-devel

下载 gRPC 源代码

我们采用下载并编译源代码的方式来安装 gRPC。

git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
cd grpc
git submodule update --init

编译安装

进入 grpc 目录,进行编译安装。

make
make install
cd third_party/protobuf
make
make install

测试

protoc --version

输出:

libprotoc 3.7.0

上面 gRPC 的安装步骤,也可以在 Dockerfile 中完成,以便于制定镜像。

附 gRPC 镜像 Dockerfile。

FROM centos:7.4.1708

WORKDIR /home/grpc

RUN yum install epel-release -y \
	yum install -y git \
	yum install -y vim \
	yum install -y net-tools telnet \
	yum install -y which \
	yum install -y autoconf libtool \
	yum install -y make \ 
	yum install -y gcc gcc-c++ kernel-devel

RUN /bin/sh -c 'git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc && cd grpc && git submodule update --init'

RUN /bin/sh -c 'cd /home/grpc/grpc && make && make install && cd third_party/protobuf && make && make install'

参考资料

  • https://github.com/grpc/grpc/blob/master/BUILDING.md
发布了193 篇原创文章 · 获赞 443 · 访问量 123万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章