因最近须要作分布式的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, 大功告成,至此所有编译经过