栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

RabbitMQ普通集群搭建

RabbitMQ普通集群搭建

搭建第一个节点:

docker run -d --hostname rabbit_host1 --name rabbitmq1 -p 15672:15672 -p 5672:5672 -e RABBITMQ_NODENAME=rabbit -e RABBITMQ_DEFAULT_USER=tech -e RABBITMQ_DEFAULT_PASS=tech -e RABBITMQ_ERLANG_cookie='rabbitmq_cookie_tech' --privileged=true -v /usr/local/rabbitmq/1/lib:/var/lib/rabbitmq   rabbitmq:management

搭建第二个节点:

docker run -d --hostname rabbit_host2 --name rabbitmq2 -p 15673:15672 -p 5673:5672 --link rabbitmq1:rabbit_host1 -e RABBITMQ_NODENAME=rabbit -e RABBITMQ_DEFAULT_USER=tech -e RABBITMQ_DEFAULT_PASS=tech -e RABBITMQ_ERLANG_cookie='rabbitmq_cookie_tech' --privileged=true -v /usr/local/rabbitmq/2/lib:/var/lib/rabbitmq  rabbitmq:management

搭建第三个节点:

docker run -d --hostname rabbit_host3 --name rabbitmq3 -p 15674:15672 -p 5674:5672 --link rabbitmq1:rabbit_host1 --link rabbitmq2:rabbit_host2 -e RABBITMQ_NODENAME=rabbit -e RABBITMQ_DEFAULT_USER=tech -e RABBITMQ_DEFAULT_PASS=tech -e RABBITMQ_ERLANG_cookie='rabbitmq_cookie_tech' --privileged=true -v /usr/local/rabbitmq/3/lib:/var/lib/rabbitmq  rabbitmq:management

参数说明:

--hostname  主机host名称
--name  容器名称
-p  端口映射,主机端口:容器端口
--link  容器间实现互通
-e  rabbitmq参数
    RABBITMQ_ERLANG_cookie 集群节点间认证使用cookie,cookie相同才能允许节点加入集群
--privileged  使用root权限
-v 容器数据卷进行数据挂载,主机目录:容器目录

访问集群各个节点的管控台: 

对节点1进行配置:

root@rabbit_host1:/# 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@rabbit_host1 ...
root@rabbit_host1:/# rabbitmqctl reset
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.
Resetting node rabbit@rabbit_host1 ...
root@rabbit_host1:/# rabbitmqctl start_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.
Starting node rabbit@rabbit_host1 ...
root@rabbit_host1:/# exit
exit

 对节点2进行配置:

[root@localhost /]# docker exec -it rabbitmq2 bash
root@rabbit_host2:/# 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@rabbit_host2 ...
root@rabbit_host2:/# rabbitmqctl reset
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.
Resetting node rabbit@rabbit_host2 ...
root@rabbit_host2:/# rabbitmqctl join_cluster --ram rabbit@rabbit_host1
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@rabbit_host2 with rabbit@rabbit_host1

12:28:59.951 [warn]  Feature flags: the previous instance of this node must have failed to write the `feature_flags` file at `/var/lib/rabbitmq/mnesia/rabbit@rabbit_host2-feature_flags`:

12:28:59.951 [warn]  Feature flags:   - list of previously disabled feature flags now marked as such: [:maintenance_mode_status]

12:29:00.102 [error] Failed to create a tracked connection table for node :rabbit@rabbit_host2: {:node_not_running, :rabbit@rabbit_host2}

12:29:00.102 [error] Failed to create a per-vhost tracked connection table for node :rabbit@rabbit_host2: {:node_not_running, :rabbit@rabbit_host2}

12:29:00.103 [error] Failed to create a per-user tracked connection table for node :rabbit@rabbit_host2: {:node_not_running, :rabbit@rabbit_host2}
root@rabbit_host2:/# rabbitmqctl start_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.
Starting node rabbit@rabbit_host2 ...
root@rabbit_host2:/# exit
exit

对节点3进行配置:

[root@localhost /]# docker exec -it rabbitmq3 bash
root@rabbit_host3:/# 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@rabbit_host3 ...
root@rabbit_host3:/# rabbitmqctl reset
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.
Resetting node rabbit@rabbit_host3 ...
root@rabbit_host3:/# rabbitmqctl join_cluster --ram rabbit@rabbit_host1
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@rabbit_host3 with rabbit@rabbit_host1

12:31:34.735 [warn]  Feature flags: the previous instance of this node must have failed to write the `feature_flags` file at `/var/lib/rabbitmq/mnesia/rabbit@rabbit_host3-feature_flags`:

12:31:34.735 [warn]  Feature flags:   - list of previously disabled feature flags now marked as such: [:maintenance_mode_status]

12:31:34.896 [error] Failed to create a tracked connection table for node :rabbit@rabbit_host3: {:node_not_running, :rabbit@rabbit_host3}

12:31:34.896 [error] Failed to create a per-vhost tracked connection table for node :rabbit@rabbit_host3: {:node_not_running, :rabbit@rabbit_host3}

12:31:34.896 [error] Failed to create a per-user tracked connection table for node :rabbit@rabbit_host3: {:node_not_running, :rabbit@rabbit_host3}
root@rabbit_host3:/# rabbitmqctl start_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.
Starting node rabbit@rabbit_host3 ...
root@rabbit_host3:/# exit
exit

随便进入一个节点,查看集群状态

[root@localhost /]# docker exec -it rabbitmq3 bash
root@rabbit_host3:/# rabbitmqctl cluster_status
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.
Cluster status of node rabbit@rabbit_host3 ...
Basics

Cluster name: rabbit@rabbit_host3

Disk Nodes

rabbit@rabbit_host1

RAM Nodes

rabbit@rabbit_host2
rabbit@rabbit_host3

Running Nodes

rabbit@rabbit_host1
rabbit@rabbit_host2
rabbit@rabbit_host3

Versions

rabbit@rabbit_host1: RabbitMQ 3.9.8 on Erlang 24.1.2
rabbit@rabbit_host2: RabbitMQ 3.9.8 on Erlang 24.1.2
rabbit@rabbit_host3: RabbitMQ 3.9.8 on Erlang 24.1.2

Maintenance status

Node: rabbit@rabbit_host1, status: not under maintenance
Node: rabbit@rabbit_host2, status: not under maintenance
Node: rabbit@rabbit_host3, status: not under maintenance

Alarms

(none)

Network Partitions

(none)

Listeners

Node: rabbit@rabbit_host1, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: rabbit@rabbit_host1, interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Node: rabbit@rabbit_host1, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: rabbit@rabbit_host1, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Node: rabbit@rabbit_host2, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: rabbit@rabbit_host2, interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Node: rabbit@rabbit_host2, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: rabbit@rabbit_host2, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Node: rabbit@rabbit_host3, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: rabbit@rabbit_host3, interface: [::], port: 15692, protocol: http/prometheus, purpose: Prometheus exporter API over HTTP
Node: rabbit@rabbit_host3, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: rabbit@rabbit_host3, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0

Feature flags

Flag: drop_unroutable_metric, state: enabled
Flag: empty_basic_get_metric, state: enabled
Flag: implicit_default_bindings, state: enabled
Flag: maintenance_mode_status, state: enabled
Flag: quorum_queue, state: enabled
Flag: stream_queue, state: enabled
Flag: user_limits, state: enabled
Flag: virtual_host_metadata, state: enabled

状态正常,接下来进入管控台验证

访问任何一个节点的管控台,都可以看到Nodes的三个节点,说明普通集群搭建完成。

普通集群测试验证:

在一个节点上创建交换机、队列,可以观察到这些信息被同步到了其他的节点上。

在队列上发布1条消息,在其他节点上的这个队列上也能获取,但是消息只是存储在1个节点上,其他节点再去存储消息的节点上拉取。

在发布消息时候,未进行消息持久化,让存储消息的节点宕机重启后,发现消息丢失了。

在发布消息时候,如果指定消息持久化,让存储消息的节点宕机重启后,发现消息不会丢失。

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/434039.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号