View Source Cluster.Strategy.Gossip (libcluster v3.3.3)

This clustering strategy uses multicast UDP to gossip node names to other nodes on the network. These packets are listened for on each node as well, and a connection will be established between the two nodes if they are reachable on the network, and share the same magic cookie. In this way, a cluster of nodes may be formed dynamically.

The gossip protocol is extremely simple, with a prelude followed by the node name which sent the packet. The node name is parsed from the packet, and a connection attempt is made. It will fail if the two nodes do not share a cookie.

By default, the gossip occurs on port 45892, using the multicast address 233.252.1.32

The gossip protocol is not encrypted by default, but can be by providing a secret in the configuration of the strategy (as shown below). This can also be used to run multiple clusters with the same multicast configuration, as nodes not sharing the same encryption key will not be connected.

You may configure the multicast interface, multicast address, the interface address to bind to, the port, the TTL of the packets and the optional secret using the following settings:

config :libcluster,
  topologies: [
    gossip_example: [
      strategy: Elixir.Cluster.Strategy.Gossip,
      config: [
        port: 45892,
        if_addr: "0.0.0.0",
        multicast_if: "192.168.1.1",
        multicast_addr: "233.252.1.32",
        multicast_ttl: 1,
        secret: "somepassword"]]]

A TTL of 1 will limit packets to the local network, and is the default TTL.

Optionally, broadcast_only: true option can be set which disables multicast and only uses broadcasting. This limits connectivity to local network but works on in scenarios where multicast is not enabled. Use multicast_addr as the broadcast address.

Example for broadcast only:

config :libcluster,
  topologies: [
    gossip_example: [
      strategy: Elixir.Cluster.Strategy.Gossip,
      config: [
        port: 45892,
        if_addr: "0.0.0.0",
        multicast_addr: "255.255.255.255",
        broadcast_only: true]]]

Debug logging is deactivated by default for this clustering strategy, but it can be easily activated by configuring the application:

use Mix.Config

config :libcluster,
  debug: true

All the checks are done at runtime, so you can flip the debug level without being forced to shutdown your node.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Callback implementation for Cluster.Strategy.start_link/1.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Callback implementation for Cluster.Strategy.start_link/1.