一、准备环境
由于RabbitMQ是由Erlang语言编写的基于amqp协议的消息代理中间件,所以安装RabbitMQ之前需要先安装Erlang和socat环境。
- 安装socat
yum -y install socat
- 安装Erlang
由于Erlang在默认的YUM存储库中不可用,所以这里是从GitHub上下载rpm安装文件进行安装,下载地址如下(此次环境下载22.1.6版本):
https://github.com/rabbitmq/erlang-rpm/releases/tag/v22.1.6
下载完成后将安装包上传至centos系统
执行下面命令进行安装
rpm -ivh erlang-22.1.6-1.el7.x86_64.rpm
查看Erlang的版本
[root@localhost opt]# erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 10.5.4
[root@localhost opt]#
至此,Erlang环境安装完毕
二、安装RabbitMQ
1. 首先从RabbitMQ官网下载RabbitMQ安装包
2. 导入GPG密钥
[root@localhost opt]# rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
[root@localhost opt]#
3. 将RabbitMQ安装包上传到centOS
执行下面命令开始安装RabbitMQ
[root@localhost opt]# rpm -ivh rabbitmq-server-3.8.1-1.el7.noarch.rpm
准备中... ################################# [100%]
正在升级/安装...
1:rabbitmq-server-3.8.1-1.el7 ################################# [100%]
[root@localhost opt]#
至此,RabbitMQ已经安装在CentOS上。
三、配置RabbitMQ
- 启动RabbitMQ
[root@localhost opt]# systemctl start rabbitmq-server
[root@localhost opt]#
- 将RabbitMQ设置成开机自启动
[root@localhost opt]# systemctl enable rabbitmq-server
Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.
[root@localhost opt]#
- 查看RabbitMQ状态信息
[root@localhost opt]# systemctl status rabbitmq-server
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2019-11-22 09:44:35 CST; 1min 27s ago
Main PID: 7775 (beam.smp)
Status: "Initialized"
CGroup: /system.slice/rabbitmq-server.service
├─7775 /usr/lib64/erlang/erts-10.5.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 /us...
├─7952 /usr/lib64/erlang/erts-10.5.4/bin/epmd -daemon
├─8089 erl_child_setup 32768
├─8110 inet_gethost 4
└─8111 inet_gethost 4
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: Doc guides: https://rabbitmq.com/documentation.html
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: Support: https://rabbitmq.com/contact.html
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: Tutorials: https://rabbitmq.com/getstarted.html
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: Monitoring: https://rabbitmq.com/monitoring.html
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: Logs: /var/log/rabbitmq/rabbit@localhost.log
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: Config file(s): (none)
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: Starting broker...systemd unit for activation check: "rabbitmq-server.service"
11月 22 09:44:35 localhost.localdomain systemd[1]: Started RabbitMQ broker.
11月 22 09:44:35 localhost.localdomain rabbitmq-server[7775]: completed with 0 plugins.
[root@localhost opt]#
- 开启RabbitMQ Web控制台
RabbitMQ Web控制台默认情况下是关闭的,可以通过以下命令进行开启
[root@localhost opt]# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@localhost:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@localhost...
The following plugins have been enabled:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
started 3 plugins.
[root@localhost opt]#
开启RabbitMQ Web控制台之后,还需要为该控制台创建管理用户,
rabbitmqctl add_user admin admin123
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
以上命令的意思是:新建一个用户名为admin,密码为admin123的用户,并且给该用户设置成administrator的角色,最后给该用户授予访问 “/” 虚拟主机空间的权限
-
通过上一步的配置之后,可以通过访问系统的15672端口进行访问RabbitMQ Web控制台,用户名和密码是上一步创建的
至此,RabbitMQ安装配置完成。