如何使用 cqlsh 连接到 Cassandra(远程主机)
How to connect to Cassandra(remotehost) using 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 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
1) 确保服务是 运行ning:
$ ps 辅助 | grep 卡桑德拉
示例:
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) 通过检查服务器配置确保您使用的 IP 正确:
$ifconfig
示例:
eth1 Link encap:Ethernet HWaddr 08:00:27:a6:4e:46
inet addr:192.168.56.10 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 地址:fe80::a00:27ff:fea6:4e46/64 Scope:Link
向上广播 运行 多播 MTU:1500 Metric:1
3) 确保您可以从您所在的服务器连接到该 IP:
$ ssh 用户@xxx.xxx.xx.xx
4) 检查节点的状态并确认它显示相同的 IP:
$nodetool 状态
5) 运行连接IP的命令(不使用默认端口只需要指定端口):
$ cqlsh xxx.xxx.xx.xx
您可能需要将来自 2.1 或 2.0 的 cqlsh 放在 mac 上以匹配您尝试连接的服务器。所以这就是我首先要尝试的。
我遇到了同样的错误(运行 Cassandra 2.2.0 on Windows 8.1),并找到了 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):
下的其他 optvalues 旁边添加以下内容(~第 2520 行):
optvalues.protocolversion = option_with_default(configs.get, 'cql', 'protocolversion', DEFAULT_PROTOCOL_VERSION)
在 def read_options(cmdlineargs, environment):
中的 return 语句之前添加以下内容(~第 2574 行)
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
我无法 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
1) 确保服务是 运行ning:
$ ps 辅助 | grep 卡桑德拉
示例: 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) 通过检查服务器配置确保您使用的 IP 正确:
$ifconfig
示例:
eth1 Link encap:Ethernet HWaddr 08:00:27:a6:4e:46
inet addr:192.168.56.10 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 地址:fe80::a00:27ff:fea6:4e46/64 Scope:Link
向上广播 运行 多播 MTU:1500 Metric:1
3) 确保您可以从您所在的服务器连接到该 IP:
$ ssh 用户@xxx.xxx.xx.xx
4) 检查节点的状态并确认它显示相同的 IP:
$nodetool 状态
5) 运行连接IP的命令(不使用默认端口只需要指定端口):
$ cqlsh xxx.xxx.xx.xx
您可能需要将来自 2.1 或 2.0 的 cqlsh 放在 mac 上以匹配您尝试连接的服务器。所以这就是我首先要尝试的。
我遇到了同样的错误(运行 Cassandra 2.2.0 on Windows 8.1),并找到了 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):
下的其他 optvalues 旁边添加以下内容(~第 2520 行):
optvalues.protocolversion = option_with_default(configs.get, 'cql', 'protocolversion', DEFAULT_PROTOCOL_VERSION)
在 def read_options(cmdlineargs, environment):
中的 return 语句之前添加以下内容(~第 2574 行)
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