【Thrift一】Thrift编译安装
编程技术  /  houtizong 发布于 3年前   100
The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages
上面这段话选自Apache对Thrift的一句话介绍,Thrift是一个高性能的RPC服务框架。在技术选型时,有如下三方面的需求时,考虑使用Thrift
1.高并发
2.请求和响应的数据传输量大
3.业务系统跨多种语言
个人认为在没有特别strong的理由情况下,慎用Thrift。HTTP请求通常都能够满足需求,使用Thrift带来很多开发上的额外的工作量,一个简单的服务,就要写客户端代码,.thrift接口定义以及服务器端的服务响应代码,简单的事情复杂化。使用更多的RPC框架是codehaus的Hessian
以在Ubuntu上安装为例
参考:
http://thrift.apache.org/docs/install/debian
http://thrift.apache.org/docs/BuildingFromSource
1.下载Thrift安装包
http://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.1/thrift-0.9.1.tar.gz
2.安装Thrift编译和安装所以来的工具和库
sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev
3.解压thrift-0.9.1.tar.gz
tar -xzvf thrift-0.9.1.tar.gz
4.进入Thrift的解压目录
5.在终端命令行执行命令
./configure JAVAC=/software/devsoftware/jdk1.7.0_55/javac
--JAVAC选项表示显式的指定javac命令的位置,而不需thrift在编译时根据系统配置进行猜测
配置过程提示信息如下,等Thrift熟悉了,再来看看这个过程应该是比较有意思的
tom$ ./configure JAVAC=/software/devsoftware/jdk1.7.0_55/javacchecking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for a thread-safe mkdir -p... /bin/mkdir -pchecking for gawk... nochecking for mawk... mawkchecking whether make sets $(MAKE)... yeschecking how to create a ustar tar archive... gnutarchecking for pkg-config... /usr/bin/pkg-configchecking pkg-config is at least version 0.9.0... yeschecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for style of include used by make... GNUchecking dependency style of gcc... gcc3checking how to run the C preprocessor... gcc -Echecking for g++... g++checking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking dependency style of g++... gcc3checking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking how to print strings... printfchecking for a sed that does not truncate output... /bin/sedchecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking for fgrep... /bin/grep -Fchecking for ld used by gcc... /usr/bin/ldchecking if the linker (/usr/bin/ld) is GNU ld... yeschecking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -Bchecking the name lister (/usr/bin/nm -B) interface... BSD nmchecking whether ln -s works... yeschecking the maximum length of command line arguments... 1572864checking whether the shell understands some XSI constructs... yeschecking whether the shell understands "+="... yeschecking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noopchecking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noopchecking for /usr/bin/ld option to reload object files... -rchecking for objdump... objdumpchecking how to recognize dependent libraries... pass_allchecking for dlltool... nochecking how to associate runtime and link libraries... printf %s\nchecking for ar... archecking for archiver @FILE support... @checking for strip... stripchecking for ranlib... ranlibchecking command to parse /usr/bin/nm -B output from gcc object... okchecking for sysroot... nochecking for mt... mtchecking if mt is a manifest tool... nochecking for ANSI C header files... yeschecking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yeschecking for inttypes.h... yeschecking for stdint.h... yeschecking for unistd.h... yeschecking for dlfcn.h... yeschecking for objdir... .libschecking if gcc supports -fno-rtti -fno-exceptions... nochecking for gcc option to produce PIC... -fPIC -DPICchecking if gcc PIC flag -fPIC -DPIC works... yeschecking if gcc static flag -static works... yeschecking if gcc supports -c -o file.o... yeschecking if gcc supports -c -o file.o... (cached) yeschecking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yeschecking whether -lc should be explicitly linked in... nochecking dynamic linker characteristics... GNU/Linux ld.sochecking how to hardcode library paths into programs... immediatechecking whether stripping libraries is possible... yeschecking if libtool supports shared libraries... yeschecking whether to build shared libraries... yeschecking whether to build static libraries... yeschecking how to run the C++ preprocessor... g++ -Echecking for ld used by g++... /usr/bin/ld -m elf_x86_64checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yeschecking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yeschecking for g++ option to produce PIC... -fPIC -DPICchecking if g++ PIC flag -fPIC -DPIC works... yeschecking if g++ static flag -static works... yeschecking if g++ supports -c -o file.o... yeschecking if g++ supports -c -o file.o... (cached) yeschecking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yeschecking dynamic linker characteristics... (cached) GNU/Linux ld.sochecking how to hardcode library paths into programs... immediatechecking whether make sets $(MAKE)... (cached) yeschecking for bison... bison -ychecking for flex... flexchecking lex output file root... lex.yychecking lex library... -lflchecking whether yytext is a pointer... yeschecking whether ln -s works... yeschecking for gawk... (cached) mawkchecking for ranlib... (cached) ranlibchecking for boostlib >= 1.40.0... yeschecking for libevent >= 1.0... yeschecking for zlib >= 1.2.3... yeschecking for QT... nochecking for GLIB... nochecking for GOBJECT... nochecking for MONO... nochecking for MONO... nochecking for javac and java... nochecking for ant... nochecking for ant version > 1.7... expr: syntax errornochecking for erl... nochecking for erlc... nochecking for a Python interpreter with version >= 2.4... pythonchecking for python... /usr/bin/pythonchecking for python version... 2.7checking for python platform... linux2checking for python script directory... ${prefix}/lib/python2.7/dist-packageschecking for python extension module directory... ${exec_prefix}/lib/python2.7/dist-packageschecking for trial... /usr/bin/trialchecking for perl... /usr/bin/perlchecking for perl module Bit::Vector... nochecking for php... nochecking for php-config... nochecking for phpunit... nochecking for ruby... nochecking for rake... nochecking for bundle... nochecking for cabal... nochecking for runhaskell... nochecking for go... nochecking for DMD... nochecking for library containing strerror... none requiredchecking for an ANSI C-conforming const... yeschecking for inline... inlinechecking for working volatile... yeschecking for stdbool.h that conforms to C99... yeschecking for _Bool... nochecking for ANSI C header files... (cached) yeschecking whether time.h and sys/time.h may both be included... yeschecking for sys/wait.h that is POSIX.1 compatible... yeschecking return type of signal handlers... voidchecking arpa/inet.h usability... yeschecking arpa/inet.h presence... yeschecking for arpa/inet.h... yeschecking sys/param.h usability... yeschecking sys/param.h presence... yeschecking for sys/param.h... yeschecking fcntl.h usability... yeschecking fcntl.h presence... yeschecking for fcntl.h... yeschecking for inttypes.h... (cached) yeschecking limits.h usability... yeschecking limits.h presence... yeschecking for limits.h... yeschecking netdb.h usability... yeschecking netdb.h presence... yeschecking for netdb.h... yeschecking netinet/in.h usability... yeschecking netinet/in.h presence... yeschecking for netinet/in.h... yeschecking pthread.h usability... yeschecking pthread.h presence... yeschecking for pthread.h... yeschecking stddef.h usability... yeschecking stddef.h presence... yeschecking for stddef.h... yeschecking for stdlib.h... (cached) yeschecking sys/socket.h usability... yeschecking sys/socket.h presence... yeschecking for sys/socket.h... yeschecking sys/time.h usability... yeschecking sys/time.h presence... yeschecking for sys/time.h... yeschecking sys/un.h usability... yeschecking sys/un.h presence... yeschecking for sys/un.h... yeschecking sys/poll.h usability... yeschecking sys/poll.h presence... yeschecking for sys/poll.h... yeschecking sys/resource.h usability... yeschecking sys/resource.h presence... yeschecking for sys/resource.h... yeschecking for unistd.h... (cached) yeschecking libintl.h usability... yeschecking libintl.h presence... yeschecking for libintl.h... yeschecking malloc.h usability... yeschecking malloc.h presence... yeschecking for malloc.h... yeschecking openssl/ssl.h usability... yeschecking openssl/ssl.h presence... yeschecking for openssl/ssl.h... yeschecking openssl/rand.h usability... yeschecking openssl/rand.h presence... yeschecking for openssl/rand.h... yeschecking openssl/x509v3.h usability... yeschecking openssl/x509v3.h presence... yeschecking for openssl/x509v3.h... yeschecking sched.h usability... yeschecking sched.h presence... yeschecking for sched.h... yeschecking wchar.h usability... yeschecking wchar.h presence... yeschecking for wchar.h... yeschecking for pthread_create in -lpthread... yeschecking for clock_gettime in -lrt... yeschecking for setsockopt in -lsocket... nochecking for BN_init in -lcrypto... yeschecking for SSL_ctrl in -lssl... yeschecking for int16_t... yeschecking for int32_t... yeschecking for int64_t... yeschecking for int8_t... yeschecking for mode_t... yeschecking for off_t... yeschecking for size_t... yeschecking for ssize_t... yeschecking for uint16_t... yeschecking for uint32_t... yeschecking for uint64_t... yeschecking for uint8_t... yeschecking for ptrdiff_t... yeschecking whether struct tm is in sys/time.h or time.h... time.hchecking whether AI_ADDRCONFIG is declared... yeschecking for working alloca.h... yeschecking for alloca... yeschecking for pid_t... yeschecking vfork.h usability... nochecking vfork.h presence... nochecking for vfork.h... nochecking for fork... yeschecking for vfork... yeschecking for working fork... yeschecking for working vfork... (cached) yeschecking for stdlib.h... (cached) yeschecking for GNU libc compatible malloc... yeschecking for working memcmp... yeschecking for stdlib.h... (cached) yeschecking for GNU libc compatible realloc... yeschecking sys/select.h usability... yeschecking sys/select.h presence... yeschecking for sys/select.h... yeschecking for sys/socket.h... (cached) yeschecking types of arguments for select... int,fd_set *,struct timeval *checking whether lstat correctly handles trailing slash... yeschecking whether stat accepts an empty string... nochecking whether strerror_r is declared... yeschecking for strerror_r... yeschecking whether strerror_r returns char *... yeschecking for strftime... yeschecking for vprintf... yeschecking for _doprnt... nochecking for strtoul... yeschecking for bzero... yeschecking for ftruncate... yeschecking for gethostbyname... yeschecking for gettimeofday... yeschecking for memmove... yeschecking for memset... yeschecking for mkdir... yeschecking for realpath... yeschecking for select... yeschecking for socket... yeschecking for strchr... yeschecking for strdup... yeschecking for strerror... yeschecking for strstr... yeschecking for strtol... yeschecking for sqrt... yeschecking for alarm... yeschecking for clock_gettime... yeschecking for sched_get_priority_min... yeschecking for sched_get_priority_max... yeschecking the behavior of a signed right shift... arithmeticconfigure: creating ./config.statusconfig.status: creating Makefileconfig.status: creating compiler/cpp/Makefileconfig.status: creating compiler/cpp/version.hconfig.status: creating compiler/cpp/src/windows/version.hconfig.status: creating lib/Makefileconfig.status: creating lib/cpp/Makefileconfig.status: creating lib/cpp/test/Makefileconfig.status: creating lib/cpp/thrift-nb.pcconfig.status: creating lib/cpp/thrift-z.pcconfig.status: creating lib/cpp/thrift-qt.pcconfig.status: creating lib/cpp/thrift.pcconfig.status: creating lib/c_glib/Makefileconfig.status: creating lib/c_glib/thrift_c_glib.pcconfig.status: creating lib/c_glib/test/Makefileconfig.status: creating lib/csharp/Makefileconfig.status: creating lib/d/Makefileconfig.status: creating lib/d/test/Makefileconfig.status: creating lib/erl/Makefileconfig.status: creating lib/go/Makefileconfig.status: creating lib/go/test/Makefileconfig.status: creating lib/hs/Makefileconfig.status: creating lib/java/Makefileconfig.status: creating lib/js/test/Makefileconfig.status: creating lib/perl/Makefileconfig.status: creating lib/perl/test/Makefileconfig.status: creating lib/php/Makefileconfig.status: creating lib/php/test/Makefileconfig.status: creating lib/py/Makefileconfig.status: creating lib/rb/Makefileconfig.status: creating test/Makefileconfig.status: creating test/cpp/Makefileconfig.status: creating test/hs/Makefileconfig.status: creating test/nodejs/Makefileconfig.status: creating test/php/Makefileconfig.status: creating test/perl/Makefileconfig.status: creating test/py/Makefileconfig.status: creating test/py.twisted/Makefileconfig.status: creating test/py.tornado/Makefileconfig.status: creating test/rb/Makefileconfig.status: creating tutorial/Makefileconfig.status: creating tutorial/cpp/Makefileconfig.status: creating tutorial/go/Makefileconfig.status: creating tutorial/java/Makefileconfig.status: creating tutorial/js/Makefileconfig.status: creating tutorial/py/Makefileconfig.status: creating tutorial/py.twisted/Makefileconfig.status: creating tutorial/py.tornado/Makefileconfig.status: creating tutorial/rb/Makefileconfig.status: creating config.hconfig.status: config.h is unchangedconfig.status: creating lib/cpp/src/thrift/config.hconfig.status: lib/cpp/src/thrift/config.h is unchangedconfig.status: executing depfiles commandsconfig.status: executing libtool commandsthrift 0.9.1Building C++ Library ......... : yesBuilding C (GLib) Library .... : noBuilding Java Library ........ : noBuilding C# Library .......... : noBuilding Python Library ...... : yesBuilding Ruby Library ........ : noBuilding Haskell Library ..... : noBuilding Perl Library ........ : noBuilding PHP Library ......... : noBuilding Erlang Library ...... : noBuilding Go Library .......... : noBuilding D Library ........... : noC++ Library: Build TZlibTransport ...... : yes Build TNonblockingServer .. : yes Build TQTcpServer (Qt) .... : noPython Library: Using Python .............. : /usr/bin/pythonIf something is missing that you think should be present,please skim the output of configure to find the missingcomponent. Details are present in config.log.
6. 在终端执行make命令进行编译
make
7. 执行命令make check执行完整性检查测试
make check
8. 执行命令sh test/test.sh执行单元测试
sh test/test.sh
9. 执行命令make install完成最后安装
sudo make install
10.执行which thrift查看thrift的安装路径
whcih thrift
默认,thrift安装在/usr/local/bin/thrift
11.执行thrift --help查看thrift命令的选项
Usage: thrift [options] fileOptions: -version Print the compiler version -o dir Set the output directory for gen-* packages (default: current directory) -out dir Set the ouput location for generated files. (no gen-* folder will be created) -I dir Add a directory to the list of directories searched for include directives -nowarn Suppress all compiler warnings (BAD!) -strict Strict compiler warnings on -v[erbose] Verbose mode -r[ecurse] Also generate included files -debug Parse debug trace to stdout --allow-neg-keys Allow negative field keys (Used to preserve protocol compatibility with older .thrift files) --allow-64bit-consts Do not print warnings about using 64-bit constants --gen STR Generate code with a dynamically-registered generator. STR has the form language[:key1=val1[,key2,[key3=val3]]]. Keys and values are options passed to the generator. Many options will not require values.Available generators (and options): as3 (AS3): bindable: Add [bindable] metadata to all the struct classes. c_glib (C, using GLib): cocoa (Cocoa): log_unexpected: Log every time an unexpected field ID or type is encountered. validate_required: Throws exception if any required field is not set. cpp (C++): cob_style: Generate "Continuation OBject"-style classes. no_client_completion: Omit calls to completion__() in CobClient class. templates: Generate templatized reader/writer methods. pure_enums: Generate pure enums instead of wrapper classes. dense: Generate type specifications for the dense protocol. include_prefix: Use full include paths in generated files. csharp (C#): async: Adds Async support using Task.Run. asyncctp: Adds Async CTP support using TaskEx.Run. wcf: Adds bindings for WCF to generated classes. serial: Add serialization support to generated classes. nullable: Use nullable types for properties. hashcode: Generate a hashcode and equals implementation for classes. union: Use new union typing, which includes a static read function for union types. d (D): delphi (delphi): ansistr_binary: Use AnsiString for binary datatype (default is TBytes). register_types: Enable TypeRegistry, allows for creation of struct, union and container instances by interface or TypeInfo() erl (Erlang): go (Go): package_prefix= Package prefix for generated files. thrift_import= Override thrift package import path (default:git.apache.org/thrift.git/lib/go/thrift) gv (Graphviz): exceptions: Whether to draw arrows from functions to exception. hs (Haskell): html (HTML): standalone: Self-contained mode, includes all CSS in the HTML files. Generates no style.css file, but HTML files will be larger. java (Java): beans: Members will be private, and setter methods will return void. private-members: Members will be private, but setter methods will return 'this' like usual. nocamel: Do not use CamelCase field accessors with beans. hashcode: Generate quality hashCode methods. android_legacy: Do not use java.io.IOException(throwable) (available for Android 2.3 and above). java5: Generate Java 1.5 compliant code (includes android_legacy flag). sorted_containers: Use TreeSet/TreeMap instead of HashSet/HashMap as a implementation of set/map. javame (Java ME): js (Javascript): jquery: Generate jQuery compatible code. node: Generate node.js compatible code. ocaml (OCaml): perl (Perl): php (PHP): inlined: Generate PHP inlined files server: Generate PHP server stubs oop: Generate PHP with object oriented subclasses rest: Generate PHP REST processors py (Python): new_style: Generate new-style classes. twisted: Generate Twisted-friendly RPC services. tornado: Generate code for use with Tornado. utf8strings: Encode/decode strings using utf8 in the generated code. slots: Generate code using slots for instance members. dynamic: Generate dynamic code, less code generated but slower. dynbase=CLS Derive generated classes from class CLS instead of TBase. dynexc=CLS Derive generated exceptions from CLS instead of TExceptionBase. dynimport='from foo.bar import CLS' Add an import line to generated code to find the dynbase class. rb (Ruby): rubygems: Add a "require 'rubygems'" line to the top of each generated file. st (Smalltalk): xsd (XSD):
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接