Use libcluster to set up cluster automatically.
Add dependency in mix.exs and run mix deps.get
:
defp deps do
[
# ...
{:libcluster, "~> 3.3"}
# ...
]
end
Add Cluster.Supervisor process in the supervision tree of the app (usually in lib/appname/application.ex):
defmodule MyApp.App do
use Application
def start(_type, _args) do
topologies = [
local_udp_gossip_aja: [
strategy: Cluster.Strategy.Gossip,
config: [
secret: "this_is_a_shared_secret"
]
]
]
children = [
{Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
# ..other children..
]
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end
end
Run 3 nodes:
MIX_ENV=node1 iex --name [email protected] --cookie this_is_a_shared_secret -S mix
MIX_ENV=node2 iex --name [email protected] --cookie this_is_a_shared_secret -S mix
MIX_ENV=node3 iex --name [email protected] --cookie this_is_a_shared_secret -S mix
On node2 and node3 run:
:riak_core.join('[email protected]')
On node1 run:
# To see the planned changes in the ring:
:riak_core_claimant.plan()
# Now we can commit the plan:
:riak_core_claimant.commit()
# Periodically run some of these:
:riak_core_console.member_status([])
:riak_core_handoff_manager.status()
:riak_core_console.transfers([])
{:ok, ring} = :riak_core_ring_manager.get_my_ring()
:riak_core_ring.pretty_print(ring, [:legend])
:riak_core_status.ringready()
Todo: automatically admit new node to riak core cluster using something like Horde's NodeListener