CentOS 5下安装perl module以支持IPV6

在我们的产品中用到了LWP::UserAgent,用于在perl代码中进行http请求,测试发现在纯V6环境下会返回下面的错误:

Can't connect to [2001:db8:0:1:10:208:135:232]:8002 (Bad hostname '[2001:db8:0:1:10:208:135:232]')

调查了以后发现一些perl应用依赖于IO::Socket::INET,由于这个模块本身不支持IPV6,所以在纯V6环境下可能需要做一些工作才能work。搜索CPAN,模块Net::INET6Glue::INET_is_INET6提供了对这个问题的解决方案,在应用代码中只需要引用一下就可以。

use Net::INET6Glue::INET_is_INET6;
但是CentOS 5最新版本的perl是5.8.8,默认并没有这个模块,下面的问题就是如何安装呢?

如果有网络环境,比如在开发机上,最简单的办法就是从CPAN直接安装,shell中命令如下:

cpan App::cpanminus
cpanm  Net::INET6Glue::INET_is_INET6
第一个命令会执行比较长时间,需要耐性等待一下,中间还会问你y/n,全部默认。

第二个命令执行后,会显示出同时安装的依赖模块:

Fetching http://www.cpan.org/authors/id/S/SU/SULLR/Net-INET6Glue-0.603.tar.gz ... OK
Configuring Net-INET6Glue-0.603 ... OK
==> Found dependencies: IO::Socket::IP
--> Working on IO::Socket::IP
Fetching http://www.cpan.org/authors/id/P/PE/PEVANS/IO-Socket-IP-0.37.tar.gz ... OK
Configuring IO-Socket-IP-0.37 ... OK
==> Found dependencies: Socket
--> Working on Socket
Fetching http://www.cpan.org/authors/id/P/PE/PEVANS/Socket-2.018.tar.gz ... OK
==> Found dependencies: ExtUtils::Constant
--> Working on ExtUtils::Constant
Fetching http://www.cpan.org/authors/id/N/NW/NWCLARK/ExtUtils-Constant-0.23.tar.gz ... OK
Configuring ExtUtils-Constant-0.16 ... OK
Building and testing ExtUtils-Constant-0.23 ... OK
Successfully installed ExtUtils-Constant-0.23 (upgraded from 0.17)
Configuring Socket-2.018 ... OK
Building and testing Socket-2.018 ... OK
Successfully installed Socket-2.018 (upgraded from 1.78)
Building and testing IO-Socket-IP-0.37 ... OK
Successfully installed IO-Socket-IP-0.37
Building and testing Net-INET6Glue-0.603 ... OK
Successfully installed Net-INET6Glue-0.603
4 distributions installed

在产品中,需要将perl模块做成rpm来安装,搜索了一下找到一个比较方便的工具:cpan2rpm,在CPAN中可以下载。

下来的是tgz包,通过make安装,命令会报这样一个错:

Can't locate object method "interpolate" via package "Pod::Text" at ./cpan2rpm line 519.

原因是Pod::Text中interpolate这个方法已经迁移到Pod::Parser模块中,需要将代码中的Pod::Text替换为Pod::Parser,然后make、make install就OK了。

cpan2rpm安装好以后,就可以将Net::INET6Glue::INET_is_INET6模块以及它的依赖做成rpm了,步骤如下:

1.下载tgz(包括依赖),从上面通过CPAN安装的过程可以看出共有3个依赖,分别是:ExtUtils-Constant、Socket和IO-Socket-IP。以ExtUtils-Constant举例:

wget http://www.cpan.org/authors/id/N/NW/NWCLARK/ExtUtils-Constant-0.23.tar.gz
2.执行cpan2rpm
cpan2rpm --no-sign ./ExtUtils-Constant-0.23.tar.gz
结果显示如下:
-- cpan2rpm - Ver: 2.028 --
Upgrade check
Fetch: HTTP

-- module: ./ExtUtils-Constant-0.23.tar.gz --
Metadata retrieval
...
...
+ umask 022
+ cd /usr/src/redhat/BUILD
+ rm -rf ExtUtils-Constant-0.23
+ exit 0
RPM: /usr/src/redhat/RPMS/noarch/perl-ExtUtils-Constant-0.23-1.noarch.rpm
SRPM: /usr/src/redhat/SRPMS/perl-ExtUtils-Constant-0.23-1.src.rpm
-- Done --

可以看到生成出所需要的rpm和source rpm。

Done!


其实使用cpan2rpm不必先下载tgz包,只要将上面的文件名替换为模块名就可以。

另外,估计cpan2rpm可能已经很久没人维护了,在编译不同rpm时还遇到过下面的问题,一并将补丁发出来。

错误1:

get_meta(): Not a directory at /usr/bin/cpan2rpm line 396.
补丁:

diff -ru cpan2rpm-2.028/cpan2rpm cpan2rpm-new/cpan2rpm
--- cpan2rpm-2.028/cpan2rpm	2005-06-17 22:06:54.000000000 -0700
+++ cpan2rpm-new/cpan2rpm	2005-06-30 09:35:49.000000000 -0700
@@ -26,6 +26,7 @@
 
 use strict;
 use warnings;
+use File::Basename;
 use Getopt::Long;
 use Sys::Hostname;
 use Pod::Text;
@@ -387,6 +388,9 @@
         $info->{buildarch} = "noarch" if $xs == 0;
         }
 
+    if (not -d $info->{evaldir}) {
+        $info->{evaldir} = dirname($info->{evaldir});
+        }
     chdir $info->{evaldir} || die "get_meta(): $!";
 
     $_ = "$info->{evaldir}/Build.PL";

错误2:

/usr/lib/rpm/brp-compress: line 8: cd: /var/tmp/perl-Crypt-Random-Source-0.10-root: No such file or directory
补丁:

801行在destdir前面加上“--”

$info->{"make-install"} = "--destdir=%{buildroot}"









你可能感兴趣的:(cgi,perl,ipv6)