早前,在個人博文thrift多平臺安裝介紹瞭如何在debian/ubuntu下面安裝thrift,並支持erlang開發的。而在CentOS平臺下,並無成功安裝。通過不斷摸索,終於成功了,這篇博文就是介紹如何在CentOS下編譯安裝thrift,並提供erlang開發支持。html
1.失敗緣由及解決方法python
我遇到的主要問題是,erlang的crypto模塊在調用openssl的共享庫的時候失敗,從而致使編譯thrift的erlang類庫失敗,整個編譯過程沒法繼續下去。linux
在erl終端輸入crypto:start()就能夠看到下面的狀況c++
[root@localhost 6]# /usr/local/bin/erl Erlang R16B03 (erts-5.10.4) [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false] Eshell V5.10.4 (abort with ^G) 1> crypto:start(). ** exception error: undefined function crypto:start/0 2> =ERROR REPORT==== 12-Jan-2014::00:06:29 === Unable to load crypto library. Failed with error: "load_failed, Failed to load NIF library: '/usr/local/lib/erlang/lib/crypto-3.2/priv/lib/crypto.so: undefined symbol: EC_GROUP_new_curve_GF2m'" OpenSSL might not be installed on this system. =ERROR REPORT==== 12-Jan-2014::00:06:29 === The on_load function for module crypto returned {error, {load_failed, "Failed to load NIF library: '/usr/local/lib/erlang/lib/crypto-3.2/priv/lib/crypto.so: undefined symbol: EC_GROUP_new_curve_GF2m'"}}
若是你也遇到這個問題,那能夠確定,編譯的thrift無法提供erlang開發支持。git
若是你的crypto:start()輸出結果是ok的話,那就不會出現問題。github
$erl Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:3:3] [async-threads:10] [kernel-poll:false] Eshell V5.10.4 (abort with ^G) 1> crypto:start(). ok 2>
若是出現像上述這樣一樣問題的話,極可能是Erlang的crypto模塊與安裝的openssl動態連接庫不兼容,能夠看Erlang的crypto模塊與最新的openssl動態連接庫不兼容的問題與解決方案獲得詳細的信息。chrome
解決方法有2個,能夠從新編譯openssl,或者使用Erlang Solutions提供的二進制erlang/otp包.shell
另外我遇到的一個小問題是,erlang/otp的版本低,可能小於R14的,都會致使編譯通不過。選用最新的erlang/otp版本就不會出現這個問題。apache
2.安裝erlang/otpbootstrap
在安裝thrift前,咱們要先安裝erlang/otp.下面介紹2種方法,源碼安裝,以及使用Erlang Solutions的二進制包。
2.1 源碼安裝erlang/otp
首先編譯安裝openssl,我這裏選用的版本是openssl-1.0.0l.tar.gz
wget -c http://www.openssl.org/source/openssl-1.0.0l.tar.gz
tar xzf openssl-1.0.0l.tar.gz
cd openssl-1.0.0l
./config
按照Erlang的crypto模塊與最新的openssl動態連接庫不兼容的問題與解決方案所說的方法編輯Makefile文件,添加-fPIC編譯選項
在vim裏面搜索gcc,而後在下面的行添加:
添加完畢後,咱們就能夠編譯安裝了:
make make install
在config階段,我使用默認配置,因此openssl安裝目錄在/usr/local/ssl
接下來編譯erlang/otp
在CentOS下面編譯erlang/otp,能夠參考下面2篇博文來安裝erlang/otp的依賴項:
CentOS(Fedora)下源代碼編譯安裝 erlang 環境的 shell 腳本
很好,咱們繼續前進:
yum install -y kernel-devel m4 fop ncurses-devel tk unixODBC unixODBC-devel gcc gcc-c++
wget -c http://www.erlang.org/download/otp_src_R16B03.tar.gz
tar xzf otp_src_R16B03.tar.gz
cd otp_src_R16B03
在configure階段,指定使用咱們定製的openssl
./configure --with-ssl=/usr/local/ssl make make install
編譯安裝erlang/otp大概花費20分鐘,安裝位置在/usr/local下面。
2.2 使用Erlang Solutions提供的二進制erlang/otp包
Erlang Solutions提供了多個平臺的erlang/otp的二進制安裝包,很是容易使用。
Erlang Solutions的erlang安裝包信息在這裏,使用的js文件好像有兼容問題,在linux下的chrome瀏覽器,只能看到source選項卡.
須要注意的是,Erlang Solutions編譯的erlang/otp包可能會有問題,例如上面的crypto:start()就出現上面的問題。咱們在使用的時候,遇到問題,咱們能夠按照上面源碼編譯的方法進行安裝。
就在前天,也就是2014-01-10,使用Erlang Solutions的rpm包就出現了crypto:start()啓動不成功的現象,而後我昨天檢測到它更新了erlang的centos安裝包,應該就是修復了這個問題。有圖爲證:
使用下面的命令來安裝erlang/otp:
wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm rpm -Uvh erlang-solutions-1.0-1.noarch.rpm yum makecache yum install -y erlang
3.源碼編譯安裝thrift
下面的步驟跟thrift多平臺安裝中的Debian/Ubuntu下編譯安裝thrift差很少。
yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel xz git -y git clone -b 0.9.1 https://github.com/apache/thrift thrift-0.9.1 cd thrift-0.9.1 ./bootstrap.sh
在生成configure文件時出錯:
configure.ac:20: error: Autoconf version 2.65 or higher is required configure.ac:20: the top level autom4te: /usr/bin/m4 failed with exit status: 63 autoscan: /usr/bin/autom4te failed with exit status: 63
果真好事多磨,好吧,咱們繼續源碼安裝autoconf:
wget -c http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz tar xJf autoconf-2.69.tar.xz cd autoconf-2.69 ./configure make make install
升級autoconf後,執行bootstrap.sh,提示信息有大量的warning,但仍是生成了configure文件。無論warning,咱們繼續前進:
./configure --with-cpp=no --with-python=no make make check make install
沒有報錯,至此終於完成了thrift的安裝。