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

RabbitMQ集群配置以及负载均衡配置

RabbitMQ集群配置以及负载均衡配置

    • 环境配置
    • 集群配置
      • 安装rabbitmq
        • 启动rabbitmq
        • 开启远程登录
        • 添加用户并且授权用户
        • 添加数据存放目录和日志存放目录
        • 查看端口
        • 拷⻉erlang.cookie
        • 将mq-2、mq-3作为内存节点加⼊mq-1节点集群中
        • 查看集群状态
        • 添加一个新的队列
    • RabbitMq负载均衡配置-HAProxy
        • 安装HAProxy
        • 修改配置文件
        • 登录haproxy
        • mysql授权root用户远程登录

环境配置

服务器ip地址
rabbitmq-1192.168.10.128
rabbitmq-2192.168.10.129
rabbitmq-3192.168.10.130

集群配置

安装rabbitmq

  • 三台机子都配置对应得hosts文件

    [root@localhost ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.10.128 rabbitmq-1
    192.168.10.129 rabbitmq-2
    192.168.10.130 rabbitmq-3
    
  • 三台机子都得安排rabbitmq 目前三台机子都上传了对应得安装包

    [root@localhost ~]# ls
    anaconda-ks.cfg   rabbitmq-server-3.7.10-1.el7.noarch.rpm   erlang-21.3.8.21-1.el7.x86_64.rpm 
    [root@localhost ~]# yum install -y erlang-21.3.8.21-1.el7.x86_64.rpm
    [root@localhost ~]# yum install -y rabbitmq-server-3.7.10-1.el7.noarch.rpm
    
启动rabbitmq
[root@localhost ~]#  systemctl daemon-reload
[root@localhost ~]# systemctl start rabbitmq-server
开启远程登录
[root@localhost ~]# cd /usr/share/doc/rabbitmq-server-3.7.10/
[root@localhost rabbitmq-server-3.7.10]# cp rabbitmq.config.example /etc/rabbitmq
[root@localhost rabbitmq-server-3.7.10]# cd /etc/rabbitmq/
[root@localhost rabbitmq]# ls
enabled_plugins  rabbitmq.config.example
[root@localhost rabbitmq]# mv rabbitmq.config.example  rabbitmq.config
[root@localhost rabbitmq]# vim rabbitmq.config 

修改下面配置文件的内容 第349行

# 开启rabbitmq的web访问界面:
[root@localhost ~]# rabbitmq-plugins enable rabbitmq_management
  • 输入对应的ip即可以登录

    有默认用户guest 密码也是guest

添加用户并且授权用户
[root@localhost ~]# rabbitmqctl add_user root 1
Adding user "root" ...
[root@localhost ~]# rabbitmqctl set_user_tags root administrator
Setting tags for user "root" to [administrator] ...
[root@localhost ~]# rabbitmqctl list_users
Listing users ...
user    tags
guest   [administrator]
root    [administrator]
[root@localhost ~]# rabbitmqctl set_permissions -p "/" root ".*" ".*" ".*"
Setting permissions for user "root" in vhost "/" ...
添加数据存放目录和日志存放目录
[root@localhost ~]# mkdir -p /data/rabbitmq/data
[root@localhost ~]# mkdir -p /data/rabbitmq/logs
[root@localhost ~]# chmod 777 -R /data/rabbitmq
[root@localhost ~]# chown rabbitmq.rabbitmq /data/ -R
创建配置文件:
[root@localhost ~]# vim /etc/rabbitmq/rabbitmq-env.conf
[root@localhost ~]# cat /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_MNESIA_BASE=/data/rabbitmq/data
RABBITMQ_LOG_BASE=/data/rabbitmq/logs
重启服务
[root@localhost ~]# systemctl restart rabbitmq-server
查看端口
[root@localhost ~]# ss -ntlp

1564157344617

4369 – erlang发现端口
5672 --程序连接端口
15672 – 管理界面ui端口
25672 – server间内部通信口

拷⻉erlang.cookie
[root@localhost ~]# cd /var/lib/rabbitmq/
# ⽤scp的⽅式将rabbitmq-1节点的.erlang.cookie的值复制到其他两个节点中。
[root@localhost rabbitmq]# scp .erlang.cookie 192.168.10.129:/var/lib/rabbitmq/
root@192.168.10.129's password: 
.erlang.cookie                                                                                                       100%   20    14.6KB/s   00:00    
[root@localhost rabbitmq]# scp .erlang.cookie 192.168.10.130:/var/lib/rabbitmq/
root@192.168.10.130's password: 
.erlang.cookie

各节点是经由过程⼀个magic cookie来实现的,这个cookie存放在/var/lib/rabbitmq/.erlang.cookie中,⽂件是400的权限。所以必须保证各节点cookie⼀致,不然节点之间就⽆法通信.

(官方在介绍集群的文档中提到过.erlang.cookie 一般会存在这两个地址:第一个是home/.erlang.cookie;第二个地方就是/var/lib/rabbitmq/.erlang.cookie。如果我们使用解压缩方式安装部署的rabbitmq,那么这个文件会在{home}目录下,也就是$home/.erlang.cookie。如果我们使用rpm等安装包方式进行安装的,那么这个文件会在/var/lib/rabbitmq目录下。)

将mq-2、mq-3作为内存节点加⼊mq-1节点集群中
在mq-2、mq-3执⾏如下命令:
[root@localhost ~]# systemctl restart rabbitmq-server
[root@localhost ~]# rabbitmqctl stop_app  #停止节点
[root@localhost ~]# rabbitmqctl reset   #如果有数据需要重置,没有则不用
[root@localhost ~]# rabbitmqctl join_cluster --ram rabbit@rabbitmq-1  #添加到磁盘节点
Clustering node 'rabbit@rabbitmq-2' with 'rabbit@rabbitmq-1' ...
[root@localhost ~]# rabbitmqctl start_app  #启动节点
Starting node 'rabbit@rabbitmq-2' ...
======================================================================
[root@localhost ~]# systemctl restart rabbitmq-server
[root@localhost ~]# rabbitmqctl stop_app
[root@localhost ~]# rabbitmqctl reset
[root@localhost ~]# rabbitmqctl join_cluster --ram rabbit@rabbitmq-1
Clustering node 'rabbit@rabbitmq-3' with 'rabbit@rabbitmq-1' ...
[root@localhost ~]# rabbitmqctl start_app
Starting node 'rabbit@rabbitmq-3' ...(1)默认rabbitmq启动后是磁盘节点,在这个cluster命令下,mq-2和mq-3是内存节点,
mq-1是磁盘节点。
(2)如果要使mq-2、mq-3都是磁盘节点,去掉--ram参数即可。
(3)如果想要更改节点类型,可以使⽤命令rabbitmqctl change_cluster_node_type
disc(ram),前提是必须停掉rabbit应⽤
注:
#如果有需要使用磁盘节点加入集群[root@rabbitmq-2 ~]# rabbitmqctl join_cluster  rabbit@rabbitmq-1[root@rabbitmq-3 ~]# rabbitmqctl join_cluster  rabbit@rabbitmq-1

image-20231108154240796

登录上去有上面这几个即就是添加成功了

查看集群状态
# 在任意一个上面即可查看
在 RabbitMQ 集群任意节点上执行 rabbitmqctl cluster_status来查看是否集群配置成功。
在mq-1磁盘节点上面查看
[root@localhost ~]# rabbitmqctl cluster_status

1564158874154

添加一个新的队列
  • 添加队列

image-20231108154447835

  • 更改为集群可看

    当前这个只有mq-1可用

image-20231108154617880

修改 修改完之后就跟上面得一样了

[root@localhost ~]# rabbitmqctl set_policy  ha-all "^" '{"ha-mode":"all"}'

RabbitMq负载均衡配置-HAProxy

安装HAProxy
[root@localhost ~]# yum install haproxy
修改配置文件
[root@localhost ~]# vim /etc/haproxy/haproxy.cfg
ballog         127.0.0.1 local2chroot      /var/lib/haproxypidfile     /var/run/haproxy.pidmaxconn     4000user        haproxygroup       haproxynbproc      4daemon# turn on stats unix socketstats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
defaultsmode                    httplog                     globalretries                 3timeout connect         10stimeout client          1mtimeout server          1mtimeout check           10smaxconn                 2048
#---------------------------------------------------------------------
##监控查看本地状态#####
listen admin_statsbind *:88mode httpoption httplogoption httpcloselog 127.0.0.1 local0 errstats uri  /haproxystats auth root:1stats refresh 30s
####################################
###反代监控
frontend serverbind *:5670log globalmode tcp#option forwardfordefault_backend rabbitmqmaxconn 3
backend rabbitmqmode        tcplog         globalbalance     roundrobinserver      rabbitmq1 192.168.10.128:5672 check inter 2000s rise 2 fall 3server      rabbitmq2 192.168.10.129:5672 check inter 2000s rise 2 fall 3server      rabbitmq3 192.168.10.130:5672 check inter 2000s rise 2 fall 3[root@localhost ~]# systemctl start haproxy
[root@localhost ~]# ss -ntlp | grep 88
LISTEN     0      128          *:88                       *:*                   users:(("haproxy",pid=17070,fd=5),("haproxy",pid=17069,fd=5),("haproxy",pid=17068,fd=5),("haproxy",pid=17067,fd=5))
登录haproxy

192.168.10.128:88/haproxy

mysql授权root用户远程登录
[root@localhost ~]# mysql -uroot -p'Cjb@1234'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.42 MySQL Community Server (GPL)Copyright (c) 2000, 2023, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> grant all on *.* to 'root'@'%' identified by 'Cjb@1234';
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> \q
Bye

相关文章:

RabbitMQ集群配置以及负载均衡配置

RabbitMQ集群配置以及负载均衡配置 环境配置集群配置安装rabbitmq启动rabbitmq开启远程登录添加用户并且授权用户添加数据存放目录和日志存放目录查看端口拷⻉erlang.cookie将mq-2、mq-3作为内存节点加⼊mq-1节点集群中查看集群状态添加一个新的队列 RabbitMq负载均衡配置-HAPr…...

Leetcode Hot100之六:42.接雨水

题目 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图&#xff0c;计算按此排列的柱子&#xff0c;下雨之后能接多少雨水。 提示&#xff1a; n height.length 1 < n < 2 * 10^4 0 < height[i] < 10^5 思路 暴力循环&#xff1a; 原本的思路是左边界i从左到…...

electron 主进程 和 渲染进程通信 ipcRenderer 和 mainWindow.webContents

electron 开发时最麻烦就是electron版本和node版本的选择和正确安装 electron 用npm安装时太慢容易报错&#xff0c;建议用cnpm i 进行安装 注意最新版渲染进程使用node nodeIntegration: true, // 渲染进程可用node contextIsolation: false, // 这个值影响nodeIntegration是…...

关于VUE启动内存溢出

安装node v10.14.2 后 启动公司的VUE项目 使用命令npm run dev 命令 报错&#xff1a; <--- Last few GCs --->[20940:00000244699848E0] 215872 ms: Scavenge 1690.2 (1836.4) -> 1679.6 (1836.4) MB, 5.4 / 0.7 ms (average mu 0.266, current mu 0.253) a…...

HBase学习笔记(1)—— 知识点总结

目录 HBase概述 HBase 基本架构 HBase安装部署启动 HBase Shell HBase数据读写流程 HBase 优化 HBase概述 HBase是以 hdfs 为数据存储的&#xff0c;一种分布式、非关系型的、可扩展的 NoSQL 数据库 关系型数据库和非关系型数据库的区别&#xff1a; 关系型数据库和非关…...

【Linux】 awk命令使用

AWK 是一种处理文本文件的语言&#xff0c;是一个强大的文本分析工具。 之所以叫 AWK 是因为其取了三位创始人 Alfred Aho&#xff0c;Peter Weinberger, 和 Brian Kernighan 的 Family Name 的首字符。 语法 awk [选项] [文件] awk [选项] [程序] [文件] awk命令 -Linux手…...

Sentinel网关限流

背景 在微服务架构下&#xff0c;每个服务的性能都不同&#xff0c;为避免出现流量洪峰将服务冲垮&#xff0c;需要依赖限流工具来保护服务的稳定性。sentinel是阿里提供的限流工具&#xff0c;社区活跃&#xff0c;功能也很全面&#xff0c;包含实时监控、流控、熔断等功能。…...

solidworks对电脑要求高吗?2023solidworks配置要求

solidworks对电脑要求高吗&#xff1f;SolidWorks是一款功能强大的三维CAD软件&#xff0c;对电脑配置有一定的要求。一般来说&#xff0c;运行SolidWorks需要的电脑配置包括较高的处理器性能、足够的内存和存储空间&#xff0c;以及一块性能良好的显卡。此外&#xff0c;对于大…...

搭建神经网络(torch.nn的用法)

零零碎碎总结了一些torch框架里面nn模块的用法&#xff0c;尤其是关于搭建神经网络的 nn.ModuleList nn.Module nn.Sequential nn.Linear nn.Dropout nn.Embedding nn.DataParallel() 将模型封装起来&#xff0c;便于在多个gpu上并行计算&#xff0c;训练或者推理 nn.…...

卡码网语言基础课 | 11. 句子缩写

目录 一、 字符串大小的比较 二、 ASCII码值 三、 基本框架代码 四、 解题思路 4.1 首字母问题 4.2 判定小写字母 4.3 小写字母转换为大写字母 五、空格判断 六、 代码模块化 6.1 满足的条件 6.2 代码完善 七、 题目解答 7.1 原始代码 7.2 改进代码 八、 拓展与…...

Surface RT 安装 Linux

零&#xff1a;起因 在家无事找出来一台老旧设备 Surface RT 一代的&#xff0c;系统最新是 Windows 8.1 arm版&#xff0c;应用商店都已经打不开了 虽说有破解方法&#xff0c;能运行些软件&#xff0c;但怎么说也不是任意安装&#xff0c;所以局限性还是相当的大&#xff0…...

C++中的函数重载:多功能而强大的特性

引言 函数重载是C编程语言中的一项强大特性&#xff0c;它允许在同一个作用域内定义多个同名函数&#xff0c;但这些函数在参数类型、个数或顺序上有所不同。本文将深入探讨函数重载的用法&#xff0c;以及它的优势和应用场景。 正文 在C中&#xff0c;函数重载是一项非常有…...

数据分析实战 | K-means算法——蛋白质消费特征分析

目录 一、数据及分析对象 二、目的及分析任务 三、方法及工具 四、数据读入 五、数据理解 六、数据准备 七、模型训练 ​编辑 八、模型评价 九、模型调参与预测 一、数据及分析对象 txt文件——“protein.txt”&#xff0c;主要记录了25个国家的9个属性&#xff0c;主…...

HTTP协议详解-下(Tomcat)

如何构造 HTTP 请求 对于 GET 请求 地址栏直接输入点击收藏夹html 里的 link script img a…form 标签 通过 form 标签构造GET请求 <body><!-- 表单标签, 允许用户和服务器之间交互数据 --><!-- 提交的数据报以键值对的结果来组织 --><form action&quo…...

acwing算法基础之搜索与图论--prim算法

目录 1 基础知识2 模板3 工程化 1 基础知识 朴素版prim算法的关键步骤&#xff1a; 初始化距离数组dist&#xff0c;将其内的所有元素都设为正无穷大。定义集合S&#xff0c;表示生成树。循环n次&#xff1a;找到不在集合S中且距离集合S最近的结点t&#xff0c;用它去更新剩余…...

Amazon EC2 Serial Console 现已在其他亚马逊云科技区域推出

即日起&#xff0c;交互式 EC2 Serial Console 现也在以下区域推出&#xff1a;中东&#xff08;巴林&#xff09;、亚太地区&#xff08;雅加达&#xff09;、非洲&#xff08;开普敦&#xff09;、中东&#xff08;阿联酋&#xff09;、亚太地区&#xff08;香港&#xff09;…...

hdlbits系列verilog解答(100输入逻辑门)-39

文章目录 一、问题描述二、verilog源码三、仿真结果一、问题描述 构建一个具有 100 个输入in[99:0]的组合电路。 有 3 个输出: out_and: output of a 100-input AND gate. out_or: output of a 100-input OR gate. out_xor: output of a 100-input XOR gate. 二、verilog源…...

Python 中 Selenium 的屏幕截图

文章目录 使用 save_screenshot() 函数在 Python 中使用 selenium 捕获屏幕截图使用 get_screenshot_as_file() 函数在 Python 中使用 selenium 捕获屏幕截图使用 Screenshot-Selenium 包在 Python 中使用 selenium 捕获屏幕截图总结我们可以使用 Selenium 在自动化 Web 浏览器…...

scrapy发json的post请求

一 、scrapy发json的post请求&#xff1a; def start_requests(self):self.headers {Content-Type: application/json}json_data {"productName": "", "currentPage": "1", "recordNumber": "10", "langua…...

一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

目录 1解题思路&#xff1a; 2代码如下&#xff1a; 3运行结果&#xff1a; 4总结&#xff1a; 5介绍&#xff1a; 1解题思路&#xff1a; 利用循环&#xff08;穷举法&#xff09;来 对 所 需要的数 进行确定 2代码如下&#xff1a; #include <stdio.h>int main() …...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

C++实现分布式网络通信框架RPC(3)--rpc调用端

目录 一、前言 二、UserServiceRpc_Stub 三、 CallMethod方法的重写 头文件 实现 四、rpc调用端的调用 实现 五、 google::protobuf::RpcController *controller 头文件 实现 六、总结 一、前言 在前边的文章中&#xff0c;我们已经大致实现了rpc服务端的各项功能代…...

大数据零基础学习day1之环境准备和大数据初步理解

学习大数据会使用到多台Linux服务器。 一、环境准备 1、VMware 基于VMware构建Linux虚拟机 是大数据从业者或者IT从业者的必备技能之一也是成本低廉的方案 所以VMware虚拟机方案是必须要学习的。 &#xff08;1&#xff09;设置网关 打开VMware虚拟机&#xff0c;点击编辑…...

HTML 列表、表格、表单

1 列表标签 作用&#xff1a;布局内容排列整齐的区域 列表分类&#xff1a;无序列表、有序列表、定义列表。 例如&#xff1a; 1.1 无序列表 标签&#xff1a;ul 嵌套 li&#xff0c;ul是无序列表&#xff0c;li是列表条目。 注意事项&#xff1a; ul 标签里面只能包裹 li…...

376. Wiggle Subsequence

376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...

【服务器压力测试】本地PC电脑作为服务器运行时出现卡顿和资源紧张(Windows/Linux)

要让本地PC电脑作为服务器运行时出现卡顿和资源紧张的情况&#xff0c;可以通过以下几种方式模拟或触发&#xff1a; 1. 增加CPU负载 运行大量计算密集型任务&#xff0c;例如&#xff1a; 使用多线程循环执行复杂计算&#xff08;如数学运算、加密解密等&#xff09;。运行图…...

HTML前端开发:JavaScript 常用事件详解

作为前端开发的核心&#xff0c;JavaScript 事件是用户与网页交互的基础。以下是常见事件的详细说明和用法示例&#xff1a; 1. onclick - 点击事件 当元素被单击时触发&#xff08;左键点击&#xff09; button.onclick function() {alert("按钮被点击了&#xff01;&…...

QT: `long long` 类型转换为 `QString` 2025.6.5

在 Qt 中&#xff0c;将 long long 类型转换为 QString 可以通过以下两种常用方法实现&#xff1a; 方法 1&#xff1a;使用 QString::number() 直接调用 QString 的静态方法 number()&#xff0c;将数值转换为字符串&#xff1a; long long value 1234567890123456789LL; …...

vue3+vite项目中使用.env文件环境变量方法

vue3vite项目中使用.env文件环境变量方法 .env文件作用命名规则常用的配置项示例使用方法注意事项在vite.config.js文件中读取环境变量方法 .env文件作用 .env 文件用于定义环境变量&#xff0c;这些变量可以在项目中通过 import.meta.env 进行访问。Vite 会自动加载这些环境变…...

关键领域软件测试的突围之路:如何破解安全与效率的平衡难题

在数字化浪潮席卷全球的今天&#xff0c;软件系统已成为国家关键领域的核心战斗力。不同于普通商业软件&#xff0c;这些承载着国家安全使命的软件系统面临着前所未有的质量挑战——如何在确保绝对安全的前提下&#xff0c;实现高效测试与快速迭代&#xff1f;这一命题正考验着…...