无法使用phpcassa连接到云服务器上的Cassandra [英] Cannot connect to Cassandra on a cloud server using phpcassa

查看:181
本文介绍了无法使用phpcassa连接到云服务器上的Cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个测试云服务器(Rackspace上的Ubuntu 10.10)来与 Cassandra数据库(0.6。 8)。
我可以使用cassandra-cli基本客户端在服务器和云端外部的计算机上连接任何问题:我已经创建并检索了样本数据。



然后,我已经在云服务器和外部计算机上安装了phpcassa。



我创建了一个非常简单的php程序来测试连接:

 <?php 
$ GLOBALS ['THRIFT_ROOT'] = dirname(__ FILE__)。 '/ include / thrift /';
require_once $ GLOBALS ['THRIFT_ROOT']。'/ packs / cassandra / Cassandra.php';
require_once $ GLOBALS ['THRIFT_ROOT']。'/ transport / TSocket.php';
require_once $ GLOBALS ['THRIFT_ROOT']。'/ protocol / TBinaryProtocol.php';
require_once $ GLOBALS ['THRIFT_ROOT']。'/ transport / TFramedTransport.php';
require_once $ GLOBALS ['THRIFT_ROOT']。'/ transport / TBufferedTransport.php';

include_once(dirname(__ FILE__)。'/include/phpcassa.php');
include_once(dirname(__ FILE__)。'/include/uuid.php');

echo'phpcassa test01< br />< br />';
CassandraConn :: add_node('184.106.97.245',9160);

$ users = new CassandraCF('Keyspace1','Standard2');

try {
$ res = $ users-> get('jsmith');
print_r($ res);
} catch(Exception $ e){
print CassandraConn :: $ last_error;
}

echo'End。'
?>

我使用缓冲传输。



我可以愉快地连接和读取服务器内的数据(我也安装了LAMP):

  phpcassa test01 
Array([age] => 42 [first] => John [last] => Smith)
结束。

但不是从外部,因为我总是遇到异常:

  phpcassa test01 
TException:TSocket:无法连接到184.106.97.245:9160(操作超时[60])
结束。

这是我的storage-conf.xml文件:

 < Storage> 
< ClusterName>测试集群< / ClusterName>
< AutoBootstrap> false< / AutoBootstrap>
< HintedHandoffEnabled> true< / HintedHandoffEnabled>
< IndexInterval> 128< / IndexInterval>
< Keyspaces>
< Keyspace Name =Keyspace1>
< ColumnFamily Name =Standard1CompareWith =BytesType
KeysCached =1000
RowsCached =100
RowCacheSavePeriodInSeconds =0
KeyCacheSavePeriodInSeconds = 3600/>
< ColumnFamily Name =Standard2
CompareWith =UTF8Type
KeysCached =100%/>
< ColumnFamily Name =StandardByUUID1CompareWith =TimeUUIDType/>
< ColumnFamily Name =Super1
ColumnType =Super
CompareWith =BytesType
CompareSubcolumnsWith =BytesType/&
< ColumnFamily Name =Super2
ColumnType =Super
CompareWith =UTF8Type
CompareSubcolumnsWith =UTF8Type
RowsCached =10000
KeysCached =50%
注释=具有超列的列族,其列和子列名称为UTF8字符串/>
< ReplicaPlacementStrategy> org.apache.cassandra.locator.RackUnawareStrategy< / ReplicaPlacementStrategy>
< ReplicationFactor> 1< / ReplicationFactor>
< EndPointSnitch> org.apache.cassandra.locator.EndPointSnitch< / EndPointSnitch>
< / Keyspace>
< / Keyspaces>
< Authenticator> org.apache.cassandra.auth.AllowAllAuthenticator< / Authenticator>
< Partitioner> org.apache.cassandra.dht.RandomPartitioner< / Partitioner>
< InitialToken>< / InitialToken>
< SavedCachesDirectory> / var / lib / cassandra / saved_caches< / SavedCachesDirectory>
< CommitLogDirectory> / var / lib / cassandra / commitlog< / CommitLogDirectory>
< DataFileDirectories>
< DataFileDirectory> / var / lib / cassandra / data< / DataFileDirectory>
< / DataFileDirectories>
< Seeds>
< Seed> 184.106.97.245< / Seed>
< / Seeds>
< RpcTimeoutInMillis> 10000< / RpcTimeoutInMillis>
< CommitLogRotationThresholdInMB> 128< / CommitLogRotationThresholdInMB>
< ListenAddress> 184.106.97.245< / ListenAddress>
< StoragePort> 7000< / StoragePort>
< ThriftAddress> 184.106.97.245< / ThriftAddress>
< ThriftPort> 9160< / ThriftPort>
< ThriftFramedTransport> false< / ThriftFramedTransport>
< DiskAccessMode> auto< / DiskAccessMode>
< RowWarningThresholdInMB> 64< / RowWarningThresholdInMB>
< SlicedBufferSizeInKB> 64< / SlicedBufferSizeInKB>
< FlushDataBufferSizeInMB> 32< / FlushDataBufferSizeInMB> $ bl $ b< FlushIndexBufferSizeInMB> 8< / FlushIndexBufferSizeInMB>
< ColumnIndexSizeInKB> 64< / ColumnIndexSizeInKB>
< MemtableThroughputInMB> 64< / MemtableThroughputInMB>
< BinaryMemtableThroughputInMB> 256< / BinaryMemtableThroughputInMB>
< MemtableOperationsInMillions> 0.3< / MemtableOperationsInMillions>
< MemtableFlushAfterMinutes> 60< / MemtableFlushAfterMinutes>
< ConcurrentReads> 8< / ConcurrentReads>
< ConcurrentWrites> 32< / ConcurrentWrites>
< CommitLogSync> periodic< / CommitLogSync>
< CommitLogSyncPeriodInMS> 10000< / CommitLogSyncPeriodInMS>
< GCGraceSeconds> 864000< / GCGraceSeconds>
< DoConsistencyChecksBoolean> true< / DoConsistencyChecksBoolean>
< / Storage>

Rackspace支持建议更改防火墙设置,但我没有防火墙:



root @ Oahu:〜#iptables --list
链接INPUT(策略ACCEPT)
目标prot opt源目标
链接FORWARD(policy ACCEPT)
target prot opt source destination
Chain OUTPUT(policy ACCEPT)
target prot opt source destination

任何帮助非常感谢!!!



Cheers,Rujero

解决方案

使用 http:// wiki访问节点(第一个) .apache.org / cassandra / CassandraCli


I have setup a test cloud server (Ubuntu 10.10 on Rackspace) to play with Cassandra database (0.6.8). I can connect no problem both from within the server and from a computer external to the cloud using the cassandra-cli basic client: I have created and retrieved sample data.

I have then installed phpcassa on the cloud server and on an external computer.

I have created a very simple php program to test the connection:

<?php
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/include/thrift/';
require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/Cassandra.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';

include_once(dirname(__FILE__) . '/include/phpcassa.php');
include_once(dirname(__FILE__) . '/include/uuid.php');

echo 'phpcassa test01<br /><br />';
CassandraConn::add_node('184.106.97.245', 9160);

$users = new CassandraCF('Keyspace1', 'Standard2');

try {
    $res = $users->get('jsmith');
    print_r($res);
} catch (Exception $e) {
    print CassandraConn::$last_error;
}

echo 'End.'
?>

I am using buffered transport.

I can happily connect and read data from within the server (I have also installed LAMP on it):

phpcassa test01
Array ( [age] => 42 [first] => John [last] => Smith ) 
End.

but not from outside because I am always getting the exception:

phpcassa test01
TException: TSocket: Could not connect to 184.106.97.245:9160 (Operation timed out [60])
End.

This is my storage-conf.xml file:

<Storage>
<ClusterName>Test Cluster</ClusterName>
<AutoBootstrap>false</AutoBootstrap>
<HintedHandoffEnabled>true</HintedHandoffEnabled>
<IndexInterval>128</IndexInterval>
<Keyspaces>
<Keyspace Name="Keyspace1">
  <ColumnFamily Name="Standard1" CompareWith="BytesType"
                KeysCached="1000"
                RowsCached="100"
                RowCacheSavePeriodInSeconds="0"
                KeyCacheSavePeriodInSeconds="3600"/>
  <ColumnFamily Name="Standard2" 
                CompareWith="UTF8Type"
                KeysCached="100%"/>
  <ColumnFamily Name="StandardByUUID1" CompareWith="TimeUUIDType" />
  <ColumnFamily Name="Super1"
                ColumnType="Super"
                CompareWith="BytesType"
                CompareSubcolumnsWith="BytesType" />
  <ColumnFamily Name="Super2"
                ColumnType="Super"
                CompareWith="UTF8Type"
                CompareSubcolumnsWith="UTF8Type"
                RowsCached="10000"
                KeysCached="50%"
                Comment="A column family with supercolumns, whose column and subcolumn names are UTF8 strings"/>
  <ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
  <ReplicationFactor>1</ReplicationFactor>
  <EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>        
</Keyspace>
</Keyspaces>
<Authenticator>org.apache.cassandra.auth.AllowAllAuthenticator</Authenticator>  
<Partitioner>org.apache.cassandra.dht.RandomPartitioner</Partitioner>
<InitialToken></InitialToken>
<SavedCachesDirectory>/var/lib/cassandra/saved_caches</SavedCachesDirectory>
<CommitLogDirectory>/var/lib/cassandra/commitlog</CommitLogDirectory>
<DataFileDirectories>
  <DataFileDirectory>/var/lib/cassandra/data</DataFileDirectory>
</DataFileDirectories>
<Seeds>
  <Seed>184.106.97.245</Seed>
</Seeds>
<RpcTimeoutInMillis>10000</RpcTimeoutInMillis>
<CommitLogRotationThresholdInMB>128</CommitLogRotationThresholdInMB>
<ListenAddress>184.106.97.245</ListenAddress>
<StoragePort>7000</StoragePort>
<ThriftAddress>184.106.97.245</ThriftAddress>
<ThriftPort>9160</ThriftPort>
<ThriftFramedTransport>false</ThriftFramedTransport>
<DiskAccessMode>auto</DiskAccessMode>
<RowWarningThresholdInMB>64</RowWarningThresholdInMB>
<SlicedBufferSizeInKB>64</SlicedBufferSizeInKB>
<FlushDataBufferSizeInMB>32</FlushDataBufferSizeInMB>
<FlushIndexBufferSizeInMB>8</FlushIndexBufferSizeInMB>
<ColumnIndexSizeInKB>64</ColumnIndexSizeInKB>
<MemtableThroughputInMB>64</MemtableThroughputInMB>
<BinaryMemtableThroughputInMB>256</BinaryMemtableThroughputInMB>
<MemtableOperationsInMillions>0.3</MemtableOperationsInMillions>
<MemtableFlushAfterMinutes>60</MemtableFlushAfterMinutes>
<ConcurrentReads>8</ConcurrentReads>
<ConcurrentWrites>32</ConcurrentWrites>
<CommitLogSync>periodic</CommitLogSync>
<CommitLogSyncPeriodInMS>10000</CommitLogSyncPeriodInMS>
<GCGraceSeconds>864000</GCGraceSeconds>
<DoConsistencyChecksBoolean>true</DoConsistencyChecksBoolean>
</Storage>

Rackspace support suggested changing the firewall settings but I have no firewall:

root@Oahu:~# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Any help very much appreciated!!!

Cheers, Rujero

解决方案

Access the node (first) with http://wiki.apache.org/cassandra/CassandraCli

这篇关于无法使用phpcassa连接到云服务器上的Cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆