RabbitMQ是基于Erlang语言开发的。
在安装RabbitMQ前,首先搭建好Erlang环境。
$ cd /opt
$ wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm
#####本人获取连接文件包时,下载速度太慢,采取先下载到本地电脑,再使用x-ftp上传到服务器
$ yum install erlang-19.0.4-1.el7.centos.x86_64.rpm
安装Rabbit,
$ cd /opt
$ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-3.6.10-1.el7.noarch.rpm
$ yum install rabbitmq-server-3.6.10-1.el7.noarch.rpm
启动服务,
$ service rabbitmq-server start
查看服务状态
$ service rabbitmq-server status
$ service rabbitmq-server status
Redirecting to /bin/systemctl status rabbitmq-server.service
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-04-13 21:20:47 CST; 1 day 15h ago
Process: 22831 ExecStop=/usr/sbin/rabbitmqctl stop (code=exited, status=0/SUCCESS)
Main PID: 23248 (beam)
Status: "Initialized"
CGroup: /system.slice/rabbitmq-server.service
├─23248 /usr/lib64/erlang/erts-8.0.3/bin/beam -W w -A 64 -P 1048576 -t 5000000 -stbt db -zdbbl 32000 -K true -- -root /usr...
├─23421 /usr/lib64/erlang/erts-8.0.3/bin/epmd -daemon
├─23525 erl_child_setup 1024
├─23538 inet_gethost 4
└─23539 inet_gethost 4
Apr 13 21:20:46 VM_0_14_centos rabbitmq-server[23248]: RabbitMQ 3.6.10. Copyright (C) 2007-2017 Pivotal Software, Inc.
Apr 13 21:20:46 VM_0_14_centos rabbitmq-server[23248]: ## ## Licensed under the MPL. See http://www.rabbitmq.com/
Apr 13 21:20:46 VM_0_14_centos rabbitmq-server[23248]: ## ##
Apr 13 21:20:46 VM_0_14_centos rabbitmq-server[23248]: ########## Logs: /var/log/rabbitmq/rabbit@VM_0_14_centos.log
Apr 13 21:20:46 VM_0_14_centos rabbitmq-server[23248]: ###### ## /var/log/rabbitmq/rabbit@VM_0_14_centos-sasl.log
Apr 13 21:20:46 VM_0_14_centos rabbitmq-server[23248]: ##########
Apr 13 21:20:46 VM_0_14_centos rabbitmq-server[23248]: Starting broker...
Apr 13 21:20:47 VM_0_14_centos rabbitmq-server[23248]: systemd unit for activation check: "rabbitmq-server.service"
Apr 13 21:20:47 VM_0_14_centos systemd[1]: Started RabbitMQ broker.
Apr 13 21:20:47 VM_0_14_centos rabbitmq-server[23248]: completed with 0 plugins.
查看日志
$ cd /var/log/rabbitmq/
$ less rabbit@VM_0_14_centos.log
=INFO REPORT==== 13-Apr-2020::21:13:25 ===
Starting RabbitMQ 3.6.10 on Erlang 19.0.4
Copyright (C) 2007-2017 Pivotal Software, Inc.
Licensed under the MPL. See http://www.rabbitmq.com/
=INFO REPORT==== 13-Apr-2020::21:13:25 ===
node : rabbit@VM_0_14_centos
home dir : /var/lib/rabbitmq
config file(s) : /etc/rabbitmq/rabbitmq.config (not found)
cookie hash : A6jIhactOxEauQuG5sbz4A==
log : /var/log/rabbitmq/rabbit@VM_0_14_centos.log
sasl log : /var/log/rabbitmq/rabbit@VM_0_14_centos-sasl.log
database dir : /var/lib/rabbitmq/mnesia/rabbit@VM_0_14_centos
=INFO REPORT==== 13-Apr-2020::21:13:27 ===
Memory limit set to 735MB of 1838MB total.
=INFO REPORT==== 13-Apr-2020::21:13:27 ===
Enabling free disk space monitoring
=INFO REPORT==== 13-Apr-2020::21:13:27 ===
Disk free limit set to 50MB
=INFO REPORT==== 13-Apr-2020::21:13:27 ===
Limiting to approx 924 file handles (829 sockets)
=INFO REPORT==== 13-Apr-2020::21:13:27 ===
FHC read buffering: OFF
FHC write buffering: ON
=INFO REPORT==== 13-Apr-2020::21:13:27 ===
Database directory at /var/lib/rabbitmq/mnesia/rabbit@VM_0_14_centos is empty. Initialising from scratch...
=INFO REPORT==== 13-Apr-2020::21:13:27 ===
Waiting for Mnesia tables for 30000 ms, 9 retries left
log中显示没有找到配置文件,自己创建这个文件
$ config file(s) : /etc/rabbitmq/rabbitmq.config (not found)
创建rabbitmq.config
$ cd /etc/rabbitmq/
$ vi rabbitmq.config
编辑保存如下内容(别忘了最后的“.”):
[{rabbit, [{loopback_users, []}]}].
开启管理UI
$ /sbin/rabbitmq-plugins enable rabbitmq_management
重启服务
service rabbitmq-server restart
访问管理UI(注意外网登录要先开放5672/15672端口)
通过 http://ip:15672 使用guest,guest 进行登陆了
登陆成功
登陆成功
添加用户
命令格式
rabbitmqctl add_user <username> <newpassword>
$ rabbitmqctl add_user root 123456
Creating user "root"
用户授权
rabbitmqctl set_permissions -p "/" root ".*" ".*" ".*"
查看用户授权
$ rabbitmqctl list_permissions root
Listing permissions for user "root"
/ .* .* .*
添加角色
将root用户设置为administrator角色
$ rabbitmqctl set_user_tags root administrator
Setting tags for user "root" to [administrator]
查看当前用户列表
$ rabbitmqctl list_users
Listing users
guest [administrator]
root [administrator]
完成以上操作后,可以使用root身份登录管理UI http://ip:15672
本文操作完全参考# CentOs7.3 搭建 RabbitMQ 3.6 单机服务与使用
Rabbit简单使用可参考# Spring Boot 中使用 RabbitMQ
网友评论