praveen.upadhyay
praveen.upadhyay

Reputation: 273

Not able to connect to Cassandra from remote host

My subject line might say that it is a duplicated question but is it not. I have tried all the possible way of searching about this issue but failed to resolve my problem.

I have Windows 8.1 running on my PC. I have installed Ubuntu 16.04 version as a VM by using Hyper-V on it. I have installed Cassandra 3.7 on my Ubuntu system.

Cassandra was been able to connect from the localhost i.e. from the Ubuntu system. I created the keyspace and all, but when I am trying to connect Casandra from my golang code as below, I am getting error.

package main

import (
    "fmt"
    "log"

    "github.com/gocql/gocql"
)

func main() {
    // connect to the cluster
    cluster := gocql.NewCluster("192.168.137.217") //Put comma separated IPs in case of multiple cluster
    cluster.Keyspace = "broker_keyspace"
    cluster.Consistency = gocql.Quorum
    session, _ := cluster.CreateSession()
    defer session.Close()
}

192.168.137.217 is my VM's IP address. Error which I am getting is saying that 9042 port is not allowed to connect. This code I am trying to run from my Windows 8.1 system (which is host for the VM where Cassandra is running). I did try to telnet and found that 9042 port is not open host to connect.

I started playing with cassandra.yaml config file, but now it is not even working on Ubuntu system. I am not able to get the node status using

nodetool status

The common config I am having in my cassandra.yaml file is as below.

rpc_address: localhost
listen_address: localhost

I did also uncommented the below line in /etc/cassandra/cassandra-env.sh file and updated the public name to 127.0.0.1.

# add this if you're having trouble connecting:
JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=127.0.0.1"

I restarted the cassandra using service cassandra restart, but when I am trying nodetool status it is giving below error.

nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused'.

Sorry for the long question, but please help I am really fed up with the problem, trying very hard from last 6-7 hours.

Thanks..

Upvotes: 1

Views: 1222

Answers (2)

Mohd Arshil
Mohd Arshil

Reputation: 305

You can follow the following steps to solve the mentioned problems.

Change the following parameters in cassandra.yaml (etc/cassandra/cassandra.yaml)

- start_rpc: true
- rpc_address: 0.0.0.0

And uncomment

broadcast_rpc_address: 1.2.3.4

Upvotes: 0

Johnny Miller
Johnny Miller

Reputation: 91

Have you tried not using localhost and actually using the 192.168.137.217 address for everything - JMX, rpc, listen etc..? Would that be a problem? Also, assuming this is just a dev VM on your PC - maybe check that the firewall is off?

Upvotes: 1

Related Questions