之前的文章曾經介紹過有關 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