Reputation: 181
Hello I am trying to set up a three node Cassandra Cluster on Azure linux VMs and connect to it from an external machine using the C# datastax client. However I am having trouble connecting via a VMs public IP from outside the network. Any help would be greatly appreciated as I am about lost now.
Here is the Java Version the machines are running.
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-0ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
My cassandra version is
3.11.3
When I run the nodetool status I can see the machines on the cluster however it is shown the local ip addresses on the Azure VNetwork not their public IP addresses. I am unsure if this is correct?
Datacenter: dc1europe
=====================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
DN 10.1.0.7 101.37 KiB 256 32.8% 617d3f87-cb04-4c29-9e0c-e2c712487ad5 rack1europe
UN 10.1.0.6 158.26 KiB 256 33.1% b79a1aa0-a049-46f2-8efc-679d10a097e2 rack1europe
DN 10.1.0.9 101.36 KiB 256 34.2% 58a101e5-51f2-491e-833f-cc5c49a8740a rack1europe
I can use cqlsh Internal IP Address
to connect to any of the machines but when I use the cqlsh Public IP Address
I get the following error:
Connection error: ('Unable to connect to any servers', {'XX.XXX.XXX.XXX': error(None, "Tried connecting to [('XX.XXX.XXX.XXX', 9042)]. Last error: timed out")})
When I run netstat -vatn
it shows me that my machine is in fact listening on port 9042 but again I am unsure if this is correct:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:9042 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 10.1.0.6:7000 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:42271 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:7199 0.0.0.0:* LISTEN
tcp 0 64 10.1.0.6:22 109.76.85.23:51728 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
I can telnet using the public IP address of the machine I am currently logged into on the cluster but when I try to telnet using the public IP address of another machine on the cluster I get the following:
Trying XX.XXX.XXX.XXX...
But a connection is never established.
Here are the relevant settings from my cassandra.yaml file which I have edited for all three nodes on the cluster
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "10.1.0.6, 10.1.0.7"
listen_address:
# broadcast_address: 1.2.3.4
start_rpc: false
rpc_address: 0.0.0.0
broadcast_rpc_address: <PUBLIC IP OF CURRENT NODE>
I have edited the NSG in azure to allow all the required inbound ports including 7000, 7001, 7199, 9042, 9160, 9142 so this should not be a problem.
I'm unsure whether the problem is with my Azure VM/Network configuration or my Cassandra Setup. Any pointers or help would be great!
Thanks.
Upvotes: 1
Views: 1531
Reputation: 338
My setup.
Windows VM as Webserver
Ubuntu as Cassandra node.
Both in same subscription and different resource group and VNETs.
For connection from Windows machine to Cassandra.
Followed these steps and it worked :)
1) Peer VNet. This has to be done on both vnets. Initially I was not able to ping Ubuntu VM from Windows VM, after peering I was able to ping.
2) Open port 9042 on Cassandra VM you can add restriction for address range of Webserver.
3) In Ubuntu VM edit etc/cassandra/cassandra.yaml and change following settings. IP is private ip address of Ubuntu VM
1) rpc_address: 10.0.1.5
2) listen_address: 10.0.1.5
3) seeds: "10.0.1.5"
4) Now try any test application to connect to cassandra from Webserver.
e.g
var cluster = Cluster.Builder()
.AddContactPoints("10.0.1.5")
.WithPort(9042)
.WithAuthProvider(new PlainTextAuthProvider("cassandra", "cassandra"))
.Build();
ISession session = cluster.Connect();
You should be able connect and run statements.
Cheers,
Hemant
Upvotes: 2
Reputation: 1706
From you description, it sounds like Nat Forwarding/Endpoint. I assume its a classic deployment so below is information to look at Endpoints.
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/classic/setup-endpoints
Upvotes: 1