Can't get Cassandra remote access on vagrant

≯℡__Kan透↙ 提交于 2019-12-12 13:17:47

问题


I am using vagrant/puppet to configure a VM with Apache Cassandra. Local access (via cqlsh) works, but not remote access.

Here is my 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

I could show you my puppet file, but I think it would be easier/clearer to share the cassandra.yaml it generated.

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

On the box...

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>

From my host machine (Windows), I can ping the virtual.

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

But when I try to access this Cassandra instance in my .NET project (on host) using the following code...

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

..I get this exception.

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)

What gives?

UPDATE

I started over from scratch, creating an empty vagrant vm (no provisioning) and manually installed Cassandra. The same thing is happening. However, when I switched from a "private_network" to a "public_network" with bridged/DHCP, it worked.

I want to say that the ports aren't open with "private_network", but I have installed other services (RabbitMQ/Postgres) and they work with out an issue. So, why is Cassandra not working with the "private_network"?


回答1:


Make sure your Vagrantfile is using private_network, as in:

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

Notice that when you use vagrant ssh you are shown some info prior the prompt which includes:

IP address for eth1: 192.168.33.10

Edit your /etc/cassandra/cassandra.yml file (lines ~482/483) to be:

# rpc_address: localhost
rpc_interface: eth1

i.e. comment out the rpc_address and instead specify the rpc_interface as given by vagrant, then:

sudo service cassandra restart


来源:https://stackoverflow.com/questions/31907092/cant-get-cassandra-remote-access-on-vagrant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!