How to connect remotely to Cassandra cluster?

panic: gocql: unable to create session: unable to discover protocol version: dial tcp i/o timeout

Photo by Kevin Ku on Unsplash

This is a quick article on how to set up Cassandra for remote access.

After creating your cluster, keyspace, and table, it’s time now to connect to Cassandra DB.
Locally We can connect to Cassandra using the CQLSH interface. what if any third party application wants to access to our database? that’s when RPC comes in.
RPC stands for Remote Procedure Call.

So let’s configure it.

To configure the Cassandra RPC, navigate and open the cassandra.yaml file with any editor:

> sudo nano /etc/cassandra/cassandra.yaml

find this line

# For security reasons, you should not expose this port to the internet.  Firew$
rpc_address: localhost

Replace localhost by the current host IP where Cassandra is installed, for example 192.168.xx.xx

# For security reasons, you should not expose this port to the internet.  Firew$
rpc_address: Your_IP_Addr

As mentioned this port should not be exposed to the internet or shared with anyone for security reasons.

Now save the file and restart Cassandra

> sudo service cassandra restart

Try to connect from any remote computer


Or use any programming language :
With Go

// main.go
package main
import ("fmt"
)var Session *gocql.Sessionfunc main() {var err errorcluster := gocql.NewCluster("YOUR_IP_ADDR")cluster.Keyspace = "restfulapi"Session, err = cluster.CreateSession()if err != nil {panic(err)}fmt.Println("cassandra well initialized")}> go run main.gocassandra well initialized

Boom, well done!!!!!😁




Tech nerd. South Korea

Love podcasts or audiobooks? Learn on the go with our new app.

An example of a full technology stack for web and mobile application development…

Build your own Video Game using Thunkable!

How to Solve Container with Most Water?

The “i” is for intelligence.

Sorting in Scala — a cat shop example

Codefresh adds native integration for DigitalOcean Kubernetes clusters

My story of how I used Ansible and Terraform for my hobby project, what troubles I had, and how you…

Dear Git: Please remove Pull Request comments!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sinai Nday

Sinai Nday

Tech nerd. South Korea

More from Medium

Binary protection using go embed and plugins

How to configure CircleCI and SonarQube for GoLang Application

Talk about Go: How to custom build a gateway interceptor in Gin framwork