首页 > 其他分享 >消息中间件RabbitMQ_RabbitMQ集群搭建8

消息中间件RabbitMQ_RabbitMQ集群搭建8

时间:2024-04-15 18:00:31浏览次数:24  
标签:rabbit2 rabbit1 root rabbitmq 集群 RabbitMQ 消息中间件 super

一、集群搭建概述

 摘要:实际生产应用中都会采用消息队列的集群方案,如果选择RabbitMQ那么有必要了解下它的集群方案原理

 一般来说,如果只是为了学习RabbitMQ或者验证业务工程的正确性那么在本地环境或者测试环境上使用其单实例部署就可以了,但是出于MQ中间件本身的可靠性、并发性、吞吐量和消息堆积能力等问题的考虑,在生产环境上一般都会考虑使用RabbitMQ的集群方案。

二、集群方案的原理

 RabbitMQ这款消息队列中间件产品本身是基于Erlang编写,Erlang语言天生具备分布式特性(通过同步Erlang集群各节点的magic cookie来实现)。因此,RabbitMQ天然支持Clustering。这使得RabbitMQ本身不需要像ActiveMQ、Kafka那样通过ZooKeeper分别来实现HA方案和保存集群的元数据。集群是保证可靠性的一种方式,同时可以通过水平扩展以达到增加消息吞吐量能力的目的。

  

  很多个RabbitMQ节点,节点之间使用镜像队列的方式来同步节点里的数据。外面用HAProxy进行反向代理。生产者和消费者都访问HAProxy,然后HAProxy代理访问各个RabbitMQ节点。

三、单机多实例部署(伪集群)

 由于某些因素的限制,有时候你不得不在一台机器上去搭建一个rabbitmq集群,这个有点类似zookeeper的单机版。真实生成环境还是要配成多机集群的。有关怎么配置多机集群的可以参考其他的资料,这里主要论述如何在单机中配置多个rabbitmq实例。

主要参考官方文档:https://www.rabbitmq.com/clustering.html

 首先确保RabbitMQ运行没有问题

[root@super ~]# rabbitmqctl status
Status of node rabbit@super ...
[{pid,10232},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.6.5"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.6.5"},
      {webmachine,"webmachine","1.10.3"},
      {mochiweb,"MochiMedia Web Server","2.13.1"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.6.5"},
      {rabbit,"RabbitMQ","3.6.5"},
      {os_mon,"CPO  CXC 138 46","2.4"},
      {syntax_tools,"Syntax tools","1.7"},
      {inets,"INETS  CXC 138 49","6.2"},
      {amqp_client,"RabbitMQ AMQP Client","3.6.5"},
      {rabbit_common,[],"3.6.5"},
      {ssl,"Erlang/OTP SSL application","7.3"},
      {public_key,"Public key infrastructure","1.1.1"},
      {asn1,"The Erlang ASN1 compiler version 4.0.2","4.0.2"},
      {ranch,"Socket acceptor pool for TCP protocols.","1.2.1"},
      {mnesia,"MNESIA  CXC 138 12","4.13.3"},
      {compiler,"ERTS  CXC 138 10","6.0.3"},
      {crypto,"CRYPTO","3.6.3"},
      {xmerl,"XML parser","1.3.10"},
      {sasl,"SASL  CXC 138 11","2.7"},
      {stdlib,"ERTS  CXC 138 10","2.8"},
      {kernel,"ERTS  CXC 138 10","4.2"}]},
 {os,{unix,linux}},
 {erlang_version,
     "Erlang/OTP 18 [erts-7.3] [source] [64-bit] [async-threads:64] [hipe] [kernel-poll:true]\n"},
 {memory,
     [{total,56066752},
      {connection_readers,0},
      {connection_writers,0},
      {connection_channels,0},
      {connection_other,2680},
      {queue_procs,268248},
      {queue_slave_procs,0},
      {plugins,1131936},
      {other_proc,18144280},
      {mnesia,125304},
      {mgmt_db,921312},
      {msg_index,69440},
      {other_ets,1413664},
      {binary,755736},
      {code,27824046},
      {atom,1000601},
      {other_system,4409505}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"}]},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,411294105},
 {disk_free_limit,50000000},
 {disk_free,13270233088},
 {file_descriptors,
     [{total_limit,924},{total_used,6},{sockets_limit,829},{sockets_used,0}]},
 {processes,[{limit,1048576},{used,262}]},
 {run_queue,0},
 {uptime,43651},
 {kernel,{net_ticktime,60}}]

 停止rabbitmq服务

[root@super sbin]# service rabbitmq-server stop
Stopping rabbitmq-server: rabbitmq-server.

 启动第一个节点:

[root@super sbin]# RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=rabbit1 rabbitmq-server start

              RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /var/log/rabbitmq/rabbit1.log
  ######  ##        /var/log/rabbitmq/rabbit1-sasl.log
  ##########
              Starting broker...
 completed with 6 plugins.

 启动第二个节点:

  web管理插件端口占用,所以还要指定其web插件占用的端口号。

[root@super ~]# RABBITMQ_NODE_PORT=5674 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15674}]" RABBITMQ_NODENAME=rabbit2 rabbitmq-server start

              RabbitMQ 3.6.5. Copyright (C) 2007-2016 Pivotal Software, Inc.
  ##  ##      Licensed under the MPL.  See http://www.rabbitmq.com/
  ##  ##
  ##########  Logs: /var/log/rabbitmq/rabbit2.log
  ######  ##        /var/log/rabbitmq/rabbit2-sasl.log
  ##########
              Starting broker...
 completed with 6 plugins.

 结束命令:

rabbitmqctl -n rabbit1 stop
rabbitmqctl -n rabbit2 stop

 rabbit1操作作为主节点:

[root@super ~]# rabbitmqctl -n rabbit1 stop_app  
Stopping node rabbit1@super ...
[root@super ~]# rabbitmqctl -n rabbit1 reset     
Resetting node rabbit1@super ...
[root@super ~]# rabbitmqctl -n rabbit1 start_app
Starting node rabbit1@super ...
[root@super ~]# 

 rabbit2操作为从节点:

[root@super ~]# rabbitmqctl -n rabbit2 stop_app
Stopping node rabbit2@super ...
[root@super ~]# rabbitmqctl -n rabbit2 reset
Resetting node rabbit2@super ...
[root@super ~]# rabbitmqctl -n rabbit2 join_cluster rabbit1@'super' ###''内是主机名换成自己的
Clustering node rabbit2@super with rabbit1@super ...
[root@super ~]# rabbitmqctl -n rabbit2 start_app
Starting node rabbit2@super ...

查看集群状态:

[root@super ~]# rabbitmqctl cluster_status -n rabbit1
Cluster status of node rabbit1@super ...
[{nodes,[{disc,[rabbit1@super,rabbit2@super]}]},
 {running_nodes,[rabbit2@super,rabbit1@super]},
 {cluster_name,<<"rabbit1@super">>},
 {partitions,[]},
 {alarms,[{rabbit2@super,[]},{rabbit1@super,[]}]}]

web监控:

四、集群管理

 

 

五、

 

标签:rabbit2,rabbit1,root,rabbitmq,集群,RabbitMQ,消息中间件,super
From: https://www.cnblogs.com/ajing2018/p/18136622

相关文章

  • 消息中间件RabbitMQ_RabbitMQ应用问题7
    一、RabbitMQ应用问题1、消息可靠性保障消息补偿机制2、消息幂等性保障乐观锁解决方案 二、消息可靠性保障需求: 100%确保消息发送成功 消息补偿:三、消息幂等性保障幂等性指一次和多次请求某一个资源,对于资源本身应该具有同样的结果。也就是说,其......
  • 消息中间件RabbitMQ_RabbitMQ高级特性6
    一、RabbitMQ高级特性消息可靠性投递ConsumerACK消费端限流TTL死信队列延迟队列日志与监控消息可靠性分析与追踪管理二、消息的可靠投递1、模式在使用RabbitMQ的时候,作为消息发送方希望杜绝任何消息丢失或者投递失败场景。RabbitMQ为我们提供了两种方式......
  • docker安装rabbitmq
    //查找镜像dockersearchrabbitmq//默认拉取官方最新版本dockerpullrabbitmq//创建容器,也可直接执行该命令,没有镜像会去先拉取镜像dockerrun-d--namemyrabbitmq-p5672:5672-p15672:15672rabbitmq//进入镜像dockerexec-it容器id/bin/bash//安装UI插件rabb......
  • RabbitMQ 入门:我的思维导图总结
    刚看完尚硅谷的RabbitMQ入门教程,感觉自己对知识点的理解还有些混乱,看完相关面试题后整理了一份简单的思维导图,仅供参考,如有错误,欢迎指正!视频教程:尚硅谷RabbitMQ教程丨快速掌握MQ消息中间件rabbitmq_哔哩哔哩_bilibili1.概览2.具体细节2.1基本概念常见面试题:什......
  • linux环境安装——mysql集群安装复习——主从复制
    1、首先安装mysql: mkdir-p/soft/mysql8mkdir-p/evir/mysql8执行上传文件操作rpm-qa|grepmariadb查询是否有这个文件rpm-e--nodepsmariadb-libs进行删除rpm-qa|grepmariadb查询这个文件是否删干净tar-xf/soft/my......
  • 消息中间件RabbitMQ_RabbitMQ的工作模式4
    一、Workqueues工作队列模式1、模式说明WorkQueues:与入门程序的简单模式相比,多了一个或一些消费端,多个消费端共同消费同一个队列中的消息。应用场景:对于任务过重或任务较多情况使用工作队列可以提高任务处理的速度。2、代码编写WorkQueues与入门程序的简......
  • 丐版sqlserver AlwaysOn集群
    丐版sqlserver集群之前试过docker的,k8s的,然后发现,还是最朴素的是最简单的,希望有大佬能够汉化,他妈的,那些英文看得人要发癫啊。前置准备,参照丐版pxc集群:https://www.cnblogs.com/zwnfdswww/p/18112077如果不关防火墙:打开对应的端口即可:sudofirewall-cmd--zone=public--a......
  • tidb 6.1.4 table cache 导致的集群QPS异常问题
    1.问题现象TIDB日志中频繁的刷以下日志:[2024/03/1309:09:40.542+08:00][WARN][cache.go:205]["lockcachedtableforread"][error="previousstatement:updatemysql.table_cache_metasetlock_type='READ',lease=448342830925742080where......
  • linux环境安装——redis集群安装复习——集群
                  ......
  • 01_在NET中使用RabbitMQ
    1.Linux上安装Docken服务器系统版本以及内核版本:cat/etc/redhat-release查看服务器内核版本:uname-r安装依赖包:yuminstall-yyum-utilsdevice-mapper-persistent-datalvm2设置阿里云镜像源:yum-config-manager--add-repohttps://mirrors.aliyun.com/docker-ce/linu......