RabbitMQ
一、中间件服务相关概念
- AMQP协议:高级消息队列协议
- 路由模型
- direct
- topic
- fan-out
- headers
- broker
- exchange
- binding
- queue
- 中间件的实现
- Qpid, ActiveMQ (apache)
- RabbitMQ
- Kafka
- 0MQ
二、RabbitMQ
1、yum安装(epel)
# yum install rabbitmq-server -y
2、插件管理
# rabbitmq-plugins list #列出所有插件
# rabbitmq-plugins enable rabbitmq_management #启用插件
3、启动服务
# systemctl restart rabbitmq-server.service #监听5672, 15672, 25672
web访问:http://192.168.100.8:15672/ guset/guest
4、配置方式
- 配置变量:网络参数及配置文件路径;
- 配置文件:服务器各组件访问权限、资源限制、插件及集群;
- 运行时参数:集群的运行时参数;
- 环境变量: /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_BASE:数据库和日志文件
RABBITMQ_CONFIG_FILE:配置文件路径;/etc/rabbitmq/rabbitmq
RABBITMQ_LOGS:日志文件
RABBITMQ_NODE_IP_ADDRESS:监听的IP
RABBITMQ_NODE_PORT:监听的端口
RABBITMQ_PLUGINS_DIR:插件目录
RABBITMQ_NODE_NAME:节点名称
- 配置文件
auth_mechanisms:认证机制
default_user
default_pass
default_permission
disk_free_limit
heartbeat
hipe_comlile:定义高性能的编译器
log_levels:{none|error|warning|info}
tcp_listeners:监听的地址和端口 5672
ssl_listeners:基于ssl通信协议监听的地址和端口
vm_memory_high_watermark:内存的高可用标记
- 运行时参数配置:rabbitmqctl
set_parameter
clear_parameter
set_policy
clear_policy
set_vm_memory_high_watermark
- rabbitmqctl命令
~]# rabbitmqctl status
~]# rabbitmqctl start_app
~]# rabbitmqctl stop_app
- 用户管理
~]# rabbitmqctl add_user dongfei 123456
~]# rabbitmqctl set_user_tags dongfei administrator
~]# rabbitmqctl list_users
add_user <username> <password>
delete_user <username>
change_password <username> <newpassword>
clear_password <username>
set_user_tags <username> <tag> ...
list_users
- 权限管理
~]# rabbitmqctl list_permissions
~]# rabbitmqctl set_permissions -p /myhost1 dongfei ".*" ".*" ".*"
~]# rabbitmqctl list_user_permissions dongfei
set_permissions [-p <vhostpath>] <user> <conf> <write> <read>
clear_permissions [-p <vhostpath>] <username>
list_permissions [-p <vhostpath>]
list_user_permissions <username>
- 虚拟主机
~]# rabbitmqctl add_vhost /myhost1
~]# rabbitmqctl list_vhosts
add_vhost <vhostpath>
delete_vhost <vhostpath>
list_vhosts [<vhostinfoitem> ...]
- 交换器组件查看命令
list_queues [-p <vhostpath>] [<queueinfoitem> ...]
list_exchanges [-p <vhostpath>] [<exchangeinfoitem> ...]
list_bindings [-p <vhostpath>] [<bindinginfoitem> ...]
list_connections [<connectioninfoitem> ...]
list_channels [<channelinfoitem> ...]
list_consumers [-p <vhostpath>]
- 其它命令
status broker状态
environment 环境变量
report
eval 执行erlang底层表达式
close_connection <connectionpid> <explanation> 关闭指定连接
trace_on [-p <vhost>] 开启追踪功能
trace_off [-p <vhost>]
set_vm_memory_high_watermark <fraction> 设定内存的高水位标记,默认0.4
三、RabbitMQ Cluster
192.168.100.8 rabbitmq
192.168.100.10 rabbitmq2
- 配置hosts解析
- 时间同步
- rabbitmq节点
[root@rabbitmq ~]# systemctl start rabbitmq-server
[root@rabbitmq ~]# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq ...
[{nodes,[{disc,[rabbit@rabbitmq]}]},
{running_nodes,[rabbit@rabbitmq]},
{cluster_name,<<"rabbit@rabbitmq">>}, #记录这条新消息
{partitions,[]}]
...done.
[root@rabbitmq1 ~]# md5sum /var/lib/rabbitmq/.erlang.cookie
94827f8d9a2fbdc7a7b628c7702d46c8 /var/lib/rabbitmq/.erlang.cookie
- rabbitmq2节点
[root@rabbitmq2 ~]# systemctl start rabbitmq-server
[root@rabbitmq2 ~]# rabbitmqctl stop_app
[root@rabbitmq2 ~]# scp rabbitmq:/var/lib/rabbitmq/.erlang.cookie /var/lib/rabbitmq/
[root@rabbitmq2 ~]# md5sum /var/lib/rabbitmq/.erlang.cookie
94827f8d9a2fbdc7a7b628c7702d46c8 /var/lib/rabbitmq/.erlang.cookie
[root@rabbitmq2 ~]# rabbitmqctl join_cluster rabbit@rabbitmq
[root@rabbitmq2 ~]# rabbitmqctl start_app
[root@rabbitmq2 ~]# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq2 ...
[{nodes,[{disc,[rabbit@rabbitmq,rabbit@rabbitmq2]}]},
{running_nodes,[rabbit@rabbitmq,rabbit@rabbitmq2]},
{cluster_name,<<"rabbit@rabbitmq">>}, #这里的集群变成了rabbit@rabbitmq就可以了
{partitions,[]}]
...done.
- 集群相关命令
join_cluster <clusternode> [--ram]
cluster_status
change_cluster_node_type disc | ram
forget_cluster_node [--offline]
update_cluster_nodes clusternode
sync_queue queue
cancel_sync_queue queue
set_cluster_name name