因最近須要作分佈式的TCP服務與WebApi實時交互,須要實現從業務端能直接與最終的客戶端互通,瞭解了幾天相關的技術,一開始準備本身寫一套Tcp+Ipc服務實現跨服務器的socket連接消息調度,可是考慮到時間與穩定性的問題,最終仍是決定使用現有的成熟的框架來作,原本先注意到的是Message Queue相關的技術,在詳細瞭解後認爲最貼合個人應用場景的是應該是RPC,而後在對比性能效率篩選各個RPC框架,最終適合的就是 google的 protocal buffer 與 Thrift, 因個人系統可能會比較多種語言,好比 Linux C,C#,Java,PHP,因此Thrift更適合。python
下面首先來看下Thrift的安裝,雖然在網上有不少的安裝講解,有的講的也很細緻,可是都有一個問題就是給出的資源包多多少少都存在些問題,對於技術方向不在這個領域的人來講,安裝起來簡直就是在自殘!我下面講到的安裝步驟及資源包也是針對我本身相應的平臺來作的,不一樣的系統或版本以前可能存在差別,在作參考時須要注意了,同時我使用的依賴包基本都是最新版的包括Thrift也是自github下的最新版,下面是詳細的安裝過程。c++
#依賴安裝 yum -y update yum install wget yum install git yum install gcc gcc-c++ yum install libevent-devel zlib-devel openssl-devel yum install m4 yum install glibc-devel glibc glib2 glib2-devel #autoconf yum install autoconf-2.69 #libtool wget http://mirrors.ustc.edu.cn/gnu/libtool/libtool-2.4.6.tar.gz tar -xvf libtool-2.4.6.tar.gz cd libtool-2.4.6 ./bootstrap ./configure make &make install cd .. #automake yum install perl-Thread-Queue wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz tar -xvf automake-1.15.tar.gz cd automake-1.15 ./configure make &make install cd .. #bison wget http://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz tar -xvf bison-3.0.4.tar.gz cd bison-3.0.4 ./configure --prefix=/usr/soft/bison make &make install cd .. #bootstrap wget http://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.gz tar -xvf boost_1_64_0.tar.gz cd boost_1_64_0 ./bootstrap.sh ./b2 install cd .. #dotnetcore yum install libunwind libicu wget https://download.microsoft.com/download/E/7/8/E782433E-7737-4E6C-BFBF-290A0A81C3D7/dotnet-dev-centos-x64.1.0.4.tar.gz #runtime wget https://download.microsoft.com/download/D/7/A/D7A9E4E9-5D25-4F0C-B071-210CB8267943/dotnet-centos-x64.1.1.2.tar.gz tar -xvf dotnet-dev-centos-x64.1.0.4.tar.gz -C /opt/dotnet/ tar -xvf dotnet-centos-x64.1.1.2.tar.gz -C /opt/dotnet/ mkdir /opt/dotnet tar -xvf dotnet-dev-centos-x64.1.0.4.tar.gz -C /opt/dotnet/ tar -xvf dotnet-centos-x64.1.1.2.tar.gz -C /opt/dotnet/ ln -s /opt/dotnet/dotnet /usr/local/bin #thrift git clone https://github.com/apache/thrift.git cd thrift ./bootstrap.sh ./configure --prefix=/usr/soft/thrift --with-boost=/usr/soft/bootstrap/ #若出現以下錯誤 ./configure: line 3802: PKG_PROG_PKG_CONFIG: command not found ./configure: line 18272: syntax error near unexpected token `QT,' ./configure: line 18272: ` PKG_CHECK_MODULES(QT, QtCore >= 4.3, QtNetwork >= 4.3, have_qt=yes, have_qt=no)' #運行以下命令 find /usr -name "pkg.m4" 返回 /usr/share/aclocal/pkg.m4 aclocal --print-ac-dir 返回 /usr/local/share/aclocal #這兩個地址不同,再加上 bootstrap.sh 裏面定義了 aclocal -I ./aclocal #這致使定義在 pkg.m4裏全局變量 PKG_PROG_PKG_CONFIG 與 PKG_CHECK_MODULES 找不到,因此報錯 #作以下修改解決這個問題, 在bootstrap.sh 裏面修改 aclocal -I ./aclocal -I /usr/share/aclocal/ #保存 從新從 ./bootstrap.sh 就能夠了! #以上命令運行成功以下 thrift 1.0.0-dev Building Plugin Support ...... : no Building C++ Library ......... : yes Building C (GLib) Library .... : yes Building Java Library ........ : no Building C# Library .......... : no Building .NET Core Library ... : yes Building Python Library ...... : yes Building Ruby Library ........ : no Building Haxe Library ........ : no Building Haskell Library ..... : no Building Perl Library ........ : no Building PHP Library ......... : no Building Dart Library ........ : no Building Erlang Library ...... : no Building Go Library .......... : no Building D Library ........... : no Building NodeJS Library ...... : no Building Lua Library ......... : no Building Rust Library ........ : no C++ Library: Build TZlibTransport ...... : yes Build TNonblockingServer .. : yes Build TQTcpServer (Qt4) ... : no Build TQTcpServer (Qt5) ... : no .NET Core Library: Using .NET Core ........... : /usr/local/bin/dotnet Using .NET Core version ... : 1.0.4 Python Library: Using Python .............. : /usr/bin/python If something is missing that you think should be present, please skim the output of configure to find the missing component. Details are present in config.log. #而後繼續 make &make install #若遇到以下錯誤 src/thrift/server/TNonblockingServer.cpp: In member function 'void apache::thrift::server::TNonblockingServer::TConnection::workSocket()': src/thrift/server/TNonblockingServer.cpp:460:16: error: expected ')' before 'PRIu32' "(%" PRIu32 " > %" PRIu64 #作以下修改,在下面位置加入 #define __STDC_FORMAT_MACROS vi ./lib/cpp/src/thrift/Thrift.h #ifdef HAVE_INTTYPES_H #define __STDC_FORMAT_MACROS #include <inttypes.h> #endif #再make,覺得這樣就過了嗎? NO!!! #因爲咱們須要支持DotNetCore,git裏面原有的示例項目配置與當前的SDK環境可能不一致,那咱們須要改動以下位置 vi ./lib/netcore/build.sh #在第一處 加上以下指令 dotnet --info dotnet migrate //將全部項目遷移到當前環境,注意必定要在 restore 以前,不然報錯 dotnet restore #第二處, 這裏mono環境編譯配置,所有註釋掉 # Instead, run directly with mono for the full .net version #dotnet build **/*/project.json -r centos.7-x64 #dotnet build **/*/project.json -r win10-x64 #dotnet build **/*/project.json -r osx.10.11-x64 #dotnet build **/*/project.json -r ubuntu.16.04-x64 #保存,繼續 #OK, 大功告成,至此所有編譯經過