使用Thrift需要進行安裝,主要安裝兩個工具:
- 接口定義文件(.thrift)的編譯器
- 不同語言的公共基礎庫程序
1 安裝依賴工具和庫
sudo apt-get install automake bison flex g++ git libboost-all-dev libevent-dev \
libssl-dev libtool make pkg-config
2 安裝Thrift編譯器和程序庫
可以從https://thrift.apache.org/download下載Thrift源文件:
- thrift-0.11.0.tar.gz 是可以在Linux或Mac安裝的源文件
- Thrift compiler for Windows (thrift-0.11.0.exe) 是Windows的安裝文件
1) 解壓縮源文件
tar -zxvf thrift-0.11.0.tar.gz
2)配置安裝過程
cd thrift-0.11.0
./configure --prefix=/usr/local/ --without-php --without-java --without-perl --without-nodejs
--prefix
表示安裝到的路徑--without-PACKAGE
表示不安裝PACKAGE語言的庫,如--without-php
表示不安裝php的Thrift基礎程序庫- 其他configure選項參數可以通過
./configure --help
進行查看
3)解析來執行
sudo make
4)安裝
sudo make install
5)驗證
執行如下命令
thrift -version
若有如下信息,則表示安裝成功
注意
安裝成功後對於選擇安裝的語言,調用Thrift的程序庫實際上也安裝完成。但是對於Python語言,Thrift會附帶安裝適用於Python 2的程序庫(包),缺少了Python 3的程序庫;同時,對於Ubuntu系統(或Debian系統),默認python的搜索包路徑在dist-packages子目錄下,而Thrift安裝的Python程序包路徑在site-packages子目錄下,python程序不能直接導入thrift包。所以,對於Python語言,我們可以使用下面的方法自己安裝thrift包。
3 安裝Thrift 的Python包
pip install thrift