Centos 7 Base版安装Thrift 并支持DotNetCore

       因最近需要做分布式的TCP服务与WebApi实时交互,需要实现从业务端能直接与最终的客户端互通,了解了几天相关的技术,一开始准备自己写一套Tcp+Ipc服务实现跨服务器的socket链接消息调度,但是考虑到时间与稳定性的问题,最终还是决定使用现有的成熟的框架来做,本来先注意到的是Message Queue相关的技术,在详细了解后认为最贴合我的应用场景的是应该是RPC,然后在对比性能效率筛选各个RPC框架,最终适合的就是 google的 protocal buffer 与 Thrift, 因我的系统可能会比较多种语言,比如 Linux C,C#,Java,PHP,所以Thrift更适合。

        下面首先来看下Thrift的安装,虽然在网上有很多的安装讲解,有的讲的也很细致,但是都有一个问题就是给出的资源包多多少少都存在些问题,对于技术方向不在这个领域的人来说,安装起来简直就是在自残!我下面讲到的安装步骤及资源包也是针对我自己相应的平台来做的,不同的系统或版本之前可能存在差异,在做参考时需要注意了,同时我使用的依赖包基本都是最新版的包括Thrift也是自github下的最新版,下面是详细的安装过程。

    

#依赖安装
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, 大功告成,至此全部编译通过

 

 

转载于:https://my.oschina.net/u/562914/blog/1377703

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值