MQ的使用场景

削峰,异步,解耦

MQ集群分布

环境配置:

修改路由表:因为我们的rabbit@+ip:这里不可以写ip所以我们就写一个路由表直接映射,linux再/etc/hosts下面

如果使用的yum下载的话,那么我们是没有配置文件的;所以我们就自己建立一个配置文件

配置文件的地址:https://github.com/rabbitmq/rabbitmq-server/blob/v3.8.x/deps/rabbit/docs/rabbitmq.conf.example

配置文件放置的位置就在你的安装目录下;

1
2
[root@iZwz94khotag1q066igytrZ rabbitmq]# whereis rabbitmq
rabbitmq: /usr/lib/rabbitmq /etc/rabbitmq

我放置的地方是:/etc/rabbitmq目录下

配置完了重启服务,打开页面发现下面的界面就配置成功了

image-20210304214349359

1. 主从模式

1.概念

一个主机配置一个从机,然后从节点可以同步复制主节点的消息内容,但是如果主节点宕机那么从节点将不会提供服务,但是可以获得从节点的消息

2.查看cookie

这是一个隐藏文件夹:

我们要让所有的集群的cookie一样

1
cat /var/lib/rabbitmq/.erlang.cookie

添加节点(在从节点上配置,主节点不变):

1
2
3
1.关闭       rabbitmqctl stop_app
2.加入集群 rabbitmqctl join_cluster rabbit@mq01
3.启动服务 rabbitmqctl start_app

我们需要明白的就是主从的概念,就是谁添加到谁,被添加的就是主节点,主动的就是从节点

完成上面的步骤以后可以查看集群状态,在任何一个节点上都可以

1
rabbitmqctl cluster_status

显示如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Cluster status of node rabbit@iZwz94khotag1q066igytrZ ...
Basics

Cluster name: rabbit@iZwz94khotag1q066igytrZ

Disk Nodes

rabbit@iZwz94khotag1q066igytrZ

RAM Nodes

rabbit@localhost

Running Nodes

rabbit@iZwz94khotag1q066igytrZ
rabbit@localhost

Versions

rabbit@iZwz94khotag1q066igytrZ: RabbitMQ 3.8.13 on Erlang 23.2.3
rabbit@localhost: on Erlang

Maintenance status

Node: rabbit@iZwz94khotag1q066igytrZ, status: not under maintenance
Node: rabbit@localhost, status: unknown

Alarms

(none)

Network Partitions

(none)

Listeners

Node: rabbit@iZwz94khotag1q066igytrZ, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: rabbit@iZwz94khotag1q066igytrZ, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: rabbit@iZwz94khotag1q066igytrZ, 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: user_limits, state: enabled
Flag: virtual_host_metadata, state: enabled

图形界面如下:

image-20210304224549906

2.镜像队列配置

再前面的基础上进行一个规则的制定

1
rabbitmqctl set_policy hello "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}'

就可以使用