RabbitMQ Cluster 2019(2)Cluster HA and Proxy

阅读更多
RabbitMQ Cluster 2019(2)Cluster HA and Proxy

Set the HA policy for our cluster
> rabbitmqctl -n rabbit1 set_policy ha-all "^" '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "^" to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...

You can check the exchanges to see the policy is HA-ALL
http://ubuntu-master:15672/#/exchanges

Set Up HAProxy to proxy
Find the latest version from here
http://www.haproxy.org/#down

> wget http://www.haproxy.org/download/1.8/src/haproxy-1.8.20.tar.gz
> tar zxvf haproxy-1.8.20.tar.gz

> make TARGET=generic ARCH=x86_64 USE_PCRE=1
> make install DESTDIR='/home/carl/tool/haproxy-1.8.20' PREFIX=''


> sudo ln -s /home/carl/tool/haproxy-1.8.20 /opt/haproxy-1.8.20
> sudo ln -s /opt/haproxy-1.8.20 /opt/haproxy

Add sbin to the PATH
export PATH="/opt/haproxy/sbin:$PATH"

Check the installation and version
> haproxy -v
HA-Proxy version 1.8.20 2019/04/25
Copyright 2000-2019 Willy Tarreau

Prepare the configuration directory
> mkdir conf

The configuration file is as follow:
> cat conf/haproxy.conf
#logging options
global
        log 127.0.0.1 local0 info
        maxconn 5120
        chroot /opt/haproxy
        uid 99
        gid 99
        daemon
        quiet
        nbproc  2
        pidfile /opt/haproxy/haproxy.pid
#load balancing defaults
defaults
       log        global
       #使用4层代理模式,"mode   http"为7层代理模式
       mode       tcp
       #if you set mode to tcp,then you nust change tcplog into httplog
       option     tcplog
       option     dontlognull
       retries    3
       option redispatch
       maxconn 2000
       contimeout      5s
       clitimeout      120s
       srvtimeout      120s
      
#front-end IP for consumers and producters
listen rabbitmq_local_cluster
       bind 0.0.0.0:5670
       #配置TCP模式
       mode      tcp
       #balance url_param userid
       #balance url_param session_id check_post 64
       #balance hdr(User-Agent)
       #balance hdr(host)
       #balance hdr(Host) use_domain_only
       #balance rdp-cookie
       #balance leastconn
       #balance source  //ip
       #简单的轮询
       balance roundrobin
       #rabbitmq集群节点配置
       server rabbit1 ubuntu-master:5672 check inter 5000 rise 2 fall 2
       server rabbit2 ubuntu-master:5672 check inter 5000 rise 2 fall 2
listen monitor
        bind 0.0.0.0:8100
        mode http
        option httplog
        stats enable
        stats uri /stats
        stats refresh 5s

Command to start the haproxy
> sudo sbin/haproxy -f conf/haproxy.conf


Visit the stats Page
http://ubuntu-master:8100/stats

References:
https://objcoding.com/2018/10/19/rabbitmq-cluster/
https://blog.csdn.net/WoogeYu/article/details/51119101
https://juejin.im/entry/5c0fb747e51d4505fe6c4b71
https://www.jianshu.com/p/6376936845ff




你可能感兴趣的:(RabbitMQ Cluster 2019(2)Cluster HA and Proxy)