Haproxy+Keepalived实现RabbtMQ Cluster高可用

系统架构

                                          |
                                  [VIP:11.1.1.100]	
+---------+-------------------------------+-------------------------------+----------+
          |                               |                               |
+---------+------------+                  |                   +----------------------+
| [  HAProxy Node #1 ] |                  |                   | [  HAProxy Node #2 ] |
|    ha1.sumail.com    |                  |                   |    ha2.sumail.com    |
|      11.1.1.61       |                  |                   |      11.1.1.62       |
+----------------------+                  |                   +----------------------+
                                          |                                
+---------+-------------------------------+-------------------------------+----------+
          |                               |                               |
+---------+------------+       +----------+-----------+       +-----------+----------+
| [  Cluster Node #1 ] |       | [  Cluster Node #2 ] |       | [  Cluster Node #3 ] |
|   node1.sumail.com   +<------+   node2.sumail.com   +<------+   node3.sumail.com   |
|      11.1.1.51       |       |      11.1.1.52       |       |      11.1.1.53       |
+----------------------+       +----------------------+       +----------------------+

系统环境配置

[root@ha1 ~]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

11.1.1.51   node1 node1.sumail.com
11.1.1.52   node2 node2.sumail.com
11.1.1.53   node3 node3.sumail.com

11.1.1.61   ha1   ha1.sumail.com
11.1.1.62   ha2   ha2.sumail.com                             


[root@ha1 ~]# scp /etc/hosts ha2:/etc/hosts
The authenticity of host 'ha2 (11.1.1.62)' can't be established.
ED25519 key fingerprint is SHA256:BQD837RdlkpurpiYQYlLVeWNmk1zRFwIjeHo7YnMcfk.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ha2' (ED25519) to the list of known hosts.
root@ha2's password: 
hosts                                                                                                                                                                          100%  331   322.6KB/s   00:00    
[root@ha1 ~]# scp /etc/hosts node1:/etc/hosts
The authenticity of host 'node1 (11.1.1.51)' can't be established.
ED25519 key fingerprint is SHA256:BQD837RdlkpurpiYQYlLVeWNmk1zRFwIjeHo7YnMcfk.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: ha2
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'node1' (ED25519) to the list of known hosts.
root@node1's password: 
hosts                                                                                                                                                                          100%  331   116.5KB/s   00:00    
[root@ha1 ~]# scp /etc/hosts node2:/etc/hosts
The authenticity of host 'node2 (11.1.1.52)' can't be established.
ED25519 key fingerprint is SHA256:BQD837RdlkpurpiYQYlLVeWNmk1zRFwIjeHo7YnMcfk.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: ha2
    ~/.ssh/known_hosts:4: node1
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'node2' (ED25519) to the list of known hosts.
root@node2's password: 
hosts                                                                                                                                                                          100%  331   248.3KB/s   00:00    
[root@ha1 ~]# scp /etc/hosts node3:/etc/hosts
The authenticity of host 'node3 (11.1.1.53)' can't be established.
ED25519 key fingerprint is SHA256:BQD837RdlkpurpiYQYlLVeWNmk1zRFwIjeHo7YnMcfk.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: ha2
    ~/.ssh/known_hosts:4: node1
    ~/.ssh/known_hosts:5: node2
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'node3' (ED25519) to the list of known hosts.
root@node3's password: 
hosts                                                                                                                                                                          100%  331   201.0KB/s   00:00    


RabbitMQ Cluster 安装与配置

安装Haproxy、Keepalived

# ha1
[root@ha1 ~]# dnf install haproxy keepalived -y

# ha2
[root@ha2 ~]# dnf install haproxy keepalived -y

编辑日志配置文件

# 编辑rsyslog配置文件
[root@ha1 ~]# vi /etc/rsyslog.conf

# 取消30行和31行前的注释
module(load="imudp") # needs to be done just once
input(type="imudp" port="514")
# 在32行添加如下内容
$AllowedSender  UDP, 127.0.0.1
 
 # 修改47行
*.info;mail.none;authpriv.none;cron.none;local2.none               /var/log/messages
# 添加48行内容
local2.*                                                           /var/log/haproxy.log


# 复制配置文件到ha2
[root@ha1 ~]# scp /etc/rsyslog.conf ha2:/etc/rsyslog.conf 
root@ha2's password: 
rsyslog.conf 
# 重启rsyslog
[root@ha1 ~]# systemctl restart rsyslog

[root@ha2 ~]# systemctl restart rsyslog

配置Haproxy


# haproxy 配置参考文档:https://docs.haproxy.org/
# 备份配置文件
[root@ha1 ~]# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak

[root@ha1 ~]# vim /etc/haproxy/haproxy.cfg  
global
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     2000000
    user        haproxy
    group       haproxy
    daemon

    # nbthread  # 指定单个haproxy进程开启的线程数  启用此参数不能开启多核  

    # nbproc 4  #开启的haproxy进程数,建议与CPU核数保持一致
    # cpu-map 1 0
    # cpu-map 2 1
    # cpu-map 3 2
    # cpu-map 4 3
    # stats bind-process 4
    stats socket /var/lib/haproxy/stats

    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    #maxconn                 3000
# 监控页面
listen monitor-stats
    bind *:80
    option      forwardfor
    stats       enable
    stats       auth    admin:admin
    stats       hide-version
    stats       show-node
    stats       refresh 60s
    stats       uri     /haproxy?stats

# rabbitmq api接口
listen mq_cluster_5672
    bind *:5672
    mode tcp
    balance     roundrobin
    server      node1   11.1.1.51:5672  check
    server      node2   11.1.1.52:5672  check
    server      node3   11.1.1.53:5672  check
    # check             #       检测参数 默认不开启
    # addr      IP              #       指定待检测的IP
    # port      num             #       指定待检测的端口
    # inter     num             #       检测周期  默认2s
    # fall      num             #       后端服务器检测失败次数  默认3次
    # rise      num             #       后端服务器从下线到恢复检查次数,默认为2
    # weight    num     #       默认为1,最大值为256,0表示不参与负载均衡
    # backup            #       将石端服务器标记为备份认态
    # disable           #       将后端吸务器标记为不可丹状态

# rabbitmq 管理界面
listen mq_admin_15672
    bind *:15672
    mode tcp
    balance     roundrobin
    server      node1   11.1.1.51:15672 check
    server      node2   11.1.1.52:15672 check
    server      node3   11.1.1.53:15672 check


[root@ha1 ~]# scp /etc/haproxy/haproxy.cfg ha2:/etc/haproxy/haproxy.cfg
root@ha2's password: 
haproxy.cfg 
    
    
# 启动服务
[root@ha1 ~]# systemctl enable haproxy --now
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service → /usr/lib/systemd/system/haproxy.service.

[root@ha2 ~]# systemctl enable haproxy --now
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service → /usr/lib/systemd/system/haproxy.service.

防火墙放行端口

# 放行端口
[root@ha1 ~]# firewall-cmd --add-service=http
success
[root@ha1 ~]# firewall-cmd --add-port=15672/tcp
success
[root@ha1 ~]# firewall-cmd --add-port=5672/tcp
success
[root@ha1 ~]# firewall-cmd --runtime-to-permanent
success

[root@node1 ~] firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept'
[root@node1 ~] firewall-cmd --runtime-to-permanent
  • 查看haproxy

node1

image-20240309103901049

image-20240319213327499

连续刷新

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

image-20240309105414941

image-20240309104935635

node2

image-20240319220613024

image-20240309105749118

image-20240309105704888

image-20240309105724719

配置Keepalived

编辑配置文件

[root@ha1 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   router_id HA1
}

# vrrp 检测haproxy状态脚本
vrrp_script chk_haproxy {
    script "/etc/keepalived/scripts/haproxy_check.sh"
    interval 2
    timeout 2
    fall 3
}

# VRRP配置
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    track_script {
        chk_haproxy
    }

    virtual_ipaddress {
        11.1.1.100
    }
}

# haproxy 检测脚本
[root@ha1 ~]# vim /etc/keepalived/scripts/haproxy_check.sh
#!/bin/bash
CMD = `ps -C haproxy --no-header | wc -l`

if [ $CMD -eq 0 ]; then
        systemctl start haproxy
        sleep 2
        if [ $CMD -eq 0 ]; then
                killall keepalived
        fi
fi

[root@ha2 ~]# mkdir /etc/keepalived/scripts
[root@ha1 ~]# scp /etc/keepalived/keepalived.conf ha2:/etc/keepalived/keepalived.conf
root@ha2's password: 
keepalived.conf                                                                                                                                                                                                                             100%  432   385.8KB/s   00:00    
[root@ha1 ~]# scp /etc/keepalived/scripts/haproxy_check.sh  ha2:/etc/keepalived/scripts/haproxy_check.sh 
root@ha2's password: 
haproxy_check.sh                                                                                                                                                                                                                            100%  188   240.9KB/s   00:00    
[root@ha1 ~]# systemctl enable keepalived --now
[root@ha1 ~]# firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept'
[root@ha1 ~]# firewall-cmd --runtime-to-permanent

[root@ha2 ~]# systemctl enable keepalived --now
[root@ha2 ~]# firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept'
[root@ha2 ~]# firewall-cmd --runtime-to-permanent


[root@ha1 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:3a:36:d2 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 11.1.1.61/24 brd 11.1.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 11.1.1.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe3a:36d2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@ha1 ~]# 

image-20240319222730619

image-20240319222750161

image-20240319222827633

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

[root@ha1 ~]# systemctl stop keepalived
[root@ha1 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:3a:36:d2 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 11.1.1.61/24 brd 11.1.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe3a:36d2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever


[root@ha2 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:27:d3:3e brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 11.1.1.62/24 brd 11.1.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 11.1.1.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe27:d33e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

刷新页面

image-20240319224537677

[root@ha1 ~]# systemctl start keepalived
[root@ha1 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:3a:36:d2 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 11.1.1.61/24 brd 11.1.1.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 11.1.1.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe3a:36d2/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
 
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在信号处理领域,DOA(Direction of Arrival)估计是一项关键技术,主要用于确定多个信号源到达接收阵列的方向。本文将详细探讨三种ESPRIT(Estimation of Signal Parameters via Rotational Invariance Techniques)算法在DOA估计中的实现,以及它们在MATLAB环境中的具体应用。 ESPRIT算法是由Paul Kailath等人于1986年提出的,其核心思想是利用阵列数据的旋转不变性来估计信号源的角度。这种算法相比传统的 MUSIC(Multiple Signal Classification)算法具有较低的计算复杂度,且无需进行特征值分解,因此在实际应用中颇具优势。 1. 普通ESPRIT算法 普通ESPRIT算法分为两个主要步骤:构造等效旋转不变系统和估计角度。通过空间平移(如延时)构建两个子阵列,使得它们之间的关系具有旋转不变性。然后,通过对子阵列数据进行最小二乘拟合,可以得到信号源的角频率估计,进一步转换为DOA估计。 2. 常规ESPRIT算法实现 在描述中提到的`common_esprit_method1.m`和`common_esprit_method2.m`是两种不同的普通ESPRIT算法实现。它们可能在实现细节上略有差异,比如选择子阵列的方式、参数估计的策略等。MATLAB代码通常会包含预处理步骤(如数据归一化)、子阵列构造、旋转不变性矩阵的建立、最小二乘估计等部分。通过运行这两个文件,可以比较它们在估计精度和计算效率上的异同。 3. TLS_ESPRIT算法 TLS(Total Least Squares)ESPRIT是对普通ESPRIT的优化,它考虑了数据噪声的影响,提高了估计的稳健性。在TLS_ESPRIT算法中,不假设数据噪声是高斯白噪声,而是采用总最小二乘准则来拟合数据。这使得算法在噪声环境下表现更优。`TLS_esprit.m`文件应该包含了TLS_ESPRIT算法的完整实现,包括TLS估计的步骤和旋转不变性矩阵的改进处理。 在实际应用中,选择合适的ESPRIT变体取决于系统条件,例如噪声水平、信号质量以及计算资源。通过MATLAB实现,研究者和工程师可以方便地比较不同算法的效果,并根据需要进行调整和优化。同时,这些代码也为教学和学习DOA估计提供了一个直观的平台,有助于深入理解ESPRIT算法的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值