当前位置: 首页 > 工具软件 > RabbitMQ-CN > 使用案例 >

Ubuntu20.04 安装 Rabbitmq-serverMQ消息队列服务

鲍鸿波
2023-12-01

关于MQ消息中间件的介绍如下:
(介绍来自于阿里云)
超详细的RabbitMQ入门,看这篇就够了!

RabbitMQ是一款使用Erlang语言开发的,实现AMQP(高级消息队列协议)的开源消息中间件。首先要知道一些RabbitMQ的特点,官网可查:

可靠性。支持持久化,传输确认,发布确认等保证了MQ的可靠性。
灵活的分发消息策略。这应该是RabbitMQ的一大特点。在消息进入MQ前由Exchange(交换机)进行路由消息。分发消息策略有:简单模式、工作队列模式、发布订阅模式、路由模式、通配符模式。
支持集群。多台RabbitMQ服务器可以组成一个集群,形成一个逻辑Broker。
多种协议。RabbitMQ支持多种消息队列协议,比如 STOMP、MQTT 等等。
支持多种语言客户端。RabbitMQ几乎支持所有常用编程语言,包括 Java、.NET、Ruby 等等。
可视化管理界面。RabbitMQ提供了一个易用的用户界面,使得用户可以监控和管理消息 Broker。
插件机制。RabbitMQ提供了许多插件,可以通过插件进行扩展,也可以编写自己的插件。

现在开始基于ubuntu20.04安装rabbitmq-server,非常的简单:

1、安装erlang-nox,(因为是基于Erlang开发的平台):

~# apt-get install erlang-nox -y

2、更新系统和环境:

~# apt-get update -y
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease                                                 
Hit:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease                                                                                                       
Hit:4 http://mirrors.aliyun.com/ubuntu focal-backports InRelease                                                                                                     
Hit:5 http://security.ubuntu.com/ubuntu xenial-security InRelease                                                                                                    
Hit:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease
Hit:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease
Hit:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease
Hit:9 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease
Reading package lists... Done

3、安装rabbitmq-server:

~# apt-get install rabbitmq-server -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  locales-all socat
The following NEW packages will be installed:
  locales-all rabbitmq-server socat
0 upgraded, 3 newly installed, 0 to remove and 65 not upgraded.
Need to get 22.3 MB of archives.
After this operation, 249 MB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 locales-all amd64 2.31-0ubuntu9.9 [10.5 MB]
Get:2 http://mirrors.aliyun.com/ubuntu focal/main amd64 socat amd64 1.7.3.3-2 [323 kB]                                                                                                                                                                                                   
Get:3 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 rabbitmq-server all 3.8.2-0ubuntu1.3 [11.5 MB]                                                                                                                                                                          
Fetched 22.3 MB in 1min 16s (295 kB/s)                                                                                                                                                                                                                                                   
Selecting previously unselected package locales-all.
(Reading database ... 146165 files and directories currently installed.)
Preparing to unpack .../locales-all_2.31-0ubuntu9.9_amd64.deb ...
Unpacking locales-all (2.31-0ubuntu9.9) ...
Selecting previously unselected package socat.
Preparing to unpack .../socat_1.7.3.3-2_amd64.deb ...
Unpacking socat (1.7.3.3-2) ...
Selecting previously unselected package rabbitmq-server.
Preparing to unpack .../rabbitmq-server_3.8.2-0ubuntu1.3_all.deb ...
Unpacking rabbitmq-server (3.8.2-0ubuntu1.3) ...
Setting up locales-all (2.31-0ubuntu9.9) ...
Setting up socat (1.7.3.3-2) ...
Setting up rabbitmq-server (3.8.2-0ubuntu1.3) ...
Adding group `rabbitmq' (GID 118) ...
Done.
Adding system user `rabbitmq' (UID 114) ...
Adding new user `rabbitmq' (UID 114) with group `rabbitmq' ...
Not creating home directory `/var/lib/rabbitmq'.
Created symlink /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service → /lib/systemd/system/rabbitmq-server.service.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.15) ...

4、查看安装后的rabbitmq服务状态:

~# systemctl status rabbitmq-server.service 
● rabbitmq-server.service - RabbitMQ Messaging Server
     Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-03-08 06:07:10 UTC; 1min 45s ago
   Main PID: 1283193 (beam.smp)
     Status: "Initialized"
      Tasks: 87 (limit: 4612)
     Memory: 72.2M
     CGroup: /system.slice/rabbitmq-server.service
             ├─1283189 /bin/sh /usr/sbin/rabbitmq-server
             ├─1283193 /usr/lib/erlang/erts-10.6.4/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa /usr/lib/rabbi>
             ├─1283458 erl_child_setup 65536
             ├─1283485 inet_gethost 4
             └─1283486 inet_gethost 4

Mar 08 06:07:04 openvpnclient1 systemd[1]: Starting RabbitMQ Messaging Server...
Mar 08 06:07:10 openvpnclient1 systemd[1]: rabbitmq-server.service: Supervising process 1283193 which is not our child. We'll most likely not notice when it exits.
Mar 08 06:07:10 openvpnclient1 systemd[1]: Started RabbitMQ Messaging Server.
Mar 08 06:07:12 openvpnclient1 systemd[1]: rabbitmq-server.service: Supervising process 1283193 which is not our child. We'll most likely not notice when it exits.

5、创建rabbitmq管理账户:

用户名和密码

~# rabbitmqctl add_user 用户名 密码
Adding user "admin" ...

6、给创建的账户赋予管理员权限:

~# rabbitmqctl set_user_tags 账户 administrator
Setting tags for user "*账户*" to [administrator] ...

7、给账户开启访问权限:

~# rabbitmqctl set_permissions -p / 账户 '.*' '.*' '.*'
Setting permissions for user "*账户*" in vhost "/" ...

8、开启管理界面(如果不开启则无法通过浏览器访问):

默认网页端口15672

~# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@openvpnclient1:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@openvpnclient1...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.

9、重启rabbitmq-server服务:

~# systemctl restart rabbitmq-server.service
~# systemctl status rabbitmq-server.service 
● rabbitmq-server.service - RabbitMQ Messaging Server
     Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-03-08 06:24:42 UTC; 3s ago
   Main PID: 1286291 (beam.smp)
     Status: "Initialized"
      Tasks: 87 (limit: 4612)
     Memory: 98.3M
     CGroup: /system.slice/rabbitmq-server.service
             ├─1286278 /bin/sh /usr/sbin/rabbitmq-server
             ├─1286291 /usr/lib/erlang/erts-10.6.4/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -K true -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa /usr/lib/rabbi>
             ├─1286564 erl_child_setup 65536
             ├─1286591 inet_gethost 4
             └─1286592 inet_gethost 4

Mar 08 06:24:38 openvpnclient1 systemd[1]: rabbitmq-server.service: Succeeded.
Mar 08 06:24:38 openvpnclient1 systemd[1]: Stopped RabbitMQ Messaging Server.
Mar 08 06:24:38 openvpnclient1 systemd[1]: Starting RabbitMQ Messaging Server...
Mar 08 06:24:42 openvpnclient1 systemd[1]: rabbitmq-server.service: Supervising process 1286291 which is not our child. We'll most likely not notice when it exits.
Mar 08 06:24:42 openvpnclient1 systemd[1]: Started RabbitMQ Messaging Server.

10、访问网页管理界面:

http://RabbitMQ服务器IP地址(本机的话就用127.0.0.1或者0.0.0.0):15672/

END! Thanks.

 类似资料: