centos 6.5(centos7)下安装thrift 0.9.1详细教程

2016-07-28 13:11:51来源:oschina作者:双月通天人点击

进行Thrift的最小化安装,在Centos 6.5 上下面的步骤必不可少. 我们给出从源代码编译Thrift的例子。这些介绍对Thrift0.9.2 的 releases版本同样有效。


更新系统
sudoyum-yupdate(系统会被升级为6.7) 安装平台开发工具
sudoyum-ygroupinstall"DevelopmentTools"(这一步不一定成功,但是不影响后面) 升级autoconf/automake/bison
sudoyuminstall-ywget 升级 autoconf
wgethttp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tarxvfautoconf-2.69.tar.gz
cdautoconf-2.69
./configure--prefix=/usr
make
sudomakeinstall
cd.. 升级 automake
wgethttp://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz
tarxvfautomake-1.14.tar.gz
cdautomake-1.14
./configure--prefix=/usr
make
sudomakeinstall
cd.. 升级 bison
wgethttp://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz
tarxvfbison-2.5.1.tar.gz
cdbison-2.5.1
./configure--prefix=/usr
make
sudomakeinstall
cd.. 添加添加可选的c++语言库依赖库

所有语言都要用到Apache的Thrift 的IDL编译器,从这点看IDL编译器需要的一切都要安装。 (如何你只需要安装编译器可跳过此节).


如果你要使用C++开发Thrift的客户端/服务器,你还需要编译支持C++共享库的可选包。


安装C++依赖库
sudoyum-yinstalllibevent-develzlib-developenssl-devel 升级 Boost
wgethttp://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz
tarxvfboost_1_55_0.tar.gz
cdboost_1_55_0./bootstrap.sh
sudo./b2install 安装thrift-0.9.1
wgethttp://mirrors.cnnic.cn/apache/thrift/0.9.1/thrift-0.9.1.tar.gz
tar-zxvfthrift-0.9.1.tar.gz
cdthrift-0.9.1
./configure–-prefix=/your/program/path/--enable-libtool-lock
(--prefix后面的值是你要将程序安装到哪个目录,如果不写,默认安装到/usr/local下面,我的是--prefix=/home/thrift)
make
makeinstall

安装成功之后,我们进入我们的thrift的安装路径,你会看到thrift其实包含了三部分:一个bin程序、一堆头文件和若干库文件:



我们进入bin目录,执行./thrift --version, 就表示我们安装成功了



但是我们只能在这个目录下面执行thrift命令,如果我们想在任何目录下执行thrift --version的相关命令,我们可以将我们的bin目录下的thrift文件拷贝到/usr/local/bin下面,然后执行. /etc/profile(加载到环境变量)就可以了



这个目录下面的可执行文件,都可以用命令执行



任何目录可以执行这个命令



至此我们的thrift-0.9.1安装成功了!

--------------------------------------------更新于2016年7月27日-----------------------------------------------------------------------------


由于公司的编译系统环境变了,变成了到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

这样就可以快很多。

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台