1 サーバー基本情報
サーバーIP | ドッカー コンテナ名 |
---|---|
172.21.16.4 | mq_document_1 |
172.21.16.6 | mq_document_2 |
172.21.16.9 | mq_document_3 |
目標:
- コンテナ
mq_document_1
とコンテナがmq_document_3
コンテナに結合mq_document_2
2 ファイルの整理
ディレクトリ構造は次のとおりです。
mq
|-- data
|-- docker-compose.yaml
`-- rabbitmq.conf
docker-compose.yaml 構成ファイルは次のとおりです。3
つの構成ファイルは一貫しており、異なる名前を使用するだけです。
version: "3"
services:
mq:
image: rabbitmq:management
container_name: mq_document_1
hostname: mq_document_1
environment:
RABBITMQ_DEFAULT_USER: xxx
RABBITMQ_DEFAULT_PASS: xxx
RABBITMQ_ERLANG_COOKIE: rabbitcookie
RABBITMQ_CONFIG_FILE: /etc/rabbitmq/rabbitmq.conf
extra_hosts:
- "mq_document_1:172.21.16.4"
- "mq_document_2:172.21.16.6"
- "mq_document_3:172.21.16.9"
restart: always
network_mode: host
volumes:
- ./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
- ./data:/var/lib/rabbitmq
rabbitmq.conf
consumer_timeout = 21600000
listeners.tcp.default = 5673
management.tcp.port = 15673
3 アレンジファイルの説明
Docker Compose では、extra_hosts
キーワードホスト バインディング関係を構成します。--add-host=mq_document_1:172.21.16.4
これは、ネイティブ コマンドと同じ効果があります。
network_mode: host
ホスト ネットワーク モードを使用して、ネットワークをホストと共有します。
mq が使用する必要があるデフォルトのポートは次のとおりです。
4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 15691-15692/tcp, 25672/tcp
自分でポートをマッピングすることもできます. 欠点は、構成が複雑でエラーが発生しやすいことです. RabbitMQ は、AMQP プロトコルのポートとして 5672 を使用し、Web インターフェイスの管理ポートとして 15672 を使用し、Erlang 分散ノード間のポートとして 25672 を使用します.など、およびその他のポートは、構成ファイルを使用して変更する必要があります。
4 ノードを起動して参加する
3 つのサーバーは別々に実行されます。docker-compose up -d
次に、mq_document_1
と がmq_document_3
あるサーバーで操作します。手順はまったく同じです。
-
コンテナに
docker-compose exec -it mq bash
-
RabbitMQ サービスを閉じる
rabbitmqctl stop_app
環境変数 RABBITMQ_ERLANG_COOKIE が古くなっていることを確認してください。心配する必要はありません。手動設定は面倒です。そのまま使用してください。
root@mq_document_1:/# rabbitmqctl stop_app RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead. Stopping rabbit application on node rabbit@mq_document_1 ...
-
リセット
rabbitmqctl reset
-
ノード 2 に参加
rabbitmqctl join_cluster rabbit@mq_document_2
次のログが正常に追加されました。このエラーは、現在のノードが開始されていないことを意味します。次の手順に従って開始してください。
RABBITMQ_ERLANG_COOKIE env variable support is deprecated and will be REMOVED in a future version. Use the $HOME/.erlang.cookie file or the --erlang-cookie switch instead. Clustering node rabbit@mq_document_1 with rabbit@mq_document_2 07:53:44.737 [warn] Feature flags: the previous instance of this node must have failed to write the `feature_flags` file at `/var/lib/rabbitmq/mnesia/rabbit@mq_document_1-feature_flags`: 07:53:44.737 [warn] Feature flags: - list of previously disabled feature flags now marked as such: [:maintenance_mode_status] 07:53:44.812 [warn] Feature flags: the previous instance of this node must have failed to write the `feature_flags` file at `/var/lib/rabbitmq/mnesia/rabbit@mq_document_1-feature_flags`: 07:53:44.812 [warn] Feature flags: - list of previously enabled feature flags now marked as such: [:maintenance_mode_status] 07:53:44.822 [error] Failed to create a tracked connection table for node :rabbit@mq_document_1: { :node_not_running, :rabbit@mq_document_1} 07:53:44.822 [error] Failed to create a per-vhost tracked connection table for node :rabbit@mq_document_1: { :node_not_running, :rabbit@mq_document_1} 07:53:44.822 [error] Failed to create a per-user tracked connection table for node :rabbit@mq_document_1: { :node_not_running, :rabbit@mq_document_1}
-
アプリサービス開始
rabbitmqctl start_app
5 ミラー キュー ルールの構成
rabbitmq 管理インターフェース Admin->Policies
次のルールを追加します。
Name: document-mirrors
Pattern: .*(?=-document-queue)
Definition: ha-mode=all
ha-sync-mode=automatic