一、簡介
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 。
二、安裝環境
- 操作系統:centos5版本號以上操作系統
- 網絡:有獨立ip,能訪問外網
- 遠程連接軟件: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下,解壓
[root@bogon san1156]# tar zxpvf apache-ant-1.8.3.tar.gz [root@bogon 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命令測試執行情況
[root@bogon san1156]# ant Buildfile: build.xml does not exist! Build failed [root@bogon 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
此命令自己主動下載安裝程序,並安裝,可謂快捷方便。純傻瓜式操作
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中間文件
因為報錯的時候產生了一些暫時文件。須要運行
[root@localhost thrift-0.8.0]# make clean
或者
[root@localhost java]# cd /home/san1156/soft/thrift-0.8.0/lib/java [root@localhost java]# ant clean
- 4、又一次編譯。
[root@localhost thrift-0.8.0]# make
或者
[root@localhost java]# cd /home/san1156/soft/thrift-0.8.0/lib/java [root@localhost java]# ant 運行通過,說明java環境木有問題
以上問題和解決方法,是本人編譯過程中所總結,希望對后來者實用 假設不幸,你碰到的問題,這里沒有述及,能夠聯系本人一塊探討
五、其它軟件的安裝方法
- 1、centos boost install
http://blog.163.com/solylee@126/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