RabbitMQ安装

RabbitMQ安装

薛定谔的汪

前言

用过消息队列的应该知道,它的作用有:异步处理、应用解耦、流量削峰、日志处理等等。

之前用过的 ActiveMQ 消息队列,但是新东家使用的是 RabbitMQ,所以接下来会着重学习下 RabbitMQ,并结合一些实际应用场景开发一些小 Demo,争取能在入职前对其有一个基本的掌握。

RabbitMQ安装

学习 RabbitMQ 就要先安装它,Mac 上安装 RabbitMQ 可直接利用 homebrew 安装即可,非常简单。主要学习下 CentOS7上安装 RabbitMQ。

RabbitMQ是用 Erlang 语言编写的,所以首先要安装 Erlang 语言环境。

安装erlang

下载地址:http://www.erlang.org/downloads

CentOS7上可以

1
2
3
4
5
6
//安装 Erlang
yum -y install erlang
//查看 Erlang 安装位置
whereis erlang
erlang: /usr/lib64/erlang

安装完后输入 erl验证 Erlang是否安装成功:

1
2
3
4
5
erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.4 (abort with ^G)
1>

表示安装成功。

安装rabbitmq

下载地址:http://www.rabbitmq.com/releases/rabbitmq-server/
RabbitMQ 版本用的rabbitmq-server-generic-unix-..*.tar.gz的版本。以最新的3.16.15为例:

1
2
3
tar -xvf rabbitmq-server-generic-unix-3.6.15.tar.xz -C /opt
cd /opt
mv rabbitmq_server-3.6.15 rabbitmq

修改/etc/profile文件,添加下面的环境变量:

1
export PATH=$PATH:/opt/rabbitmq/sbin

最后执行source /etc/profile让文件生效。

运行:

1
2
//-detached  让 rabbitmq 后台启动
rabbitmq-server -detached

执行rabbitmqctl status查看rabbitmq是否正常启动:

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Status of node rabbit@yakai
[{pid,18241},
{running_applications,
[{rabbitmq_management,"RabbitMQ Management Console","3.6.15"},
{rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.6.15"},
{cowboy,"Small, fast, modular HTTP server.","1.0.4"},
{cowlib,"Support library for manipulating Web protocols.","1.0.2"},
{rabbitmq_management_agent,"RabbitMQ Management Agent","3.6.15"},
{amqp_client,"RabbitMQ AMQP Client","3.6.15"},
{inets,"INETS CXC 138 49","5.9.8"},
{rabbit,"RabbitMQ","3.6.15"},
{os_mon,"CPO CXC 138 46","2.2.14"},
{rabbit_common,
"Modules shared by rabbitmq-server and rabbitmq-erlang-client",
"3.6.15"},
{ranch,"Socket acceptor pool for TCP protocols.","1.3.2"},
{compiler,"ERTS CXC 138 10","4.9.4"},
{syntax_tools,"Syntax tools","1.6.13"},
{ssl,"Erlang/OTP SSL application","5.3.3"},
{public_key,"Public key infrastructure","0.21"},
{asn1,"The Erlang ASN1 compiler version 2.0.4","2.0.4"},
{crypto,"CRYPTO version 2","3.2"},
{xmerl,"XML parser","1.3.6"},
{recon,"Diagnostic tools for production use","2.3.2"},
{mnesia,"MNESIA CXC 138 12","4.11"},
{sasl,"SASL CXC 138 11","2.3.4"},
{stdlib,"ERTS CXC 138 10","1.19.4"},
{kernel,"ERTS CXC 138 10","2.16.4"}]},
{os,{unix,linux}},
{erlang_version,
"Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [async-threads:64] [hipe] [kernel-poll:true]\n"},
{memory,
[{connection_readers,0},
{connection_writers,0},
{connection_channels,0},
{connection_other,2720},
{queue_procs,161456},
{queue_slave_procs,0},
{plugins,2127960},
{other_proc,20870328},
{metrics,70160},
{mgmt_db,539808},
{mnesia,88520},
{other_ets,2239616},
{binary,1637280},
{msg_index,46456},
{code,27110331},
{atom,992409},
{other_system,9108788},
{allocated_unused,13893448},
{reserved_unallocated,270016},
{total,79159296}]},
{alarms,[]},
{listeners,[{clustering,25672,"::"},{amqp,5672,"::"},{http,15672,"::"}]},
{vm_memory_calculation_strategy,rss},
{vm_memory_high_watermark,0.4},
{vm_memory_limit,416220774},
{disk_free_limit,50000000},
{disk_free,38123782144},
{file_descriptors,
[{total_limit,65435},
{total_used,9},
{sockets_limit,58889},
{sockets_used,0}]},
{processes,[{limit,1048576},{used,343}]},
{run_queue,0},
{uptime,1029004},
{kernel,{net_ticktime,60}}]

出现如上所述表示安装成功!

启动管理插件

1
rabbitmq-plugins enable rabbitmq_management

之后打开页面输入http://yourip.com:15672/可以查看 rabbitmq 控制台,如果是在本地启动,默认账户密码都上guest(guest 默认只能登陆 localhost)。如果是在远程服务器上安装的 RabbitMQ,则需要添加其他用户。

停止 RabbitMQ

1
rabbitmqctl stop
  • Title: RabbitMQ安装
  • Author: 薛定谔的汪
  • Created at : 2018-03-17 11:48:38
  • Updated at : 2023-11-17 19:37:37
  • Link: https://www.zhengyk.cn/2018/03/17/mq/rabbitmq/install/
  • License: This work is licensed under CC BY-NC-SA 4.0.