当前位置: 首页 > news >正文

docker集群

一、创建文件夹

mkdir /mydata/rabbitmq
cd rabbitmq/
mkdir rabbitmq01 rabbitmq02 rabbitmq03

二、创建第一个节点

docker run -d --hostname rabbitmq01 --name rabbitmq01 -v /mydata/rabbitmq/rabbitmq01:/var/lib/rabbitmq -p 15673:15672 -p 5673:5672 -e RABBITMQ_ERLANG_COOKIE='atguigu' rabbitmq:management

三、启动第二个节点

docker run -d --hostname rabbitmq02 --name rabbitmq02 -v /mydata/rabbitmq/rabbitmq02:/var/lib/rabbitmq -p 15674:15672 -p 5674:5672 -e RABBITMQ_ERLANG_COOKIE='atguigu' --link rabbitmq01:rabbitmq01 rabbitmq:management

四、启动第三个节点

docker run -d --hostname rabbitmq03 --name rabbitmq03 -v /mydata/rabbitmq/rabbitmq03:/var/lib/rabbitmq -p 15675:15672 -p 5675:5672 -e RABBITMQ_ERLANG_COOKIE='atguigu' --link rabbitmq01:rabbitmq01 --link rabbitmq02:rabbitmq02 rabbitmq:management

五、访问

默认帐号密码都是guest

六、配置集群

这三个节点都准备好了。接下来就来配置集群。

第一步:先在进入rabbitmq01

进入rabbitmq01以后使用rabbitmqctl这个命令,把01的相关信息来初始化一下

rabbitmqctl可以操作rabbit MQ当前节点,比如现在来先来操作rabbitmq01

docker exec -it rabbitmq01 /bin/bash
#暂停一下当前的这个应用
rabbitmqctl stop_app 
#重置应用,如果你这个是刚新建的,就不用重置了,相当于恢复出厂设置
rabbitmqctl reset
#开启应用
rabbitmqctl start_app

第二步:进入rabbitmq02

docker exec -it rabbitmq02 /bin/bash
rabbitmqctl stop_app 
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbitmq01
rabbitmqctl start_app

第三步:进入rabbitmq03

docker exec -it rabbitmq03 /bin/bash
rabbitmqctl stop_app 
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbitmq01
rabbitmqctl start_app

全部的操作如下:

[root@vbox rabbitmq]# docker exec -it rabbitmq01 /bin/bash
root@rabbitmq01:/# rabbitmqctlUsagerabbitmqctl [--node <node>] [--timeout <timeout>] [--longnames] [--quiet] <command> [<command options>]Available commands:Help:autocomplete                                  Provides command name autocomplete variantshelp                                          Displays usage information for a commandversion                                       Displays CLI tools versionNodes:await_startup                                 Waits for the RabbitMQ application to start on the target nodereset                                         Instructs a RabbitMQ node to leave the cluster and return to its virgin staterotate_logs                                   Does nothing [deprecated]shutdown                                      Stops RabbitMQ and its runtime (Erlang VM). Monitors progress for local nodes. Does not require a PID file path.start_app                                     Starts the RabbitMQ application but leaves the runtime (Erlang VM) runningstop                                          Stops RabbitMQ and its runtime (Erlang VM). Requires a local node pid file path to monitor progress.stop_app                                      Stops the RabbitMQ application, leaving the runtime (Erlang VM) runningwait                                          Waits for RabbitMQ node startup by monitoring a local PID file. See also 'rabbitmqctl await_online_nodes'Cluster:await_online_nodes                            Waits for <count> nodes to join the clusterchange_cluster_node_type                      Changes the type of the cluster nodecluster_status                                Displays all the nodes in the cluster grouped by node type, together with the currently running nodesforce_boot                                    Forces node to start even if it cannot contact or rejoin any of its previously known peersforce_reset                                   Forcefully returns a RabbitMQ node to its virgin stateforce_standalone_khepri_boot                  Forces node to start as a standalone nodeforget_cluster_node                           Removes a node from the clusterjoin_cluster                                  Instructs the node to become a member of the cluster that the specified node is inUsers:add_user                                      Creates a new user in the internal database. This user will have no permissions for any virtual hosts by default.authenticate_user                             Attempts to authenticate a user. Exits with a non-zero code if authentication fails.change_password                               Changes the user passwordclear_password                                Clears (resets) password and disables password login for a userclear_user_limits                             Clears user connection/channel limitsdelete_user                                   Removes a user from the internal database. Has no effect on users provided by external backends such as LDAPlist_user_limits                              Displays configured user limitslist_users                                    List user names and tagsset_user_limits                               Sets user limitsset_user_tags                                 Sets user tagsAccess Control:clear_permissions                             Revokes user permissions for a vhostclear_topic_permissions                       Clears user topic permissions for a vhost or exchangelist_permissions                              Lists user permissions in a virtual hostlist_topic_permissions                        Lists topic permissions in a virtual hostlist_user_permissions                         Lists permissions of a user across all virtual hostslist_user_topic_permissions                   Lists user topic permissionslist_vhosts                                   Lists virtual hostsset_permissions                               Sets user permissions for a vhostset_permissions_globally                      Sets user permissions for all virtual hosts.set_topic_permissions                         Sets user topic permissions for an exchangeMonitoring, observability and health checks:activate_free_disk_space_monitoring           [Re-]activates free disk space monitoring on a nodecheck_if_any_deprecated_features_are_used     Generate a report listing all deprecated features in usedeactivate_free_disk_space_monitoring         Deactivates free disk space monitoring on a nodelist_bindings                                 Lists all bindings on a vhostlist_channels                                 Lists all channels in the nodelist_ciphers                                  Lists cipher suites supported by encoding commandslist_connections                              Lists AMQP connections for the nodelist_consumers                                Lists all consumers for a vhostlist_exchanges                                Lists exchangeslist_hashes                                   Lists hash functions supported by encoding commandslist_node_auth_attempt_stats                  Lists authentication attempts on the target nodelist_queues                                   Lists queues and their propertieslist_unresponsive_queues                      Tests queues to respond within timeout. Lists those which did not respondping                                          Checks that the node OS process is up, registered with EPMD and CLI tools can authenticate with itreport                                        Generate a server status report containing a concatenation of all server status information for support purposesschema_info                                   Lists schema database tables and their propertiesstatus                                        Displays status of a nodeParameters:clear_global_parameter                        Clears a global runtime parameterclear_parameter                               Clears a runtime parameter.list_global_parameters                        Lists global runtime parameterslist_parameters                               Lists runtime parameters for a virtual hostset_global_parameter                          Sets a runtime parameter.set_parameter                                 Sets a runtime parameter.Policies:clear_operator_policy                         Clears an operator policyclear_policy                                  Clears (removes) a policylist_operator_policies                        Lists operator policy overrides for a virtual hostlist_policies                                 Lists all policies in a virtual hostset_operator_policy                           Sets an operator policy that overrides a subset of arguments in user policiesset_policy                                    Sets or updates a policyVirtual hosts:add_vhost                                     Creates a virtual hostclear_vhost_limits                            Clears virtual host limitsdelete_vhost                                  Deletes a virtual hostdisable_vhost_deletion_protection             Removes deletion protection from a virtual host (so that it can be deleted)enable_vhost_deletion_protection              Protects a virtual host from deletion (until the protection is removed)list_vhost_limits                             Displays configured virtual host limitsreconcile_vhosts                              Makes sure all virtual hosts were initialized on all reachable cluster nodesrestart_vhost                                 Restarts a failed vhost data stores and queuesset_vhost_limits                              Sets virtual host limitsset_vhost_tags                                Sets virtual host tagstrace_off                                     trace_on                                      update_vhost_metadata                         Updates metadata (tags, description, default queue type, protection from deletion) a virtual hostQueues:delete_queue                                  Deletes a queuepurge_queue                                   Purges a queue (removes all messages in it)Configuration and Environment:decode                                        Decrypts an encrypted advanced.config valuedecrypt_conf_value                            Decrypts an encrypted configuration valueencode                                        Encrypts a sensitive configuration value to be used in the advanced.config fileencrypt_conf_value                            Encrypts a sensitive configuration value to be used in the advanced.config fileenvironment                                   Displays the name and value of each variable in the application environment for each running applicationset_cluster_name                              Sets the cluster nameset_disk_free_limit                           Sets the disk_free_limit settingset_log_level                                 Sets log level in the running nodeset_vm_memory_high_watermark                  Sets the vm_memory_high_watermark settingFeature flags:enable_feature_flag                           Enables a feature flag or all supported feature flags on the target nodelist_deprecated_features                      Lists deprecated featureslist_feature_flags                            Lists feature flagsOperations:close_all_connections                         Instructs the broker to close all connections for the specified vhost or entire RabbitMQ nodeclose_all_user_connections                    Instructs the broker to close all connections of the specified userclose_connection                              Instructs the broker to close the connection associated with the Erlang process ideval                                          Evaluates a snippet of Erlang code on the target nodeeval_file                                     Evaluates a file that contains a snippet of Erlang code on the target nodeexec                                          Evaluates a snippet of Elixir code on the CLI nodeforce_gc                                      Makes all Erlang processes on the target node perform/schedule a full sweep garbage collectionremove_classic_queue_mirroring_from_policies  Removes keys that enable classic queue mirroring from all regular and operator policiesresume_listeners                              Resumes client connection listeners making them accept client connections againsuspend_listeners                             Suspends client connection listeners so that no new client connections are acceptedDefinitions:export_definitions                            Exports definitions in JSON or compressed Erlang Term Format.import_definitions                            Imports definitions in JSON or compressed Erlang Term Format.Management plugin:reset_stats_db                                Resets statistics database. This will remove all metrics data!Other:hash_password                                 Hashes a plaintext passwordDeprecated:node_health_check                             DEPRECATED. This command is a no-op. See https://www.rabbitmq.com/monitoring.html#health-checksrename_cluster_node                           DEPRECATED. This command is a no-op. Node renaming is incompatible with Raft-based features such as quorum queues, streams, Khepri. update_cluster_nodes                          DEPRECATED. This command is a no-op. Node update is incompatible with Raft-based features such as quorum queues, streams, Khepri. Use 'rabbitmqctl help <command>' to learn more about a specific command
root@rabbitmq01:/# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbitmq01 ...
root@rabbitmq01:/# rabbitmqctl reset
Resetting node rabbit@rabbitmq01 ...
root@rabbitmq01:/# rabbitmqctl start_app
Starting node rabbit@rabbitmq01 ...
root@rabbitmq01:/# exit
exit
[root@vbox rabbitmq]# docker exec -it rabbitmq02 /bin/bash
root@rabbitmq02:/# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbitmq02 ...
root@rabbitmq02:/# rabbitmqctl reset
Resetting node rabbit@rabbitmq02 ...
root@rabbitmq02:/# rabbitmqctl join_cluster --ram rabbit@rabbitmq01
Clustering node rabbit@rabbitmq02 with rabbit@rabbitmq01
root@rabbitmq02:/# rabbitmqctl start_app
Starting node rabbit@rabbitmq02 ...
root@rabbitmq02:/# exit
exit
[root@vbox rabbitmq]# docker exec -it rabbitmq03 /bin/bash
root@rabbitmq03:/# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbitmq03 ...
root@rabbitmq03:/# rabbitmqctl reset
Resetting node rabbit@rabbitmq03 ...
root@rabbitmq03:/# rabbitmqctl join_cluster --ram rabbit@rabbitmq01
Clustering node rabbit@rabbitmq03 with rabbit@rabbitmq01
root@rabbitmq03:/# rabbitmqctl start_app
Starting node rabbit@rabbitmq03 ...
root@rabbitmq03:/# exit
exit
[root@vbox rabbitmq]# 

七、测试集群

随便访问一个节点

八、配置集群镜像(3.8以后废弃了这个东西)

现在默认还是普通的镜像,即数据只有在存在三个节点之一,不能解决单点故障的问题,镜像模式就是数据在每个节点都保存,实现了高可用

docker exec -it rabbitmq01 /bin/bash
rabbitmqctl set_policy -p / ha "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}' 
rabbitmqctl list_policies -p /

这里我的版本是4.1.2,所以我就没有设置这一步

九、测试集群

进入01节点

添加一个队列

发现02 03节点也都有这个队列,包括给队列存消息,三个节点都能看到这个消息,消费后都看不到这个消息了

官方文档(英文):RabbitMQ Documentation | RabbitMQ

 官方文档(中文):RabbitMQ 文档 | RabbitMQ 消息队列

http://www.lryc.cn/news/617155.html

相关文章:

  • 在Linux中部署tomcat
  • MyBatis高级特性与性能优化:从入门到精通的实战指南
  • NEON性能优化总结
  • EXISTS 替代 IN 的性能优化技巧
  • Unity大型场景性能优化全攻略:PC与安卓端深度实践 - 场景管理、渲染优化、资源调度 C#
  • C# 异步编程(BeginInvoke和EndInvoke)
  • openEuler、 CentOS、Ubuntu等 Linux 系统中,Docker 常用命令总结
  • Selenium经典面试题 - 多窗口切换解决方案
  • 深入解析游戏引擎(OGRE引擎)通用属性系统:基于Any类的类型安全动态属性设计
  • 如何在 Ubuntu 24.04 LTS Linux 上安装和使用 Flatpak
  • 游戏引擎(Unreal Engine、Unity、Godot等)大对比:选择最适合你的工具
  • [Ubuntu] VNC连接Linux云服务器 | 实现GNOME图形化
  • 从零开始的云计算生活——项目实战容器化
  • Ubuntu 22.04 离线环境下 Python 包与 FFmpeg 安装全攻略​
  • Python 爬虫:Selenium 自动化控制(Headless 模式 / 无痕浏览)
  • 使用Windbg分析多线程死锁项目实战问题分享
  • 从零开始的云计算生活——第四十一天,勇攀高峰,Kubernetes模块之单Master集群部署
  • 数据结构 双链表与LinkedList
  • 云原生环境Prometheus企业级监控
  • 浅谈 LangGraph 子图流式执行(subgraphs=True/False)模式
  • redis(2)-java客户端使用(IDEA基于springboot)
  • Selenium动态元素定位
  • glide缓存策略和缓存命中
  • 探秘华为:松山湖的科技与浪漫之旅
  • 打烊:餐厅开业前的“压力测试”
  • 《汇编语言:基于X86处理器》第13章 高级语言接口(1)
  • 前端实现 MD5 + AES 加密的安全登录请求
  • JVM基础【Java】
  • leetcode-hot-100 (图论)
  • 心理咨询|学生心理咨询评估系统|基于Springboot的学生心理咨询评估系统设计与实现(源码+数据库+文档)