0Pricing
RabbitMQ Messaging & Async Systems · レッスン

クラスター環境の構築

複数ノードで構成されるRabbitMQクラスターの構築手順を実践します。可用性を高めるため、ノードが連携して状態を共有するよう設定します。

「クラスター環境の構築」はCoddyKit上の無料RabbitMQ Messaging & Async Systemsレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはRabbitMQ Messaging & Async Systems学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 RabbitMQ Messaging & Async Systemsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Ready to Cluster RabbitMQ?

In the previous lesson, we learned about RabbitMQ clustering concepts. Now, let's get practical! We'll walk through the essential steps to set up a multi-node RabbitMQ cluster.

Building a cluster helps your messaging system become more robust and highly available. This means less downtime and more reliable message delivery.

Erlang's Secret Handshake

RabbitMQ nodes are built on Erlang, and they communicate using a shared secret called the Erlang cookie. Think of it as a password that allows nodes to trust each other.

  • Each RabbitMQ node has its own cookie file (~/.erlang.cookie or /var/lib/rabbitmq/.erlang.cookie).
  • For nodes to form a cluster, they MUST have identical Erlang cookies.
  • If cookies don't match, nodes won't be able to communicate or cluster.

Syncing Your Cookies

To ensure nodes can cluster, you need to copy the Erlang cookie from one node to all other nodes in the cluster. Choose one node as the 'source' for the cookie.

Here's how you typically do it (replace node2 with your actual node name/IP):

# On Node 1 (source)
sudo cp /var/lib/rabbitmq/.erlang.cookie /tmp/erlang.cookie.bak
sudo chmod 400 /var/lib/rabbitmq/.erlang.cookie
sudo scp /var/lib/rabbitmq/.erlang.cookie node2:/var/lib/rabbitmq/.erlang.cookie

# On Node 2 (destination)
# Ensure permissions are correct
sudo chmod 400 /var/lib/rabbitmq/.erlang.cookie
sudo chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie

Halt Before You Cluster

Before a node can join an existing cluster or form a new one, its RabbitMQ application must be stopped. This ensures a clean state for the clustering operation.

You'll use the rabbitmqctl stop_app command. This stops the RabbitMQ application but leaves the Erlang VM running.

# On Node 2 (the node joining the cluster)
sudo rabbitmqctl stop_app

Bringing Nodes Together

With the cookie synced and the app stopped, a node can now join the cluster. You'll specify the name of an existing node in the cluster to join.

Use the rabbitmqctl join_cluster <cluster_node_name> command. The cluster_node_name is usually in the format rabbit@hostname.

# On Node 2 (the node joining)
# Assuming Node 1 is 'rabbit@node1'
sudo rabbitmqctl join_cluster rabbit@node1

Restarting the Engines

After a node successfully joins the cluster, you need to start its RabbitMQ application again. It will now operate as part of the cluster.

Use the rabbitmqctl start_app command to bring the RabbitMQ application back online.

# On Node 2 (the node that joined)
sudo rabbitmqctl start_app

Check Your Cluster's Health

It's crucial to verify that all nodes have successfully joined the cluster. The rabbitmqctl cluster_status command shows you the current state of your cluster.

It lists all active nodes, their types (disk or RAM), and other important cluster information.

# On any node in the cluster
sudo rabbitmqctl cluster_status

Disk vs. RAM Nodes

When setting up a cluster, you might encounter disk nodes and RAM nodes. This refers to how a node stores its metadata (like queue definitions, exchange bindings, user data).

  • Disk nodes: Store metadata persistently on disk. At least one disk node is required in a cluster.
  • RAM nodes: Store metadata only in memory. They are faster but lose metadata on restart if not connected to a disk node.
  • Most production clusters use all disk nodes for simplicity and resilience.

Starting Fresh with Reset

Sometimes, a node might fail to join a cluster, or you might want to remove it and add it to a different cluster. In such cases, you can reset the node.

The rabbitmqctl reset command purges all data and state from a node, making it ready to be joined to a new or existing cluster.

# On the node to be reset
sudo rabbitmqctl stop_app
sudo rabbitmqctl reset
sudo rabbitmqctl start_app

Cluster Setup Check

You're setting up a RabbitMQ cluster. You've installed RabbitMQ on two servers, Node A and Node B. You've copied the Erlang cookie from Node A to Node B.

What is the next essential step on Node B before it can successfully join Node A's cluster?

Cluster Setup Summary

Great job! You've learned the practical steps to set up a RabbitMQ cluster. We covered:

  • The importance of the Erlang cookie for node authentication.
  • How to stop, join, and start RabbitMQ applications.
  • Using rabbitmqctl cluster_status to verify your cluster.
  • Briefly understanding disk and RAM nodes.
  • How to reset a node for a fresh start.

Next, we'll explore how to make your queues highly available using mirrored queues!

よくある質問

「クラスター環境の構築」レッスンは無料ですか?

はい。「クラスター環境の構築」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、RabbitMQ Messaging & Async Systemsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 RabbitMQ Messaging & Async Systemsコースには全4レッスンが含まれています。

「クラスター環境の構築」で何を学びますか?

複数ノードで構成されるRabbitMQクラスターの構築手順を実践します。可用性を高めるため、ノードが連携して状態を共有するよう設定します。 ブラウザで直接実行するハンズオンコードでRabbitMQ Messaging & Async Systemsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

RabbitMQ Messaging & Async Systemsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのRabbitMQ Messaging & Async Systemsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「クラスター環境の構築」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このRabbitMQ Messaging & Async Systemsレッスンでコードを書いて実行できますか?

はい。すべてのRabbitMQ Messaging & Async Systemsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. RabbitMQクラスタリングの概念
  2. クラスター環境の構築
  3. HA向けミラーキュー
  4. 最新のHAに向けたQuorum Queue
← RabbitMQ Messaging & Async Systemsに戻る