如何使用cqlsh连接到Cassandra(远程主机)

如何使用cqlsh连接到Cassandra(远程主机),cassandra,cqlsh,Cassandra,Cqlsh,我无法将cqlsh发送到远程主机 ./cqlsh xx.xx.x.xxx 9042 Connection error: ('Unable to connect to any servers', {'10.101.33.163': ConnectionException(u'Did not get expected SupportedMessage response; instead, got: <ErrorMessage code=0000 [Server er

我无法将cqlsh发送到远程主机

 ./cqlsh xx.xx.x.xxx 9042
   Connection error: ('Unable to connect to any servers', {'10.101.33.163':   
   ConnectionException(u'Did not get expected SupportedMessage response; 
   instead, got: <ErrorMessage code=0000 [Server error]      
   message="io.netty.handler.codec.DecoderException: 
   org.apache.cassandra.transport.ProtocolException: Invalid or unsupported 
   protocol version: 4">',)})
我在mac电脑上,使用中的说明下载cassandra

我的本地计算机上的Cassandra是2.2.1(正如我从zip文件中了解的),远程主机上的Cassandra似乎不是2.2.1(我假设它是2.0或2.1)。在不明确知道远程主机上的版本的情况下,如何尝试连接到远程主机上的cassandra

1)确保服务正在运行:

 ./cqlsh xx.xx.x.xxx 9042
   Connection error: ('Unable to connect to any servers', {'10.101.33.163':   
   ConnectionException(u'Did not get expected SupportedMessage response; 
   instead, got: <ErrorMessage code=0000 [Server error]      
   message="io.netty.handler.codec.DecoderException: 
   org.apache.cassandra.transport.ProtocolException: Invalid or unsupported 
   protocol version: 4">',)})
$ps aux | grep cassandra

例如: 106 7387 5.1 70.9 2019816 1454636 ? SLl Sep02 16:39/usr/lib/jvm/java-7-oracle/jre//bin/java-Ddse.system\u cpu\u cores=2-Ddse.system\u memory\u in_mb=2003-Dcassandra.config.loader=com.datastax.bdp.config.DseConfigurationLoader-Ddse.system\u cpu\u cores=2-Ddse.system\u memory\u in_in_mb=2003-Dcassandra.config.loader=com.datastax.bdp.config.DseConfigurationLoader-ea-javagen

2)通过检查服务器配置确保使用了正确的IP:

$ifconfig

例如:

eth1链路封装:以太网HWaddr 08:00:27:a6:4e:46
inet地址:192.168.56.10Bcast:192.168.56.255掩码:255.255.255.0 inet6地址:fe80::a00:27ff:fea6:4e46/64范围:链接 上行广播运行多播MTU:1500度量:1

3)确保您可以从您所在的服务器连接到该IP:

$sshuser@xxx.xxx.xx.xx

4)检查节点的状态并确认其显示相同的IP:

$nodetool状态

5)运行命令以连接IP(仅在不使用默认端口时指定端口):


$cqlsh xxx.xxx.xx.xx

您可能需要在mac上安装2.1或2.0版本的cqlsh,以匹配您尝试连接的服务器。这就是我首先要尝试的。

我遇到了同样的错误(在Windows 8.1上运行Cassandra 2.2.0),并找到了Gustav Grusell为我提供的解决方案:

他介绍的解决方法是修改cqlsh.py脚本以接受协议版本。进行这些更改后,您将能够通过将
--protocolversion=3
传递给cqlsh来指定协议版本3(例如)

在您的Cassandra bin文件夹中找到
cqlsh.py
,并在进行这些更改之前对其进行备份

在另一个
解析器旁边添加以下行。添加选项
语句(~第175行):

def read_options(cmdlineargs,environment)下的其他optvalue旁边添加以下内容:
(~line 2520):

def read_options(cmdlineargs,environment)中的return语句之前添加以下内容:
(~line 2574)

修改def main(选项、主机名、端口)中的Shell命令:
以包含协议版本(~第2657行):


下面是我的cqlsh.py现在的样子:

看起来像这样-简单明了。为我工作!你能区分我们可以在哪个服务器上运行哪个命令吗。试图实现同样的目标。从一台服务器连接到安装cassabdra single cluster的另一台服务器'
parser.add_option("--protocolversion", default=DEFAULT_PROTOCOL_VERSION, help='Specify protocol version (default: %default).')
optvalues.protocolversion =  option_with_default(configs.get, 'cql', 'protocolversion', DEFAULT_PROTOCOL_VERSION)
if options.protocolversion:
    try:
        options.protocolversion = int(optvalues.protocolversion)
    except ValueError:
        options.protocolversion=DEFAULT_PROTOCOL_VERSION
                  connect_timeout=options.connect_timeout,
                  protocol_version=options.protocolversion)