Last active
September 27, 2022 06:28
-
-
Save ukazap/eeb89b989e62909086e276c7c47bdf3b to your computer and use it in GitHub Desktop.
Revisions
-
阿謙 revised this gist
Sep 27, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ ## Set up libcluster Use [libcluster](https://github.com/bitwalker/libcluster) to set up cluster automatically. Add dependency in mix.exs and run `mix deps.get`: -
阿謙 renamed this gist
Sep 27, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
阿謙 created this gist
Sep 27, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ # riak_core cluster formation ## Set up libcluster Use libcluster to set up cluster automatically. Add dependency in mix.exs and run `mix deps.get`: ```elixir defp deps do [ # ... {:libcluster, "~> 3.3"} # ... ] end ``` Add Cluster.Supervisor process in the supervision tree of the app (usually in lib/appname/application.ex): ```elixir 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 ``` ## Running Run 3 nodes: ```shell 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: ```elixir :riak_core.join('[email protected]') ``` On node1 run: ```elixir # 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() ```