无法在vagrant上实现对Cassandra的远程访问

3
我是使用vagrant/puppet来配置一个带有Apache Cassandra的虚拟机。本地访问(通过cqlsh)可以正常工作,但远程访问无法实现。
以下是我的Vagrantfile。
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = 'ubuntu/trusty32'

  config.vm.define "dev" do |dev|
    dev.vm.hostname = "devbox"
    dev.vm.network :private_network, ip: "192.168.10.200"
  end

  config.vm.provision "puppet" do |puppet|
    puppet.module_path = "puppet/modules"
    puppet.manifests_path = "puppet/manifests"
    puppet.manifest_file = "default.pp"
  end

  config.vm.provider "virtualbox" do |v|
    v.memory = 4096
    v.cpus = 2
  end

  config.ssh.forward_agent = true

end

我可以展示我的木偶文件,但我认为分享它生成的cassandra.yaml会更容易/清晰。

https://gist.github.com/theonlylawislove/de34477b2cb34f106fa4

在盒子上...

vagrant@devbox:~$ cqlsh
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")})
vagrant@devbox:~$ cqlsh 192.168.10.200
Connected to Test Cluster at 192.168.10.200:9042.
[cqlsh 5.0.1 | Cassandra 2.2.0 | CQL spec 3.3.0 | Native protocol v4]
Use HELP for help.
cqlsh>

从我的主机(Windows)可以ping虚拟机。

Pinging 192.168.10.200 with 32 bytes of data:
Reply from 192.168.10.200: bytes=32 time<1ms TTL=128
Reply from 192.168.10.200: bytes=32 time<1ms TTL=128
Reply from 192.168.10.200: bytes=32 time<1ms TTL=128
Reply from 192.168.10.200: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.10.200:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

但是,当我尝试使用以下代码在我的.NET项目中(在主机上)访问这个Cassandra实例时...

var cluster = Cluster.Builder().AddContactPoint("192.168.10.200").Build();
var session = cluster.Connect("test");

我得到了这个异常。

An exception of type 'Cassandra.NoHostAvailableException' occurred in Cassandra.dll but was not handled in user code

Additional information: None of the hosts tried for query are available (tried: 192.168.10.200:9042)

发生了什么事?

更新

我从头开始创建了一个空的vagrant虚拟机(没有配置),并手动安装了Cassandra。同样的问题仍然存在。但是,当我从“private_network”切换到使用桥接/DHCP的“public_network”时,它可以工作。

我想说的是,“private_network”端口可能没有打开,但是我已经安装了其他服务(如RabbitMQ/Postgres),它们可以正常工作。那么,为什么Cassandra不能在“private_network”上工作呢?


你是否打开了Cassandra的端口? config.vm.network "forwarded_port", guest: 9042, host: 9042, auto_correct: true - jonnybazookatone
@jonnybazookatone,我试过了,还是不行。我的理解是端口转发只是为了让我通过“localhost:virtualport”访问主机上的虚拟机端口,对吗? - Paul Knopf
是的,你说得对,抱歉,我没有仔细阅读你的帖子;x。即使如此,在将端口转发到本地主机时,如果执行相同操作,您仍会收到相同的错误吗? - jonnybazookatone
我尝试访问Thrift端口(9160)时遇到了相同的问题。 - Emil D
遇到完全相同的问题。自从切换到“public_network”后,您能否发布Vagrantfile的相关部分? - Nick
显示剩余2条评论
1个回答

0

确保你的 Vagrantfile 使用了 private_network,例如:

config.vm.network "private_network", ip: "192.168.33.10"

请注意,当您使用vagrant ssh命令时,会在提示符之前显示一些信息,其中包括:
IP address for eth1: 192.168.33.10

编辑您的/etc/cassandra/cassandra.yml文件(约482/483行)如下:

# rpc_address: localhost
rpc_interface: eth1

即注释掉rpc_address,并改为指定由vagrant给出的rpc_interface,然后:

sudo service cassandra restart

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接