首页 文章

如何使用cqlsh连接到Cassandra(remotehost)

提问于
浏览
10

我不能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">',)})

我使用的是cqlsh 5.0.1和python 2.7.10

./cqlsh --version
     cqlsh 5.0.1
  python -V
    Python 2.7.10

我在Mac上并使用http://www.datastax.com/2012/01/working-with-apache-cassandra-on-mac-os-x的说明下载cassandra .

我本地的Cassandra是2.2.1(据我从zip文件中理解),看起来远程主机上的cassandra不是2.2.1(我假设它是2.0或2.1) . 如果没有明确知道远程主机上的版本是什么,我该如何尝试连接到远程主机上的cassandra

3 回答

  • 3

    1) Make sure the service is running:

    $ 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_cpu_cores = 2 -Ddse.system_memory_in_mb = 2003 -Dcassandra.config.loader = com.datastax.bdp.config .DseConfigurationLoader -Ddse.system_cpu_cores = 2 -Ddse.system_memory_in_mb = 2003 -Dcassandra.config.loader = com.datastax.bdp.config.DseConfigurationLoader -ea -javaagen ...

    2) Make sure you are using the correct IP by checking the server config:

    $ ifconfig

    例:

    eth1链接封装:以太网HWaddr 08:00:27:a6:4e:46
    inet addr:192.168.56.10 Bcast:192.168.56.255掩码:255.255.255.0 inet6地址:fe80 :: a00:27ff:fea6:4e46 / 64范围:Link UP BROADCAST RUNNING MULTICAST MTU:1500公制:1

    3) Ensure you can connect to that IP from the server you are on:

    $ ssh user@xxx.xxx.xx.xx

    4) Check the node's status and also confirm it shows the same IP:

    $ nodetool状态

    5) run the command to connect with the IP (only specify port if you are not using the default):

    $ cqlsh xxx.xxx.xx.xx

  • 10

    您可能需要在mac上放置2.1或2.0中的cqlsh以匹配您尝试连接的服务器 . 这就是我先尝试的 .

  • 2

    我遇到了同样的错误(在Windows 8.1上运行Cassandra 2.2.0),并找到了Gustav Grusell为我工作的解决方法:https://issues.apache.org/jira/browse/CASSANDRA-9467?focusedCommentId=14693410&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14693410

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

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

    将以下行与其他 parser.add_option 语句(〜第175行)一起添加:

    parser.add_option("--protocolversion", default=DEFAULT_PROTOCOL_VERSION, help='Specify protocol version (default: %default).')
    

    def read_options(cmdlineargs, environment): (〜第2520行)下添加以下其他optvalues:

    optvalues.protocolversion =  option_with_default(configs.get, 'cql', 'protocolversion', DEFAULT_PROTOCOL_VERSION)
    

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

    if options.protocolversion:
        try:
            options.protocolversion = int(optvalues.protocolversion)
        except ValueError:
            options.protocolversion=DEFAULT_PROTOCOL_VERSION
    

    修改 def main(options, hostname, port): 中的Shell命令以包含协议版本(〜第2657行):

    connect_timeout=options.connect_timeout,
                      protocol_version=options.protocolversion)
    

    这是我的cqlsh.py现在的样子:http://pastebin.com/f9D2zEE4

相关问题