CentOS 6安裝thrift支持erlang開發


早前,在我的博文thrift多平台安裝介紹了如何在debian/ubuntu下面安裝thrift,並支持erlang開發的。而在CentOS平台下,並沒有成功安裝。經過不斷摸索,終於成功了,這篇博文就是介紹如何在CentOS下編譯安裝thrift,並提供erlang開發支持。

1.失敗原因及解決方法

我遇到的主要問題是,erlang的crypto模塊在調用openssl的共享庫的時候失敗,從而導致編譯thrift的erlang類庫失敗,整個編譯過程無法繼續下去。

在erl終端輸入crypto:start()就可以看到下面的情況

[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開發支持。

如果你的crypto:start()輸出結果是ok的話,那就不會出現問題。

$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動態鏈接庫不兼容的問題與解決方案得到詳細的信息。

解決方法有2個,可以重新編譯openssl,或者使用Erlang Solutions提供的二進制erlang/otp包.

另外我遇到的一個小問題是,erlang/otp的版本低,可能小於R14的,都會導致編譯通不過。選用最新的erlang/otp版本就不會出現這個問題。

 

2.安裝erlang/otp

在安裝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 腳本

CentOS 安裝 Erlang

很好,我們繼續前進:

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的安裝。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM