简体   繁体   English

分布式系统 - 如何为分布式系统中的每个节点分配一个节点ID?

[英]Distributed system - How to assign a node ID to each node in distributed system?

How can we assign a unique ID to each node/instance of an application in a distributed environment?我们如何在分布式环境中为应用程序的每个节点/实例分配一个唯一的 ID?

  • We have deployed our app on multiple hosts and requests are distributed across them through a load balancer.我们已经在多个主机上部署了我们的应用程序,请求通过负载均衡器分布在它们之间。
  • We have a requirement where we want to store some data specific to these nodes, and if one of the servers crashes then upon restart we want to delete data specific to only that node, not for others.我们有一个要求,我们想要存储一些特定于这些节点的数据,如果其中一台服务器崩溃,那么在重新启动时我们只想删除特定于该节点的数据,而不是其他节点。
  • We can use IP addresses, but that doesn't seem to be a perfect solution.我们可以使用 IP 地址,但这似乎不是一个完美的解决方案。 How can we use node ID which is non-changeable so that once the server/node restarts it remains the same?我们如何使用不可更改的节点 ID,以便在服务器/节点重新启动后它保持不变?
  • Our application is basically a Java web application which is a kind of web socket server running on tomcat containers.我们的应用程序基本上是一个 Java web 应用程序,它是一种运行在 tomcat 容器上的 web 套接字服务器。

You could potentially use any of the following:您可能会使用以下任何一项:

  • The MAC address of the server when you created the node.创建节点时服务器的MAC地址。 MAC addresses are not supposed to be reused / re-assigned to a different server. MAC 地址不应该被重用/重新分配给不同的服务器。
  • A random (type 4) UUID.随机(类型 4)UUID。 The probability of a type 4 UUID being regenerated is too small to worry about.重新生成 4 类 UUID 的概率太小,无需担心。
  • Any large enough random number generated by a crypto quality PRNG seeded with a decent source of entropy.由加密质量的 PRNG 生成的任何足够大的随机数,该随机数以适当的熵源作为种子。
  • Anything you want... in combination with a registry mechanism that ensures that identifiers are not going to be reused.任何你想要的……与确保标识符不会被重复使用的注册机制相结合。

Presumably, you store each node's id in the persistent state of the node itself so that it can look it up when it restarts.据推测,您将每个节点的 id 存储在节点本身的持久性 state 中,以便它可以在重新启动时查找它。 (If not, you could make it the responsibility of the the node launch / relaunch mechanism to tell it.) (如果没有,您可以让节点启动/重新启动机制负责告诉它。)

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

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