go grpc Installation tutorial

  • 2020-06-15 09:12:44
  • OfStack

gRPC is an RPC framework developed by Google, using HTTP/2 protocol and ProtoBuf as a serialization tool. The client side provides Objective-ES7en and Java interfaces, while the server side has Java, Golang, C++ and other interfaces, thus providing a solution for communication between the mobile end (iOS/Androi) and the server side. Of course, the more popular approach to this solution in today's environment is the RESTFull API interface. This approach requires you to choose the encoding method, server architecture, and framework (ES16en-ES17en).

1. The premise

Make sure the go version is 1.6 and above Ensure glibc version 2.14 and above (protoc requires version 2.14 and above)

2. Download the protocol buffer v3 compiler

Download address: https: / / github com/google/protobuf/releases

The current latest version is v3.5.1

Download the golang plug-in for protoc


go get -u github.com/golang/protobuf/protoc-gen-go
##  No direct access google.golang.org When the url ,  from github Download it and put it in google.golang.org directory 
mkdir -p src/google.golang.org/
cd src/google.golang.org
git clone https://github.com/google/go-genproto genproto

4. Download grpc implemented by golang


##  Direct access google.golang.org when 
go get -u google.golang.org/grpc
##  Again, not accessible google.golang.org Is the method adopted 
mkdir -p src/google.golang.org
cd src/google.golang.org
git clone https://github.com/grpc/grpc-go grpc
cd -
##  In addition,  grpc Other dependent packages are required 1 And download 
mkdir -p src/golang.org/x
cd src/golang.org/x
git clone https://github.com/golang/net
git clone https://github.com/golang/text
cd -

5. Write pb files for gRPC

6. Compile pb to generate go code

7. Write client server code and compile and run it

Refer to the sample code for grpc-ES63en for the three steps above

8. Supplement glibc upgrade steps

View glibc version number


strings /lib64/libc.so.6 | grep GLIBC_

Download and install glibc


tar -zxf glibc-2.14.tar.gz
cd glibc-2.14
mkdir build
cd build
../configure --prefix=/opt/glibc-2.14
make && make install

Make soft connection


rm -f /lib64/libc.so.6
ln -s /opt/glibc-2.14/lib/libc-2.14.so /lib64/libc.so.6

Pay attention to the problem

Deleting libc.so.6 causes system commands to become unavailable

For example, prompt:


rm: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

Solutions:


LD_PRELOAD=/opt/glibc-2.14/lib/libc-2.14.so ln -s /opt/glibc-2.14/lib/libc-2.14.so /lib64/libc.so.6

If the upgrade fails, rollback method:


LD_PRELOAD=/lib64/libc-2.12.so ln -s /lib64/libc-2.12.so /lib64/libc.so.6

conclusion


Related articles: