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
OS:Centos5.6。