我是使用vagrant/puppet来配置一个带有Apache Cassandra的虚拟机。本地访问(通过cqlsh)可以正常工作,但远程访问无法实现。
以下是我的Vagrantfile。
我可以展示我的木偶文件,但我认为分享它生成的cassandra.yaml会更容易/清晰。
以下是我的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”上工作呢?
config.vm.network "forwarded_port", guest: 9042, host: 9042, auto_correct: true
- jonnybazookatone