RabbitMQ单机快速安装使用

RabbitMQ单机快速安装使用

一、概述

操作系统环境: CentOS7.8 x64
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

安装RabbitMQ之前需先安装Erlang

注意:CentOS7和CentOS8安装方式略有差异;Erlang和RabbitMQ版本有对应关系

本次安装版本为:Erlang-23.0.3,RabbitMQ-3.8.7


RabbitMQ Erlang Version Requirements
https://www.rabbitmq.com/which-erlang.html

Zero-dependency Erlang RPM for RabbitMQ
https://github.com/rabbitmq/erlang-rpm

二、安装Erlang

2.1.配置repo源

/etc/yum.repos.d/rabbitmq_erlang.repo

[rabbitmq_erlang]
name=rabbitmq_erlang
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
# PackageCloud's repository key and RabbitMQ package signing key
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
       https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

2.2.yum安装erlang

yum info erlang
yum -y install erlang


#另外也可以通过下载erlang rpm包方式直接安装
下载地址:https://github.com/rabbitmq/erlang-rpm/releases
wget https://github.com/rabbitmq/erlang-rpm/releases/download/v23.0.2/erlang-23.0.2-1.el7.x86_64.rpm
rpm -ivh erlang-23.0.2-1.el7.x86_64.rpm 

三.安装RabbitMQ

3.1.配置repo源

/etc/yum.repos.d/rabbitmq_rabbitmq-server.repo

[rabbitmq_rabbitmq-server]
name=rabbitmq_rabbitmq-server
baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

3.2.yum安装rabbitmq

#安装
yum -y install rabbitmq-server

#检查RabbitMQ是否安装成功
rabbitmqctl status

# 启动RabbitMQ
systemctl start rabbitmq-server #启动
systemctl enable rabbitmq-server #配置开机穹顶
systemctl status rabbitmq-server #查看状态


#另外也可以通过下载RabbitMQ rpm包方式直接安装
下载地址:https://dl.bintray.com/rabbitmq/
wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.8.7/rabbitmq-server-3.8.7-1.el7.noarch.rpm
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
yum install rabbitmq-server-3.8.7-1.el7.noarch.rpm
或rpm -ivh rabbitmq-server-3.8.7-1.el7.noarch.rpm

如果缺少socat,可以在这里下载https://centos.pkgs.org/
rpm -ivh socat-1.7.3.2-2.el7.x86_64.rpm 

四.配置使用

rabbitmqctl add_user admin 123456 #设置用户和密码
rabbitmqctl set_user_tags admin administrator #设置用户权限
rabbitmqctl add_vhost demo_dev #添加 vhost
rabbitmqctl set_permissions -p demo_dev admin ".*" ".*" ".*" #vhost设置权限

五、启用界面控制台(非必须)

启用插件
#rabbitmq-plugins enable rabbitmq_management

http://ip:15672 admin/123456 登录控制台

六、防火墙配置

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="5672" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="15672" accept"
firewall-cmd --reload



sed -i 's/SELINUX=enforing/SELINUX=disabled/' /etc/selinux/config
setforce 0
#如果是旧版rabbitmq可能非localhost不能登录
方案一:
在rabbitmq的配置文件目录下(默认为:/etc/rabbitmq)创建一个rabbitmq.config文件。
文件中添加如下配置:
[{rabbit, [{loopback_users, []}]}]. 

方案二:
把/usr/lib/rabbitmq/lib/rabbitmq_server-x.x.x/ebin/rabbit.app中的
将:{loopback_users, [<<”guest”>>]},改为:{loopback_users, []}

七、其他常用命令

rabbitmq-plugins list #查看所有插件列表
rabbitmqctl delete_user Username #删除一个用户
rabbitmqctl change_password Username Newpassword #修改用户密码
rabbitmqctl list_users #查看当前用户列表
rabbitmqctl list_permissions [-p  VHostPath] #查看(指定hostpath)所有用户的权限信息
rabbitmqctl list_user_permissions User #查看指定用户的权限信息
rabbitmqctl clear_permissions [-p VHostPath]  User #清除用户的权限信息

八、其他问题解决

Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled)

解决方案:
setsebool -P nis_enabled 1
chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/
posted @ 2020-08-23 11:00  一片相思林  阅读(444)  评论(0编辑  收藏  举报