centos 6.5(centos7)下安裝thrift 0.9.1詳細教程

進行Thrift的最小化安裝,在Centos 6.5 上下面的步驟必不可少. 咱們給出從源代碼編譯Thrift的例子。這些介紹對Thrift0.9.2 的 releases版本一樣有效。php

更新系統

sudo yum -y update         (系統會被升級爲6.7)

 

安裝平臺開發工具

sudo yum -y groupinstall "Development Tools"   (這一步不必定成功,可是不影響後面)

 

升級autoconf/automake/bison

sudo yum install -y wget

 

升級 autoconf

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 ..

 

升級 automake

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 ..

 

升級 bison

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 ..

 

添加添加可選的c++語言庫依賴庫

全部語言都要用到Apache的Thrift 的IDL編譯器,從這點看IDL編譯器須要的一切都要安裝。 (如何你只須要安裝編譯器可跳過此節).java

若是你要使用C++開發Thrift的客戶端/服務器,你還須要編譯支持C++共享庫的可選包。node

安裝C++依賴庫

sudo yum -y install libevent-devel zlib-devel openssl-devel

 

升級 Boost

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

 

安裝thrift-0.9.1

 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

這樣就能夠快不少。

相關文章
相關標籤/搜索