天天看點

Thrift安裝介紹一、簡介 二、安裝環境 三、安裝步驟 四、碰到的問題和解決方法 五、其它軟體的安裝方法 六、參考網址

一、簡介

1、語言庫要求

因為thrift支援多語言。是以編譯thrift源代碼的過程中,會用到該語言的一些類庫。如c++的boost、java的jdk等。

那麼,在安裝thrift過程中,須要對各種語言安裝哪些類庫和工具呢,官方對此有具體的介紹:

所需語言庫和工具
C++ :Boost 1.33.1+ (必選),libevent (可選,用來建立非堵塞server) ,zlib (可選)
Java :Java 1.5+ (必選),Apache Ant (必選),Apache Ivy(必選),Apache Commons Lang,SLF4J(必選)
C#: Mono 1.2.4+ 或者 Visual Studio 2005+
Python: 2.4+(必選)
PHP: 5.0+(必選)
Ruby: 1.8+(必選)
Erlang: R12(必選)
Perl 5: Bit::Vector ,Class::Accessor
以上的語言庫是看你詳細須要thrift生成如何的語言,并非必須所有都安裝。
      

2、支援的作業系統

thrift支援windows和linux兩種作業系統

未嘗試windows下的安裝(考慮到普遍性和高效率,不建議使用windows安裝thrift),下面是網上搜到windows下安裝方法:

http://wiki.apache.org/thrift/ThriftInstallationWin32

http://blog.csdn.net/snowbirdfly/article/details/6746392

linux下安裝,本人嘗試過centos4和centos5,因為centos5自帶的一些開發包版本号較高,和thrift環境比較吻合。建議使用centos5.

以下開始在centos5下安裝thrift。let’s begin 。

二、安裝環境

  1. 作業系統:centos5版本号以上作業系統
  2. 網絡:有獨立ip,能訪問外網
  3. 遠端連接配接軟體:SecureCRT

三、安裝步驟

1、安裝jdk

centos5自帶的jdk版本号是1.6.0,符合thrift安裝要求,可能須要加入環境變量。

環境變量加入方法:
vim /etc/profile

此檔案後面追加(路徑因機而異):
JAVA_HOME=/usr/share/jdk1.5.0_16
CLASSPATH=./:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
LD_LIBRARY_PATH=/usr/lib
export PATH CLASSPATH JAVA_HOME LD_LIBRARY_PATH

運作下面指令,使profile檔案生效:
source /etc/profile
      

驗證方法:

輸入java -version看java版本号,須在1.5以上
輸入javac,瞧見此指令的使用說明後。即驗證jdk成功安裝,否則,檢查一下就哪個環節出了問題。      

這個安裝比較簡單,不懂的地方能夠參考: http://www.blogjava.net/esprit/archive/2006/01/18/28489.html

2、安裝ant

  • 1、下載下傳

從 http://ant.apache.org/bindownload.cgi 下載下傳最新的tar包:apache-ant-1.8.3.tar.gz。

  • 2、安裝

cd到/usr/local下,解壓

[[email protected] san1156]# tar zxpvf apache-ant-1.8.3.tar.gz
[[email protected] san1156]# ln -s apache-ant-1.8.3 ant
      
  • 3、環境變量設定

将ANT_HOME設定到目前使用者的.bash_profile檔案

vi /root/.bash_profile
export ANT_HOME=/usr/local/ant
export PATH=/usr/local/ant/bin:$PATH
      
  • 4、測試

用ant指令測試執行情況

[[email protected] san1156]# ant
Buildfile: build.xml does not exist!
Build failed
[[email protected] san1156]# ant -version
Apache Ant(TM) version 1.8.3 compiled on February 26 2012
      

若出現以上内容。說明正常成功安裝

否則,若出現這種錯誤:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher

這是linux系統預設安裝了一些ant的lib。改動 /etc/ant.conf中 ANT_HOME=/usr/share/ant 為你正确安裝ant的位址。如 /usr/local/ant

注:編譯thriftproject要用到ant。thrift中的javaproject配置好了build.xml。故不須要手動改動此檔案。

參考網址:http://blog.csdn.net/nivana999/article/details/6526961

3、安裝ivy

  • 1、下載下傳

下載下傳apache ivy:http://labs.mop.com/apache-mirror//ant/ivy/2.2.0/apache-ivy-2.2.0-bin.tar.gz

  • 2、解壓

tar -xzvf apache-ivy-2.2.0-bin.tar.gz

  • 3、安裝

cp ivy-2.2.0.jar ANT_HOME/lib

  • 4、測試

cd 到 apache-ivy-2.2.0/src/example/hello-ivy,執行ant

假設看到:

BUILD SUCCESSFUL
Total time: 29 seconds
      

就代表歐了

4、部署其它語言環境

智能安裝指令。此指令須要遠端下載下傳一些安裝包。并自己主動安裝。下載下傳檔案大小共計60M,時間依據你的下載下傳速度而定。

sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel
      

官方說明: Installing the required packages on CentOS 5 http://wiki.apache.org/thrift/GettingCentOS5Packages

5、安裝thrift

  • 1、下載下傳thrift

http://mirror.bjtu.edu.cn/apache/thrift/0.8.0/thrift-0.8.0.tar.gz

  • 2、解壓
tar -zxvf thrift-0.8.0.tar.gz
      
  • 3、編譯
cd  thrift-0.8.0
./configure
make 
make install 
      
  • 4、測試

在命今行内輸入thrift。假設有提示指令用法。證明能夠了。

假設提示指令不可用。請接着本文向下看,對症下藥,方可藥到病除。

四、碰到的問題和解決方法

事無巨細,再簡單的事情。做起來往往也不是一帆風順,更何況是部署強大的thrift系統了。
隻是,經曆過風雨,才幹見到最燦爛的彩虹!僅僅有經受了層層不絕的bug磨練,才幹鍛煉出程式猿這顆堅強勇敢的心!      

1、Error: libcrypto required

  • 1、錯誤資訊:在安裝thrift過程中,運作./configure。報錯Error: libcrypto required
  • 2、解決方法:請安裝libssl-dev
  • 3、實施步驟:

yum install openssl openssl-devel libmcrypt libmcrypt-devel curl-devel

此指令自己主動下載下傳安裝程式,并安裝,可謂快捷友善。純傻瓜式操作

  • 4、參考網址:http://hi.baidu.com/ubuntu2me/blog/item/bcea4709fca3a1dd62d98693.html

2、Building Java Library ........ : no

  • 1、安裝目的:thrift支援多語言環境,可謂難能可貴,而java和c++又是兩大語種。缺少不論什麼一個都是遺憾。故,搭建thrift最少支援兩種語言。這裡選擇java、c++和python。
  • 2、錯誤資訊:在安裝thrift過程中,運作./configure。報語言環境時,結果是Building Java Library ........ : no。顯然非吾等所願。
Building code generators ..... :
Building C++ Library ......... : yes
Building C (GLib) Library .... : no
Building Java Library ........ : no
Building C# Library .......... : no
Building Python Library ...... : yes
Building Ruby Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : yes
Building Erlang Library ...... : no
Building Go Library .......... : no
Building TZlibTransport ...... : yes
Building TNonblockingServer .. : yes
      
  • 3、解決方法:在同級檔案夾下,more config.log,檢視不支援java環境的根本原因。

事實上,原因也無非是安裝jdk、ant或者ivy不成功導緻。

本人安裝是碰到的問題是:

configure:16550: checking for javac and java
Running "javac configtest_ax_javac_and_java.java"
Running "java configtest_ax_javac_and_java"
Exception in thread "main" java.lang.NoClassDefFoundError: configtest_ax_javac_and_java
Running "kaffe configtest_ax_javac_and_java"
./configure: line 16569: kaffe: command not found
Running "jikes configtest_ax_javac_and_java.java"
./configure: line 16562: jikes: command not found
Running "gcj -C configtest_ax_javac_and_java.java"
Running "java configtest_ax_javac_and_java"
Exception in thread "main" java.lang.NoClassDefFoundError: configtest_ax_javac_and_java
Running "kaffe configtest_ax_javac_and_java"
./configure: line 16569: kaffe: command not found
configure:16583: result: no
      

此問題的解決,不要去找configtest_ax_javac_and_java.java這個是否存在,由于找半天也找不到。

這樣的錯誤往往是環境變量classpath配置有問題,須要在classpath前面加入“./:”,預設從同級檔案夾下找javaproject檔案。

3、java.util.zip.ZipException: error in opening zip file

  • 1、錯誤資訊:在編譯thriftproject時。運作make指令。報如上的錯誤。具體資訊例如以下:
Making all in java
make[3]: Entering directory `/home/san1156/soft/thrift-0.8.0/lib/java'
/usr/local/ant/bin/ant 
Buildfile: /home/san1156/soft/thrift-0.8.0/lib/java/build.xml

setup.init:

mvn.ant.tasks.check:

proxy:

mvn.ant.tasks.download:
      [get] Getting: http://repo1.maven.org/maven2/org/apache/maven/maven-ant-tasks/2.1.3/maven-ant-tasks-2.1.3.jar
      [get] To: /home/san1156/soft/thrift-0.8.0/lib/java/build/tools/maven-ant-tasks-2.1.3.jar
      [get] Not modified - so not downloaded

mvn.init:
Unable to obtain resource from /home/san1156/soft/thrift-0.8.0/lib/java/build/tools/maven-ant-tasks-2.1.3.jar: java.util.zip.ZipException: error in opening zip file
  [typedef] Unable to obtain resource from /home/san1156/soft/thrift-0.8.0/lib/java/build/tools/maven-ant-tasks-2.1.3.jar: 
  [typedef] java.util.zip.ZipException: error in opening zip file
  [typedef]     at java.util.zip.ZipFile.open(Native Method)
  [typedef]     at java.util.zip.ZipFile.<init>(ZipFile.java:127)
  [typedef]     at java.util.jar.JarFile.<init>(JarFile.java:135)
  [typedef]     at java.util.jar.JarFile.<init>(JarFile.java:99)
  [typedef]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1006)
  [typedef]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:149)
  [typedef]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:110)
  [typedef]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:953)
  [typedef]     at org.apache.tools.ant.AntClassLoader.getNamedResources(AntClassLoader.java:922)
  [typedef]     at org.apache.tools.ant.loader.AntClassLoader5.getResources(AntClassLoader5.java:56)
  [typedef]     at org.apache.tools.ant.taskdefs.Definer.resourceToURLs(Definer.java:375)
  [typedef]     at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:267)
  [typedef]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
  [typedef]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
  [typedef]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  [typedef]     at java.lang.reflect.Method.invoke(Method.java:597)
  [typedef]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
  [typedef]     at org.apache.tools.ant.Task.perform(Task.java:348)
  [typedef]     at org.apache.tools.ant.Target.execute(Target.java:392)
  [typedef]     at org.apache.tools.ant.Target.performTasks(Target.java:413)
  [typedef]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
  [typedef]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
  [typedef]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
  [typedef]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
  [typedef]     at org.apache.tools.ant.Main.runBuild(Main.java:811)
  [typedef]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
  [typedef]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
  [typedef]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
  [typedef] Could not load definitions from resource org/apache/maven/artifact/ant/antlib.xml. It could not be found.

BUILD FAILED
/home/san1156/soft/thrift-0.8.0/lib/java/build.xml:267: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:remoteRepository
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -/usr/local/ant/lib
        -/root/.ant/lib
        -a directory added on the command line with the -lib argument


Total time: 0 seconds
make[3]: *** [all-local] Error 1
make[3]: Leaving directory `/home/san1156/soft/thrift-0.8.0/lib/java'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/san1156/soft/thrift-0.8.0/lib'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/san1156/soft/thrift-0.8.0'
make: *** [all] Error 2
      

2、處理方法: It could be related to log4j. http://stackoverflow.com/questions/325202/java-util-zip-zipexception-error-in-opening-zip-file

另外,thrift官網要求java必須安裝SLF4J,故,基本确定是未安裝SLF4J導緻。

4、安裝SLF4J、log4j

  • 1、下載下傳

官網上下載下傳apache-log4j-1.2.16.tar.gz、slf4j-1.6.4.tar.gz

下載下傳位址各自是: http://mirror.bjtu.edu.cn/apache/logging/log4j/1.2.16/apache-log4j-1.2.16.tar.gz

http://www.slf4j.org/dist/slf4j-1.6.4.tar.gz

  • 2、安裝

将須要的jar包放到運作位置,操作例如以下:

須要的jar包:log4j-1.2.16.jar、slf4j-api-1.6.4.jar、slf4j-log4j12-1.6.4.jar

指定位置:/home/san1156/soft/jdk1.6.0_30/lib/。也就是jdk的classpath路徑。

  • 3、clean中間檔案

因為報錯的時候産生了一些暫時檔案。須要運作

[[email protected] thrift-0.8.0]# make clean
      

或者

[[email protected] java]# cd /home/san1156/soft/thrift-0.8.0/lib/java
[[email protected] java]# ant clean
      
  • 4、又一次編譯。
[[email protected] thrift-0.8.0]# make
      

或者

[[email protected] java]# cd /home/san1156/soft/thrift-0.8.0/lib/java
[[email protected] java]# ant
運作通過,說明java環境木有問題
      
以上問題和解決方法,是本人編譯過程中所總結,希望對後來者實用
假設不幸,你碰到的問題,這裡沒有述及,能夠聯系本人一塊探讨
      

五、其它軟體的安裝方法

  • 1、centos boost install

http://blog.163.com/[email protected]/blog/static/171823157201101811587203/

http://hi.baidu.com/lbxthinker/blog/item/527b88ca1d8002f253664f68.html

(centos應用程式有自己的boost,點選更新就可以完畢安裝,就是版本号較低)

  • 2、gcc download

http://gcc.gnu.org/mirrors.html

  • 3、gcc安裝(未裝)

http://zhidao.baidu.com/question/1251827.html

  • 4、linux下JAVA安裝。及Java環境變量配置

http://apps.hi.baidu.com/share/detail/3320416

  • 5、ant安裝

http://blog.csdn.net/nivana999/article/details/6526961

export ANT_HOME=/home/san1156/soft/apache-ant-1.8.3
export PATH=/home/san1156/soft/apache-ant-1.8.3/bin:$PATH
改動/root/.bash_profile這個檔案,後面加入上面的環境變量
校驗ant方法:直接輸入ant,提示須要build.xml檔案
      
  • 6、linux下python的安裝

http://www.cnblogs.com/ewyb/archive/2010/10/26/1861744.html

六、參考網址

官方文檔:

編譯安裝thrift

http://wiki.apache.org/thrift/ThriftInstallation

Installing the required packages on CentOS 5

http://wiki.apache.org/thrift/GettingCentOS5Packages