How to connect Cassandra to localhost using cqlsh?

2020-05-30 03:56发布

I set rpc_port to the public IP address, and now I can connect to Cassandra just fine from an outside server.

However, I cannot connect from the Cassandra server itself, using cqlsh

I am getting an error.Thar are:

 Connection error: Could not connect to localhost:9160

Is there a configuration, I can change to be able to connect from the server itself ?

14条回答
Luminary・发光体
2楼-- · 2020-05-30 04:00

It's not listening on 127.0.0.1 since you told it to only listen on <public IP>. Make the listen address 0.0.0.0 to listen on all addresses (or just omit it if possible as this is usually the default). See Listening Sockets .NET tutorial or any other socket tutorial to get a basic understanding of socket binding.

Update (@c45556037):

Note that listen_address is the one for other nodes to use to connect to this one (a misleading name). rpc_address is the actual address to locally bind to. It's unclear from the 2.0 docs and is explained better in the 1.0 docs.

查看更多
放荡不羁爱自由
3楼-- · 2020-05-30 04:00

I faced same situation while starting cqlsh . I got following error while starting cassandra

Enter only ----cassandra----- in terminal.

it will show all jars and log files . if terminal hang , just escape from it and then enter cqlsh. then it will enter to cassandra cli.

This worked for me

查看更多
趁早两清
4楼-- · 2020-05-30 04:00

Exception connecting to localhost/9160. reason: connection refused

Connection refused to cassandra cli mode .

goto the root directory of cassandra :

bin/cassandra -- host {host-ip} --port {9160}

if you are having trouble with this , check your {cassandra-root-directory}/conf/cassandra.yaml

the thrift ip or rpc_address is the address used as the host-ip for connecting to cli . make it your local IP and if you are having trouble connecting using the port 9160 , try changing the rpc_port to 8070 and now try connecting to cassandra-cli mode using the command

bin/cassandra --host {local-IP} --port 8070

This worked for me, hope it works for you too .

查看更多
欢心
5楼-- · 2020-05-30 04:03

Consider changing /etc/cassandra.yaml:

# Whether to start the thrift rpc server.
start_rpc: false

to

start_rpc: true
查看更多
The star\"
6楼-- · 2020-05-30 04:03

Maybe start cassandra on your local machine by bin/cassandra -f first?

查看更多
Juvenile、少年°
7楼-- · 2020-05-30 04:05

if you see this in cassandra logs:

INFO  [main] 2015-07-21 12:06:27,426 CassandraDaemon.java:406 - Not starting RPC server as requested. Use JMX (StorageService->startRPCServer()) or nodetool (enablethrift) to start it

then just open a terminal and

$ nodetool enablethrift

as written in the INFO message. Should now work. Got this when my system upgraded to cassandra 2.2.0

查看更多
登录 后发表回答