cassandra本地连接失败_如何连接到本地cassandra db

I have a cassandra db running locally. I can see it working in Ops Center. However, when I open dev center and try to connect I get a cryptic "unable to connect" error.

How can I get the exact name / connectionstring that I need to use to connect to this local cassandra db via dev center?

解决方案

The hostname/IP to connect to is specified in the listen_address property of your cassandra.yaml.If you are connecting to Cassandra from your localhost only (a sandbox machine), then you can set the listen_address in your cassandra.yaml accordingly:

listen_address: localhost

When you start Cassandra, you should see lines similar to this either in STDOUT or in your system.log (timestamps removed for brevity):

Starting listening for CQL clients on localhost/127.0.0.1:9042...

Binding thrift service to localhost/127.0.0.1:9160

Listening for thrift clients...

These lines indicate which address you should be using to connect to your cluster. The first way to test your connection, is with clqsh. Note that cqlsh will connect to "localhost" by default. If you are connecting to a host/IP other than localhost, then you will need to specify it on the command line.

$ cqlsh

Connected to Test Cluster at localhost:9042.

[cqlsh 5.0.1 | Cassandra 2.1.0-rc5-SNAPSHOT | CQL spec 3.2.0 | Native protocol v3]

Use HELP for help.

cqlsh>

If this works, then you should also be able to connect (and test) from DataStax Dev Center (also on your local machine) by defining a connection to localhost, like this:

At this point, you should be able to connect via your application code (Java CQL3 driver shown):

cluster = Cluster.builder().addContactPoint("localhost").build();

Metadata metadata = cluster.Metadata;

Console.WriteLine("Connected to cluster: " + metadata.ClusterName.ToString());

Session session = cluster.connect();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值