go grpc安装使用教程

Kidoisaboy 2019-06-20

gRPCæ¯ç±Google主导å¼åçRPCæ¡æ¶ï¼ä½¿ç¨HTTP/2å议并ç¨ProtoBufä½ä¸ºåºååå·¥å·ãå¶å®¢æ·ç«¯æä¾Objective-CãJavaæ¥å£ï¼æå¡å¨ä¾§åæJavaãGolangãC++ç­æ¥å£ï¼ä»è为移å¨ç«¯ï¼iOS/Androiï¼å°æå¡å¨ç«¯é讯æä¾äºä¸ç§è§£å³æ¹æ¡ã å½ç¶å¨å½ä¸çç¯å¢ä¸ï¼è¿ç§è§£å³æ¹æ¡æ´ç­é¨çæ¹å¼æ¯RESTFull APIæ¥å£ã该æ¹å¼éè¦èªå·±å»éæ©ç¼ç æ¹å¼ãæå¡å¨æ¶æãèªå·±æ­å»ºæ¡æ¶ï¼JSON-RPCï¼ã

1. åæ

  • ç¡®ä¿goççæ¬å¨1.6å以ä¸
  • ç¡®ä¿glibcçæ¬å¨2.14å以ä¸ï¼protocéè¦2.14å以ä¸çæ¬ï¼

2. ä¸è½½protocol buffer v3çæ¬ç¼è¯å¨

ä¸è½½å°åï¼ https://github.com/google/protobuf/releases

å½åææ°çæ¬ä¸ºv3.5.1

3. ä¸è½½protocçgolangæ件

go get -u github.com/golang/protobuf/protoc-gen-go
## ä¸è½ç´æ¥è®¿é®google.golang.orgç½åæ¶, ä»githubä¸è½½ç¶åæ¾å°google.golang.orgç®å½
mkdir -p src/google.golang.org/
cd src/google.golang.org
git clone https://github.com/google/go-genproto genproto

4. ä¸è½½golangå®ç°çgrpc

## å¯ç´æ¥è®¿é®google.golang.orgæ¶
go get -u google.golang.org/grpc
## åæ ·ä¸è½è®¿é®google.golang.orgæ¯éç¨çæ¹æ³
mkdir -p src/google.golang.org
cd src/google.golang.org
git clone https://github.com/grpc/grpc-go grpc
cd -
## å¦å¤ï¼ grpcä¾èµçå¶ä»åéè¦ä¸å¹¶ä¸è½½
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. ç¼åç¨äºgRPCçpbæ件

6. ç¼è¯pbçægo代ç 

7. ç¼å客æ·ç«¯æå¡ç«¯ä»£ç å¹¶ç¼è¯è¿è¡

ä¸è¿°ä¸æ­¥å¯ä»¥åègrpc-goç示ä¾ä»£ç 

8. è¡¥åglibcå级步骤

æ¥çglibcçæ¬å·

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

ä¸è½½å¹¶å®è£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

å¶ä½è½¯è¿æ¥

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

注æé®é¢

å é¤libc.so.6ä¹åä¼å¯¼è´ç³»ç»å½ä»¤ä¸å¯ç¨çæåµ

ä¾å¦æ示ï¼

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

解å³åæ³ï¼

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

å¦æå级失败ï¼åæ»æ¹æ³ï¼

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

æ»ç»

以ä¸æè¿°æ¯å°ç¼ç»å¤§å®¶ä»ç»çgo grpcå®è£ä½¿ç¨æç¨ï¼å¸æ对大家ææ帮å©ï¼å¦æ大家æä»»ä½çé®è¯·ç»æçè¨ï¼å°ç¼ä¼åæ¶åå¤å¤§å®¶çãå¨æ­¤ä¹é常æ谢大家对èæ¬ä¹å®¶ç½ç«çæ¯æï¼

相关推荐

岁月如歌 / 0评论 2020-07-21