我正在尝试使用Hypertable在 Perl 中开发 Web 应用程序。示例代码:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use CGI::Session ('-ip_match');
use Hypertable::ThriftClient;
use Data::Dumper;
my $q = new CGI;
print $q->header(-cache_control => "no-cache, no-store, must-revalidate");
eval {
my $client = new Hypertable::ThriftClient("localhost", 38080);
my $namespace = $client->open_namespace("glinpe");
my $result = $client->hql_exec($namespace, "select * from words where row=\"maths\" keys_only");
};
if ($@) {
if ($@->isa('Thrift::TException')) {
print Dumper($@);
} else {
print Dumper($@);
}
}
print "<h1>works</h1>";
问题是尝试从 Web 浏览器执行时出现错误:
$VAR1 = bless( { 'code' => 0, 'message' => 'TSocket: Could not connect to localhost:38080 (Permission denied)' }, 'Thrift::TException' );
当从终端(在 apache 用户下)运行时,脚本可以正常工作,如果删除所有 Hypertable 代码,也可以在浏览器中正常工作。
我在 iptables 中打开了 38080 端口:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 38080 -j ACCEPT
操作系统:Centos 5.6。