简体   繁体   English

EC2中的Cassandra群集通过私有IP与自身通信。 我该如何与外界沟通?

[英]Cassandra cluster in EC2 communicates to itself over private IP. How do I communicate with it from the outside?

I've got a three machine cluster hosted in AWS. 我在AWS中托管了一个三机集群。

  • Each machine has its listen address defined as its local IP. 每台机器的侦听地址均定义为其本地IP。
  • Each machine has it's broadcast address listed as its local IP. 每台机器的广播地址都列为本地IP。
  • Each machine has its RPC address listed as its local IP. 每台计算机都有其RPC地址作为其本地IP列出。
  • Each machine has it's "seeds" property set as a list of the three local IPs. 每台计算机都将其“种子”属性设置为三个本地IP的列表。

The cluster starts up correctly and it communicates with itself just fine. 集群可以正确启动,并且可以与自身正常通信。 When I use Spring Data to connect to this cluster I set the contactPoints property as a list of the three pubic IP addresses of the nodes. 当我使用Spring Data连接到该集群时,我将contactPoints属性设置为节点的三个公共IP地址的列表。 I can successfully connect to one node however the Cassandra Java Driver throws exceptions about trying to connect to the other two nodes via their private IPs. 我可以成功连接到一个节点,但是Cassandra Java驱动程序引发了有关尝试通过其私有IP连接到其他两个节点的异常。 I suspect that that node is giving the driver internal IPs to use instead of the public IPs I gave it via contactPoints. 我怀疑该节点为驱动程序提供了内部IP而不是我通过contactPoints提供给它的公共IP。

  1. My first guess was to change the RPC address of each one to their public IP but that did not work. 我的第一个猜测是将每个RPC地址更改为其公共IP,但这没有用。
  2. My second guess was to change the broadcast address of each node to it's public IP but that did not work. 我的第二个猜测是将每个节点的广播地址更改为其公共IP,但这没有用。
  3. My third guess was to do both #1 and #2 and that did not work. 我的第三个猜测是同时做#1和#2,但这没有用。

Is there something still missing? 还缺少什么吗? Was one of those supposed to work and I just messed it up? 是应该工作的人之一,我只是搞砸了吗?

Thanks 谢谢

The cluster uses the broadcast_address to announce it to the other instances that they should attempt to communicate with the node over this address. 集群使用broadcast_address向其他实例通告它,它们应尝试通过该地址与节点进行通信。 By no means the cluster knows neither that the clients will be connecting to it using some sort of NAT translation (what if there is a mix of local and external clients), nor its external IP address (because it is an infrastructure, not cluster, property). 群集绝对不知道客户端是否会使用某种NAT转换(本地和外部客户端混合使用)或它的外部IP地址(因为它是基础结构,而不是群集)来连接到它,属性)。

So it is a driver's responsibility to find out how to connect to the cluster. 因此,驱动程序负责查找如何连接到群集。 Some drivers accept just a finite list of IPs they should connect to and only connect to those. 一些驱动程序仅接受应连接到的IP的有限列表,并且仅连接到这些IP。

But the Java driver has a policy called AddressTranslater that you can implement to perform translation from internal IP to external - for example by using AWS API. 但是Java驱动程序具有一个称为AddressTranslater的策略,您可以实施该策略以执行从内部IP到外部IP的转换-例如通过使用AWS API。 http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/AddressTranslater.html http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/policies/AddressTranslater.html

Here is a link to an implementation (I haven't used it myself): http://docs.hazelcast.org/docs/3.3/javadoc/com/hazelcast/client/spi/impl/AwsAddressTranslator.html 这是实现的链接(我自己没有使用过): http : //docs.hazelcast.org/docs/3.3/javadoc/com/hazelcast/client/spi/impl/AwsAddressTranslator.html

The broadcast_address is the address broadcast to other Cassandra nodes. broadcast_address是广播到其他Cassandra节点的地址。 It is good to set both listen_address and broadcast_address to the node's local IP. 最好将listen_address和broadcast_address都设置为节点的本地IP。 As you are going to access Cassandra via the node's public IP, you should set rpc_address and broadcast_rpc_address to the node's public IP. 当您要通过节点的公共IP访问Cassandra时,应将rpc_address和broadcast_rpc_address设置为节点的公共IP。

But for security reason, it is better to not expose Cassandra to the public world. 但是出于安全原因,最好不要将Cassandra暴露给公众。 If your application also runs in AWS, it is better to let Cassandra listen on the local IP only, and have the application access the local IP. 如果您的应用程序也运行在AWS上,最好让Cassandra仅侦听本地IP,并让应用程序访问本地IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM