How to connect to Cassandra(remotehost) using cqlsh - cassandra

I cannot cqlsh to remote host
./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">',)})
I am using cqlsh 5.0.1 and python 2.7.10
./cqlsh --version
cqlsh 5.0.1
python -V
Python 2.7.10
I am on mac and used the instructions from http://www.datastax.com/2012/01/working-with-apache-cassandra-on-mac-os-x to download cassandra.
Cassandra on my local is 2.2.1(as I understand from the zip file) and it appears like cassandra on remote host is NOT 2.2.1 (I assume it is either 2.0 or 2.1). Without definitively knowing what the version is on remote host, how can I try to connect to cassandra on remote host

1) Make sure the service is running:
$ ps aux | grep cassandra
Example:
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
Example:
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 addr: fe80::a00:27ff:fea6:4e46/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric: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 status
5) run the command to connect with the IP (only specify port if you are not using the default):
$ cqlsh xxx.xxx.xx.xx

You might need to put cqlsh from 2.1 or 2.0 on your mac to match the server you are trying to connect to. So that's what I'd try first.

I was experiencing the same error (running Cassandra 2.2.0 on Windows 8.1), and found a workaround by Gustav Grusell that worked for me: https://issues.apache.org/jira/browse/CASSANDRA-9467?focusedCommentId=14693410&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14693410
The workaround he presents is to modify your cqlsh.py script to accept a protocol version. After making these changes, you will be able to specify protocol version 3 (for example) by passing --protocolversion=3 to cqlsh.
Locate cqlsh.py in your Cassandra bin folder and back it up before making these changes.
Add the following line alongside the other parser.add_option statements (~line 175):
parser.add_option("--protocolversion", default=DEFAULT_PROTOCOL_VERSION, help='Specify protocol version (default: %default).')
Add the following alongside the other optvalues under def read_options(cmdlineargs, environment): (~line 2520):
optvalues.protocolversion = option_with_default(configs.get, 'cql', 'protocolversion', DEFAULT_PROTOCOL_VERSION)
Add the following before the return statement in def read_options(cmdlineargs, environment): (~line 2574)
if options.protocolversion:
try:
options.protocolversion = int(optvalues.protocolversion)
except ValueError:
options.protocolversion=DEFAULT_PROTOCOL_VERSION
Modify the Shell command in def main(options, hostname, port): to include the protocol version (~line 2657):
connect_timeout=options.connect_timeout,
protocol_version=options.protocolversion)
Here's what my cqlsh.py now looks like: http://pastebin.com/f9D2zEE4

Related

Not able to run Cassandra locally using brew

I am trying to run Cassandra on my machine. Tying cqlsh gives me this error,
Connection error: ('Unable to connect to any servers', {'127.0.0.1:9042': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
Running cassandra -f hangs.
I installed cassandra using brew install cassandra.
Also I have done all of the followings:
Killed docker instance
Uninstall and reinstall Cassandra (deleted all the Cassandra data and filles from my machine)
Restarted my machine
Purged docker data
I don't know why still I am running into this. Running brew services list shows:
Name Status User Plist
cassandra started aanish /Users/aanish/Library/LaunchAgents/homebrew.mxcl.cassandra.plist
mysql stopped
mysql#5.7 started aanish /Users/aanish/Library/LaunchAgents/homebrew.mxcl.mysql#5.7.plist
postgresql stopped
The cqlsh connection error indicates that localhost is not listening on port 9042 (Cassandra's CQL client port). The most likely reason is that the Cassandra process is not running.
You can confirm whether the Java process is listening on port 9042 if you run the following command in a terminal:
$ sudo lsof -nPi -sTCP:LISTEN
You will need to review the system.log (typically in /var/log/cassandra) to figure out what is going on with Cassandra.
Note that if you set rpc_address in cassandra.yaml to the IP of your mac, you need to specify that address when you connect with cqlsh. For example:
$ cqlsh 10.1.2.3

Connecting to cqlsh from remote fails, where as from localhost it connects?

Installed DSE on CentOS7 and saw no errors, I'm able to connect to cqlsh from the local machine and and I'm able to also do a telnet on the port.
However the problem is that when the same is done from a remote machine I get the below error
cqlsh XX.XXX.XX.XX 3389
Connection error: ('Unable to connect to any servers', {'10.223.61.49': ConnectionShutdown('Connection to 10.223.61.49 was closed',)})
To check the connectivity I did a telnet on this and see the below error
telnet XX.XXX.XX.XX 3389
Invalid or unsupported protocol version (13); supported versions are (3/v3, 4/v4, 5/v5-beta, 65/dse-v1)
I tried updating the Python version, also few tweaks to change the py script also didn't help

Cassandra Cqlsh is not working

I've just started working with Cassandra (homebrew install), version 3.7 and cqlsh version 5.0.1. , OS X El Capitan
Cassandra starts up fine and the cluster is operational instantly.
Cqlsh is not working (on any of the nodes) and emits the following error:
Connection error: ('Unable to connect to any servers', {'127.0.0.1':
error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error:
Connection refused")})
Edit cqlsh and change DEFAULT_HOST = IP and then run cqlsh.
I think the first step you should be doing is running netstat -ntpl. This should list down all the ports active on the system. Check for Local Address there you shall find a IP prepended with 9042.
Use this IP to connect ie cqlsh IP . If you do not find the 9042 port in the netstat output than check your cassandra.yaml file. Grep for native_transport_port see if it is 9042 or something different.
If different than connect on that port via cqlsh.
For future reference, if someone else gets it.
I'm running [cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4].
Add start_native_transport: true field in cassandra.yaml file, by default it doesn't enables it and so no rpc communication with client.
Now try connecting with cqlsh rpc_endpoint(rpc addr set in cassandra.yaml).

How to configure cassandra for remote connection

I am trying to configure Cassandra Datastax Community Edition for remote connection on windows,
Cassandra Server is installed on a Windows 7 PC, With the local CQLSH it connects perfectly to the local server.
But when i try to connect with CQLSH from another PC in the same Network, i get this error message:
Connection error: ('Unable to connect to any servers', {'MYHOST':
error(10061, "Tried connecting to [('HOST_IP', 9042)]. Last error: No
connection could be made because the target machine actively refused
it")})
So i am wondering how to configure correctly (what changes should i make on cassandra.yaml config file) the Cassandra server to allow remote connections.
Thank you in advance!
How about this:
Make these changes in the cassandra.yaml config file:
start_rpc: true
rpc_address: 0.0.0.0
broadcast_rpc_address: [node-ip]
listen_address: [node-ip]
seed_provider:
- class_name: ...
- seeds: "[node-ip]"
reference: https://gist.github.com/andykuszyk/7644f334586e8ce29eaf8b93ec6418c4
Remote access to Cassandra is via its thrift port for Cassandra 2.0. In Cassandra 2.0.x, the default cqlsh listen port is 9160 which is defined in cassandra.yaml by the rpc_port parameter. By default, Cassandra 2.0.x and earlier enables Thrift by configuring start_rpc to true in the cassandra.yaml file.
In Cassandra 2.1, the cqlsh utility uses the native protocol. In Cassandra 2.1, which uses the Datastax python driver, the default cqlsh listen port is 9042.
The cassandra node should be bound to the IP address of your server's network card - it shouldn't be 127.0.0.1 or localhost which is the loopback interface's IP, binding to this will prevent direct remote access. To configure the bound address, use the rpc_address parameter in cassandra.yaml. Setting this to 0.0.0.0 will listen on all network interfaces.
Have you checked that the remote machine can connect to the Cassandra node? Is there a firewall between the machines? You can try these steps to test this out:
1) Ensure you can connect to that IP from the server you are on:
$ ssh user#xxx.xxx.xx.xx
2) Check the node's status and also confirm it shows the same IP:
$nodetool status
3) Run the command to connect with the IP (only specify the port if you are not using the default):
$ cqlsh xxx.xxx.xx.xx
Alternate solution to Kat. Worked with Ubuntu 16.04
ssh into server server_user#**.**.**.**
Stop cassandra if running:
Check if running with ps aux | grep cassandra
If running, will output a large block of commands / flags, e.g.
ubuntu 14018 4.6 70.1 2335692 712080 pts/2 Sl+ 04:15 0:11 java -Xloggc:./../logs/gc.log ........
Note 14018 in the example is the process id
Stop with kill <process_id> (in this case 14018)
edit cassandra.yaml file to be the following
rpc_address: 0.0.0.0
broadcast_rpc_address: **.**.**.** <- your server's IP (cannot be set to 0.0.0.0)
Restart cassandra ./bin/cassandra -f (from within cassandra root)
Open another terminal on local machine & connect via cqlsh **.**.**.** (your server's IP) to test.
The ./bin/nodetool status address reported my localhost IP (127.0.0.1), but cqlsh remotely still worked despite that.

Unable to Connect to any Servers Error on Cassandra Seed Host

In my Cassandra 3-node setup, all the seed nodes are working fine. However, I am unable to connect to the seed host.
I get the following error:
Connection error: ('Unable to connect to any servers', {'127.0.0.1':
error(111,"Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
Please help.
NOTE: As you haven't specified which version of Cassandra you are running, or how you are attempting to connect to your cluster (cqlsh, Java client driver, etc...) I am going to make some assumptions here. For the future, that's good information to provide.
My guess is that if you were to run a nodetool status from one of your nodes, that you wouldn't see "127.0.0.1" in the list. Example:
$ nodetool status | grep 192.168 | awk '{ print $2 }'
192.168.1.1
192.168.1.2
192.168.1.3
My point, is that even if I am on 192.168.1.1, cqlsh 127.0.0.1 or cqlsh (without the IP) won't work. I need to specify the (non-localhost) IP address, which is probably going to be the value of your listen_address or rpc_address.

Resources