进行Thrift的最小化安装,在Centos 6.5 上下面的步骤必不可少. 咱们给出从源代码编译Thrift的例子。这些介绍对Thrift0.9.2 的 releases版本一样有效。php
sudo yum -y update (系统会被升级为6.7)
sudo yum -y groupinstall "Development Tools" (这一步不必定成功,可是不影响后面)
sudo yum install -y wget
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz tar xvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix=/usr make sudo make install cd ..
wget http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz tar xvf automake-1.14.tar.gz cd automake-1.14 ./configure --prefix=/usr make sudo make install cd ..
wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz tar xvf bison-2.5.1.tar.gz cd bison-2.5.1 ./configure --prefix=/usr make sudo make install cd ..
全部语言都要用到Apache的Thrift 的IDL编译器,从这点看IDL编译器须要的一切都要安装。 (如何你只须要安装编译器可跳过此节).java
若是你要使用C++开发Thrift的客户端/服务器,你还须要编译支持C++共享库的可选包。node
sudo yum -y install libevent-devel zlib-devel openssl-devel
wget http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz tar xvf boost_1_55_0.tar.gz cd boost_1_55_0./bootstrap.sh sudo ./b2 install
wget http://mirrors.cnnic.cn/apache/thrift/0.9.1/thrift-0.9.1.tar.gz tar -zxvf thrift-0.9.1.tar.gz cd thrift-0.9.1 ./configure –-prefix=/your/program/path/ --enable-libtool-lock (--prefix后面的值是你要将程序安装到哪一个目录,若是不写,默认安装到/usr/local下面,个人是--prefix=/home/thrift) make make install
安装成功以后,咱们进入咱们的thrift的安装路径,你会看到thrift其实包含了三部分:一个bin程序、一堆头文件和若干库文件:python
咱们进入bin目录,执行./thrift --version, 就表示咱们安装成功了linux
可是咱们只能在这个目录下面执行thrift命令,若是咱们想在任何目录下执行thrift --version的相关命令,咱们能够将咱们的bin目录下的thrift文件拷贝到/usr/local/bin下面,而后执行. /etc/profile(加载到环境变量)就能够了c++
这个目录下面的可执行文件,均可以用命令执行apache
任何目录能够执行这个命令bootstrap
至此咱们的thrift-0.9.1安装成功了!centos
--------------------------------------------更新于2016年7月27日-----------------------------------------------------------------------------ruby
因为公司的编译系统环境变了,变成了到centos7上面(centos7.0 ,7.1,7.2均可以)因此之前在centos6.5上面编译的thrift的动态库,拿到centos7.1上面链接到个人程序里面就出错了,错误以下:
./../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_free' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `X509_NAME_get_index_by_NID' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `BIO_ctrl' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_set_locking_callback' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_set_default_passwd_cb_userdata' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `RAND_poll' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ERR_free_strings' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_num_locks' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_get_error' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `sk_value' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ASN1_STRING_to_UTF8' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ASN1_STRING_data' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_get_peer_certificate' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_set_default_passwd_cb' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ASN1_STRING_length' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `X509_get_ext_d2i' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_load_verify_locations' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_set_cipher_list' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `X509_get_subject_name' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `X509_free' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ERR_remove_state' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_library_init' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_free' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `sk_pop_free' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_set_id_callback' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_read' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_get_wbio' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_get_verify_result' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_get_verify_mode' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `X509_NAME_get_entry' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `X509_NAME_ENTRY_get_data' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_accept' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_set_dynlock_destroy_callback' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_peek' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_set_dynlock_lock_callback' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_shutdown' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_set_verify' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_cleanup_all_ex_data' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ERR_peek_error' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `X509_verify_cert_error_string' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_new' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `TLSv1_method' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `EVP_cleanup' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `sk_num' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ERR_reason_error_string' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_use_certificate_chain_file' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_connect' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ERR_clear_error' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_load_error_strings' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_free' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_write' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_set_fd' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `CRYPTO_set_dynlock_create_callback' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_use_PrivateKey_file' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_CTX_ctrl' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `GENERAL_NAME_free' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `ERR_get_error' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_new' ../../../module/thirdparty/thrift-0.9.1/lib/linux/libthrift.so: undefined reference to `SSL_get_shutdown' collect2: error: ld returned 1 exit status make: *** [nodemanager] Error 1
解决办法,将thrift库拿到centos7的系统上面从新编译,用生成的新库连接到个人程序中,就能够解决,其实就能够安装上面的步骤在centos7的系统上面再作一次就能够了,可是如今不同了,就是个人程序虽然跑在64位上面,可是是32位的程序,其连接的也必须是32位的库,因此咱们thrift库要编译成32位的库,可是cenos7是64位系统,默认编译成64位程序,要想生成32位的程序,步骤以下
前面都不变,就在执行thrift的configure文件的时候加入一些编译选项,以下:
ERLCFLAGS="-m32" MONO_CFLAGS="-m32" GOBJECT_CFLAGS="-m32 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include" GLIB_CFLAGS="-m32 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include" QT_CFLAGS="-m32" CFLAGS="-m32" CXXFLAGS="-m32" LDFLAGS="-m32" ./configure --with-lua=no --prefix=/home/thrift
由于执行configure就是生成makefile,加这些编译选项就可让其生成编译32位库的makefile.
可是由于是让其编译32位的程序,会检测32位的glibc库和一些32位的环境,咱们准备好没有,若是没有的话,执行以上命令可能会出以下错误
这是由于没有32位的库环境,咱们安装好32位的环境就能够编译,安装命令以下:
yum install -y libgcc.i686 glibc-devel.i686 libstdc++.i686 zlib.i686 zlib-devel.i686 libstdc++-devel.i686 glibc-static.i686
在执行上面一串configure命令,可能出现
再安装32位的openssl-devel
yum install openssl-devel.i686
基本configure就能够成功。
可是若是这样,make编译的时候可能会出以下错误:
能够看获得其实咱们是安装glib-2.0,可是没有这个头文件,咱们从别的正常的机器上把glibconfig.h拷贝过来就能够了
scp -P2223 /usr/lib/glib-2.0/include/glibconfig.h 172.16.81.236:/usr/lib/glib-2.0/include/
而后这边在make,就会发现成功了,而后再make install,就能够去咱们指定的地方找咱们的库了。
configure还有一个地方值得咱们注意,执行configure有不少命令能够供咱们选择,像若是你不要编译erlang的thrift库,可是你的环境装了erlang环境,执行configure的时候,说erlang环境没有配置好,有以下错误:
checking for erl... /usr/local/bin/erl checking for erlc... /usr/local/bin/erlc checking for erlc... /usr/local/bin/erlc checking for erl... /usr/local/bin/erl checking for Erlang/OTP library base directory... configure: error: in `/home/buildthrift/thrift-0.9.1': configure: error: test Erlang program execution failed See `config.log' for more details
那咱们在执行configure的时候去掉erlang。命令以下:
./configure --prefix=/home/thrift --without-erlang
这样就能够成功。
其实若是咱们只要cpp,能够以下:
./configure --with-cpp --with-boost --without-python --without-csharp --without-java --without-erlang --without-perl --without-php --without-php_extension --without-ruby --without-haskell --without-go
这样就能够快不少。