一、RabbitMQ简介
MQ全称为Message Queue, 是一种分布式应用程序的的通信方法,它是消费-生产者模型的一个典型的代表,producer往消息队列中不断写入消息,而另一端consumer则可以读取或者订阅队列中的消息。
RabbitMQ是MQ产品的典型代表,是一款由Erlang语言开发,基于AMQP协议可复用的企业消息系统。业务上,可以实现服务提供者和消费者之间的数据解耦,提供高可用性的消息传输机制,在实际生产中应用相当广泛。
AMQP:Advanced Message Queue,高级消息队列协议。他是应用层协议的一个开放标准,为面向消息的中间件设计,基于此协议的客户端与消息中间件可传递消息,并不受产品、开发语言等条件的限制。
rabbitMQ的两个核心组件是exchange和queue
运行原理如下图:
RabbitMQ 最初起源于金融系统,用于在分布式系统中存储转发消息,在易用性、扩展性、高可用性等方面表现不俗。具体特点包括:
二、实验环境
系统操作: CentOS7.5 Mininal
IP : 192.168.1.103
三、安装rabbitMQ
添加erlang官方仓库
# vim /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=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[rabbitmq_erlang-source]
name=rabbitmq_erlang-source
baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
####################################################
添加rabbitMQ官方仓库
# rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
# vim /etc/yum.repos.d/rabbitmq.repo
###########################################################
[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/
gpgcheck=0
repo_gpgcheck=0
enabled=1
############################################################
# yum clean all
# yum repolist
# yum list erlang --showduplicates| sort -r
# yum list rabbitmq-server --showduplicates| sort -r
# yum -y install epel-release
# yum -y install erlang socat logrotate
# yum -y install rabbitmq-server-3.7.10
# rpm -ql rabbitmq-server
# rpm -qc rabbitmq-server
启动rabbitMQ
# systemctl start rabbitmq-server
# systemctl enable rabbitmq-server
# systemctl status rabbitmq-server
# cat /etc/passwd
# head -n 20 /var/log/rabbitmq/rabbit@`hostname`.log
# ll -a /var/lib/rabbitmq/
# cat /var/lib/rabbitmq/.erlang.cookie
# ps aux | grep rabbitmq
开启网页管理界面
# rabbitmq-plugins enable rabbitmq_management
# ss -tan | grep 5672
RabbitMQ默认监听端口:
4369 erlang发现端口
5672 client端和server端通信端口
15672 管理界面端口
25672 server间内部通信口
# vim /usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/ebin/rabbit.app
将 {loopback_users, [<<"guest">>]},改为:{loopback_users, []},
原因:rabbitmq从3.3.0开始禁止使用guest/guest权限通过除localhost外的访问
# systemctl restart rabbitmq-server
关闭防火墙
# systemctl stop firewalld
# systemctl disable firewalld
浏览器访问 http://192.168.1.103:15672
默认管理员用户名密码 : guest/guest
四、rabbitMQ命令行操作
学习rabbitmq,原理之后第一个要掌握的就是rabbitmqctl这个命令的用法了,rabbitmq的管理功能最全的就是rabbitmqctl命令,当然还有HTTP API和UI两种管理手段。
# rabbitmqctl --help
# rabbitmqctl status
rabbitMQ 用户与权限
添加用户并授权
# rabbitmqctl add_user admin Admin@123
# rabbitmqctl set_user_tags admin administrator
# rabbitmqctl set_permissions -p "/" admin '.*' '.*' '.*'
# rabbitmqctl list_users
# rabbitmqctl list_user_permissions admin
# rabbitmqctl add_vhost "/test"
# rabbitmqctl add_user test Test@123
# rabbitmqctl set_user_tags test administrator
# rabbitmqctl set_permissions -p "/test" test '.*' '.*' '.*'
# rabbitmqctl list_users
# rabbitmqctl list_user_permissions test
# rabbitmqctl list_permissions -p "/test"
配置用户远程访问
# vim /etc/rabbitmq/rabbitmq.config
###########################################################################
[
{rabbit, [{tcp_listeners, [5672]}, {loopback_users, ["admin"]}]}
].
#############################################################################
# systemctl restart rabbitmq-server
浏览器访问:http://192.168.1.103:15672
admin/Admin@123
五、rabbitMQ配置文件
简单的rabbitMQ应用配置可无需配置文件,只有需要定制复杂应用时,才需要用到配置文件。
如果是用rpm包安装,可从默认docs目录复制配置文件样例:
# cp /usr/share/doc/rabbitmq-server-3.7.10/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
# cat /etc/rabbitmq/rabbitmq.config
配置文件特点:
在rabbitmq 3.7.0 之前,rabbitmq.conf 使用了erlang语法配置格式:
1. 配置文件的语法继承于erlang语言,有点类似json
2. 注释采用%%
3. 注意最后结尾一定要加上.,表示结束,否则启动会报错
在rabbitmq 3.7.0 之后,语法配置格式使用了sysctl 格式:
1. 单个信息都在一行里面
2. 配置信息以key value 的形式保存
3. # 开头表示注释
六、启用SSL安全通讯
Management Plugin
https://www.cnblogs.com/wyt007/p/9086250.html
https://www.rabbitmq.com/management.html#single-listener-https
https://github.com/Berico-Technologies/CMF-AMQP-Configuration
七、参考
rabbitmq的整体架构一览
https://blog.51cto.com/cuidehua/1769486
CentOS7 安装 RabbitMQ 3.7
https://blog.csdn.net/liang_henry/article/details/79584843
rabbitmq/erlang-rpm
https://github.com/rabbitmq/erlang-rpm
Downloading and Installing RabbitMQ
https://www.rabbitmq.com/download.html
https://www.rabbitmq.com/install-rpm.html
Management Plugin
https://www.rabbitmq.com/management.html
Server Documentation
https://www.rabbitmq.com/admin-guide.html
rpm 安装RabbitMQ 3.7.7版本-User can only log in via localhost
https://blog.csdn.net/shenhonglei1234/article/details/82745601
rabbitMQ默认端口记录
https://blog.csdn.net/zhouxianling233/article/details/79623204
rabbitmqctl(8)
https://www.rabbitmq.com/rabbitmqctl.8.html
RabbitMQ手册之rabbitmqctl
//www.greatytc.com/p/61a90fba1d2a
Networking and RabbitMQ
https://www.rabbitmq.com/networking.html
rabbitMQ基础篇
https://blog.csdn.net/ChengDianXiaoCai/article/details/72910333
rabbitMQ管理命令rabbitmqctl详解
https://www.ywnds.com/?p=4738
RabbitMQ :常用命令 与 图形管理 及 用户权限
//www.greatytc.com/p/0964f6c46dc5
RabbitMQ on QingCloud AppCenter 用户手册
https://docs.qingcloud.com/product/big_data/rabbitmq/README.html#%E5%88%9B%E5%BB%BA-rabbitmq
rabbitmqadmin 命令行客户端工具
https://www.rabbitmq.com/management-cli.html
rabbitMQ配置文件
https://www.cnblogs.com/zhming26/p/6140307.html
https://www.rabbitmq.com/configure.html#configuration-file
rabbitmq-server/docs/rabbitmq.conf.example
https://github.com/rabbitmq/rabbitmq-server/blob/master/docs/rabbitmq.conf.example
rabbitmq之配置文件详解
https://www.cnblogs.com/cwp-bg/p/8397639.html
rabbitmq 生产环境配置
https://www.cnblogs.com/operationhome/p/10483840.html
RabbitMQ-官方指南-RabbitMQ配置
http://www.blogjava.net/qbna350816/archive/2016/08/02/431415.html
rabbitMQ消息队列: 启用SSL安全通讯
https://www.cnblogs.com/wyt007/p/9086250.html
CMF - AMQP - Configuration
https://github.com/Berico-Technologies/CMF-AMQP-Configuration
RabbitMQ技术入门与实战
https://blog.csdn.net/Super_RD/column/info/15500