zoukankan      html  css  js  c++  java
  • RabbitMQ——用HAProxy实现负载均衡

    RabbitMQ负载均衡的必要性

            集群的配置已经搭好,代码成功跑通,成功做到了高可用,但是我们的程序连接节点并不会管哪个服务器在忙、哪个服务器空闲,完全看心情想连谁就连谁。而且代码中要把每个ip的节点都手动的写出来 ,既然是手动的就很有可能发现写错这种情况,同样WEB UI 通常也不知道打开哪个好,因为每个服务器都有一个 WEB UI,可能有人说,既然哪个都行,你随便打开一个就是了。但是如果这个服务器后面崩了呢。

    基于以前问题,需要一个强大的负载均衡服务器来帮助我们完成这些事情。

    选择使用 haproxy做负载均衡。

    linux安装haproxy

    yum search haproxy     或者     yum list | grep haproxy

    yum install -y haproxy.x86_64     安装  

    rpm -qi haproxy       查看版本

    haproxy --help

    vim /etc/haproxy/haproxy.cfg  配置文件

    haproxy -f /etc/haproxy/haproxy.cfg   指定配置文件

    service haproxy start

    service haproxy status

    HAProxy控制台   http://4.14.21.19:7100/stats

     

    在RabbitMQ镜像集群已装好的前提下,

    HAProxy配置文件新添部分备份如下:

    #haproxy monitor
    listen monitor
            bind 0.0.0.0:7100
            mode http
            option httplog
            stats enable
            maxconn 10
            stats uri /stats
            stats refresh 5s
            stats   realm haproxy  #认证时的realm,作为提示用的
            stats   auth admin:Fire001  #认证用户名和密码
            stats   hide-version  #隐藏HAProxy版本号
            stats   admin if TRUE  #管理界面只有认证通过后才能在ui上进行管理
    
    
    
    #rabbitmq cluster
    listen rabbitmq_cluster
            bind 0.0.0.0:7107
            #配置TCP模式
            mode tcp
            #简单的轮询
            balance roundrobin
            #RabbitMQ集群节点配置
            server rabbitmq_node1 172.31.140.161:7101 check inter 5000 rise 2 fall 3 weight 1
            server rabbitmq_node2 172.31.140.161:7103 check inter 5000 rise 2 fall 3 weight 1
            server rabbitmq_node3 172.31.140.161:7103 check inter 5000 rise 2 fall 3 weight 1
    
    #rabbitmq console
    listen rabbitm1_console
       bind 0.0.0.0:7108
       mode http
       balance roundrobin
       server rabbitmq_console1 172.31.140.161:7102
       server rabbitmq_console2 172.31.140.161:7104
       server rabbitmq_console3 172.31.140.161:7106
  • 相关阅读:
    PAT 1010. 一元多项式求导 (25)
    PAT 1009. 说反话 (20) JAVA
    PAT 1009. 说反话 (20)
    PAT 1007. 素数对猜想 (20)
    POJ 2752 Seek the Name, Seek the Fame KMP
    POJ 2406 Power Strings KMP
    ZOJ3811 Untrusted Patrol
    Codeforces Round #265 (Div. 2) 题解
    Topcoder SRM632 DIV2 解题报告
    Topcoder SRM631 DIV2 解题报告
  • 原文地址:https://www.cnblogs.com/xingchong/p/14738588.html
Copyright © 2011-2022 走看看