当前位置: 首页 > 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() …...

2021-03-15 iview一些问题

1.iview 在使用tree组件时&#xff0c;发现没有set类的方法&#xff0c;只有get&#xff0c;那么要改变tree值&#xff0c;只能遍历treeData&#xff0c;递归修改treeData的checked&#xff0c;发现无法更改&#xff0c;原因在于check模式下&#xff0c;子元素的勾选状态跟父节…...

C++.OpenGL (10/64)基础光照(Basic Lighting)

基础光照(Basic Lighting) 冯氏光照模型(Phong Lighting Model) #mermaid-svg-GLdskXwWINxNGHso {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-GLdskXwWINxNGHso .error-icon{fill:#552222;}#mermaid-svg-GLd…...

【HarmonyOS 5 开发速记】如何获取用户信息(头像/昵称/手机号)

1.获取 authorizationCode&#xff1a; 2.利用 authorizationCode 获取 accessToken&#xff1a;文档中心 3.获取手机&#xff1a;文档中心 4.获取昵称头像&#xff1a;文档中心 首先创建 request 若要获取手机号&#xff0c;scope必填 phone&#xff0c;permissions 必填 …...

【电力电子】基于STM32F103C8T6单片机双极性SPWM逆变(硬件篇)

本项目是基于 STM32F103C8T6 微控制器的 SPWM(正弦脉宽调制)电源模块,能够生成可调频率和幅值的正弦波交流电源输出。该项目适用于逆变器、UPS电源、变频器等应用场景。 供电电源 输入电压采集 上图为本设计的电源电路,图中 D1 为二极管, 其目的是防止正负极电源反接, …...

【MATLAB代码】基于最大相关熵准则(MCC)的三维鲁棒卡尔曼滤波算法(MCC-KF),附源代码|订阅专栏后可直接查看

文章所述的代码实现了基于最大相关熵准则(MCC)的三维鲁棒卡尔曼滤波算法(MCC-KF),针对传感器观测数据中存在的脉冲型异常噪声问题,通过非线性加权机制提升滤波器的抗干扰能力。代码通过对比传统KF与MCC-KF在含异常值场景下的表现,验证了后者在状态估计鲁棒性方面的显著优…...

深入理解Optional:处理空指针异常

1. 使用Optional处理可能为空的集合 在Java开发中&#xff0c;集合判空是一个常见但容易出错的场景。传统方式虽然可行&#xff0c;但存在一些潜在问题&#xff1a; // 传统判空方式 if (!CollectionUtils.isEmpty(userInfoList)) {for (UserInfo userInfo : userInfoList) {…...

阿里云Ubuntu 22.04 64位搭建Flask流程(亲测)

cd /home 进入home盘 安装虚拟环境&#xff1a; 1、安装virtualenv pip install virtualenv 2.创建新的虚拟环境&#xff1a; virtualenv myenv 3、激活虚拟环境&#xff08;激活环境可以在当前环境下安装包&#xff09; source myenv/bin/activate 此时&#xff0c;终端…...

boost::filesystem::path文件路径使用详解和示例

boost::filesystem::path 是 Boost 库中用于跨平台操作文件路径的类&#xff0c;封装了路径的拼接、分割、提取、判断等常用功能。下面是对它的使用详解&#xff0c;包括常用接口与完整示例。 1. 引入头文件与命名空间 #include <boost/filesystem.hpp> namespace fs b…...

【java面试】微服务篇

【java面试】微服务篇 一、总体框架二、Springcloud&#xff08;一&#xff09;Springcloud五大组件&#xff08;二&#xff09;服务注册和发现1、Eureka2、Nacos &#xff08;三&#xff09;负载均衡1、Ribbon负载均衡流程2、Ribbon负载均衡策略3、自定义负载均衡策略4、总结 …...

未授权访问事件频发,我们应当如何应对?

在当下&#xff0c;数据已成为企业和组织的核心资产&#xff0c;是推动业务发展、决策制定以及创新的关键驱动力。然而&#xff0c;未授权访问这一隐匿的安全威胁&#xff0c;正如同高悬的达摩克利斯之剑&#xff0c;时刻威胁着数据的安全&#xff0c;一旦触发&#xff0c;便可…...