about 4 years ago

簡介

Thrift是RPC(Remote procedure call) framwork,利用IDL(Interface Definition Language)來定義所需要的interface,再透過code generation engine轉換來支援多種的程式語言,讓兩端不同程式語言所設計的程式能溝通,而開發者只須專注在實作interface所需的內容。此種方式大大減少開發者為了Server和Client之間傳輸所需要寫的code,如傳輸的格式(Binary、JSON等)、傳輸的方式等等。

Install on Ubuntu 14.04

以下為官網文件的Debian or Ubuntu setup整理出來的。示範安裝Thrift支援Ruby和Java。若你所要使用其他的語言,請到官網文件查詢。(當然前提要先安裝Ruby和Java,請自行google)

Basic Requirements

$ sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev

Requirements for different Programming Language

Thrift目前支援有C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delph等多種程式語言。當你想要支援的programming language越多,make後的execute file就會越大。如果想要支援這些語言,就必需安裝相關套件(Reference:Debian or Ubuntu setup)。我安裝時是用git clone source code的方式,而不是使用已包好的tar file,也發現這樣方法好像不用安裝相關套件,就可以順利安裝成功。以下為我安裝的流程:

Installation

Apache Thrift 安裝文件Building from source

$ git clone https://git-wip-us.apache.org/repos/asf/thrift.git thrift
$ cd thrift
$ ./bootstrap.sh
$ ./configure --without-py

--without-py是讓thrift不支援Python,因為Ubuntu會預裝Python。在./configure過程中會檢查相關的library。結果會顯示在螢幕上:

thrift 1.0.0

Building C++ Library ......... : yes
Building C (GLib) Library .... : no
Building Java Library ........ : yes
Building C# Library .......... : no
Building Python Library ...... : no
Building Ruby Library ........ : yes
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no

C++ Library:
   Build TZlibTransport ...... : yes
   Build TNonblockingServer .. : yes
   Build TQTcpServer (Qt) .... : no
   
Java Library:
   Using javac  .............. : javac
   Using java  ............... : java
   Using ant  ................ : /home/terry/tool/java/apache-ant-1.9.4/bin/ant

Ruby Library:
   Using Ruby ................ : /usr/local/bin/ruby

以上表示此Thrift偵測到C++、Java和Ruby,之後code generate時也只產出C++、Java和Ruby的code。接著執行

$ make
$ su - root
$ make install

值得注意的事是文件中特別標出了From the top directory, become superuser and do: make install,如果使用sudo make install會失敗,錯誤訊息為JAVA_HOME not defined correctly,而切成root再make install就成功了。

← MacVim安裝和設定 Thread Dump →
 
comments powered by Disqus