因?yàn)閟hell操作mongo比較麻煩,只好嘗試使用perl操作mongo,perl需要操作mongodb必須先安裝相應(yīng)的驅(qū)動(dòng),大部分人使用cpan安裝,個(gè)人覺得太麻煩,使用cpanm安裝perl模塊。
# cpanm MongoDB
--> Working on MongoDB
Fetching http://www.cpan.org/authors/id/F/FR/FRIEDO/MongoDB-0.702.1.tar.gz ... OK
Configuring MongoDB-0.702.1 ... OK
Building and testing MongoDB-0.702.1 ... FAIL
! Installing MongoDB failed. See /root/.cpanm/work/1376540233.15152/build.log for details. Retry with --force to force install it.
cpanm報(bào)錯(cuò)了,使用–force參數(shù)
# cpanm MongoDB --force
--> Working on MongoDB
Fetching http://www.cpan.org/authors/id/F/FR/FRIEDO/MongoDB-0.702.1.tar.gz ... OK
Configuring MongoDB-0.702.1 ... OK
Building and testing MongoDB-0.702.1 ... FAIL
! Testing MongoDB-0.702.1 failed but installing it anyway.
Successfully installed MongoDB-0.702.1 (upgraded from 0.702.0)
1 distribution installe
看起來一切完好。測試腳本
腳本內(nèi)容:
# cat /root/testMongo.pl
#!/usr/bin/perl
use MongoDB;
my $connection = MongoDB::Connection->new( host => 'localhost', port => 27017);
運(yùn)行:
# perl /root/testMongo.pl
/usr/bin/perl: symbol lookup error: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/MongoDB/MongoDB.so: undefined symbol: HeUTF8
google查詢“MongoDB.so: undefined symbol: HeUTF8”,只發(fā)現(xiàn)一篇相關(guān)文章.一群人討論這個(gè)問題。其中一個(gè)人的解決方法如下:
# wget http://search.cpan.org/CPAN/authors/id/F/FR/FRIEDO/MongoDB-0.701.4.tar.gz
# tar -xzvf MongoDB-0.701.4.tar.gz
# cd MongoDB-0.701.4
添加如下內(nèi)容到perl_mongo.h:
/* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */
#ifndef HeUTF8
#define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \
SvUTF8(HeKEY_sv(he)) : \
(U32)HeKUTF8(he))
#endif
# perl Makefile.PL
# make
# make install
perl腳本運(yùn)行ok.
實(shí)際上是因?yàn)椴患嫒莸膯栴},對于系統(tǒng)RHEL5/CENTOS5發(fā)行版,mongodb的perl驅(qū)動(dòng)最后的一個(gè)版本是v0.45
如下是國外網(wǎng)友的回復(fù):
The latest version to compile, test and install properly on Rhel5/Centos5 is v0.45 by KRISTINA. (requires Any::Moose)
https://metacpan.org/release/KRISTINA/MongoDB-0.45