Reputation: 35
I have a windowns 7 machine, on which I installed Virtual Box, in which I'm running an Ubuntu Virtual Machine.
On that Ubuntu Virtual Machine, I installed cassandra and made it run on the default port 9042. I have configured the port forwarding for virtual Box for that port.
When I try to connect to my cassandra instance using a client inside my VM, it's ok. But if I try to connect to it from my host machine (My actual computer, windows 7), I can't !
When I use tcpdump on my Ubuntu VM, it shows this :
14:22:29.340202 IP 10.0.2.2.63128 > 10.0.2.15.9042: Flags [S], seq 606528001, win 65535, options [mss 1460], length 0
14:22:29.340293 IP 10.0.2.15.9042 > 10.0.2.2.63128: Flags [R.], seq 0, ack 606528002, win 0, length 0
So I suspect the tcp flow [My host machine --> the Ubuntu VM] to be ok, but it seems like the opposite way is not working (the tcp flow Ubuntu VM --> my host machine Windows 7). I also tried to disable the firewall on Windows 7.
Any help on this ?
Upvotes: 2
Views: 3504
Reputation: 6237
This is a repost of my answer from another question
For future reference to myself and others, this worked for me for Cassandra v3.10:
http://grokbase.com/t/cassandra/user/14cpyy7bt8/connect-to-c-instance-inside-virtualbox
Once your Guest VM is provisioned with Cassandra, I had a host only network adapter set with IP 192.168.5.10.
Then had to modify /etc/cassandra/cassandra.yaml
to set:
From
rpc_address: localhost
To
rpc_address: 192.168.5.10
Then run sudo service cassandra restart
and give it 15 seconds...
Then on the guest VM or on the host the following worked:
cqlsh 192.168.5.10
Hope that helps someone.
Note it doesn't work for multiple nodes in a cluster yet
# Adjustable settings
## Cassandra cluster settings
mem_mb = "3000"
cpu_count = "2"
server_count = 1
network = '192.168.5.'
first_ip = 10
servers = []
seeds = []
cassandra_tokens = []
(0..server_count-1).each do |i|
name = 'cassandra-node' + (i + 1).to_s
ip = network + (first_ip + i).to_s
seeds << ip
servers << {'name' => name,
'ip' => ip,
'provision_script' => "sleep 15; sudo sed -i -e 's/^rpc_address: localhost/rpc_address: #{ip}/g' /etc/cassandra/cassandra.yaml; sudo service cassandra restart;",
'initial_token' => 2**127 / server_count * i}
end
# Configure VM server
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/xenial64"
servers.each do |server|
config.vm.define server['name'] do |x|
x.vm.provider :virtualbox do |v|
v.name = server['name']
v.customize ["modifyvm", :id, "--memory", mem_mb]
v.customize ["modifyvm", :id, "--cpus" , cpu_count ]
end
x.vm.network :private_network, ip: server['ip']
x.vm.hostname = server['name']
x.vm.provision "shell", path: "provision.sh"
x.vm.provision "shell", inline: server['provision_script']
end
end
end
# install Java and a few base packages
add-apt-repository ppa:openjdk-r/ppa
apt-get update
apt-get install vim curl zip unzip git python-pip -y -q
# Java install - adjust if needed
# apt-get install openjdk-7-jdk -y -q
apt-get install openjdk-8-jdk -y -q
# Install Cassandra
echo "deb http://www.apache.org/dist/cassandra/debian 310x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
sudo apt-get update
sudo apt-get install cassandra -y
sudo service cassandra start
Upvotes: 3
Reputation: 19
I enabled a Bridged adapter for the ubuntu vm (guest machine that hosts cassandra). inet addr of the guest vm is 192.168.0.6. My host's (macosx) inet addr is 192.168.0.43 and the virtual interface (vboxnet0) was given an inet address of 192.168.56.1 by VirtualBox when I created a new Host-only network through the global preferences (VirtualBox->Preferences->Network->Host-only Networks). I also ensured that the cassandra.yaml file contained the following two properties (besides the 10k others!):
listen_address: 192.168.0.6
rpc_address: 192.168.0.6
With these settings I was able to connect a java client running on my macosx (host) to a cassandra server running on a ubuntu (guest) vm.
Upvotes: 1
Reputation: 657
Assuming you have networking configured properly in VirtualBox, then check:
the cassandra.yaml configuration, the listen_address should be the IP of your VM, so it is available for remote connections.
More info: http://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html
Upvotes: 0