天天看点

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