RabbitMQ(11)Mirror HA with Cluster

RabbitMQ(11)Mirror HA with Cluster
 
We can set up that from command line with  rabbitmqctl.
We can also do that from the rabbitMQ client.
We can also do that on the UI console.
 
There are several policy.
ha-mode——————ha-params ————— Result
all           ——————(absent)     ————— Queue is mirrored, if we add one node, the system will mirror all data to that.
exactly   ——————count  ———————We will only keep certain count of mirror nodes
nodes ———————node names ———— List the mirror nodes in the parameters part
 
Let’s try to implement it in scala.
 
Lyra, High Availability RabbitMQ Client
It will helps us to achieve high availability in our services by embracing failure, allowing for AMQP resources such as connections, channels and consumers to be automatically recovered when the server or network failures occur.
 
 
msgpack 
 
or 
 
msgpack4s
 
 
Some example
Project Configuration
For RabbitMQ load balance and cluster solution. I read some documents. Actually, there are several levels.
1. Cluster
We can have a cluster of nodes which can have duplicated routing and exchange in every node.
So the client can producer to any nodes. But the persist queue information is stored in one node, so if
that node is down, we need to wait until that node recover.

2. HA based on cluster
If we have configured mirrors in the cluster, then we will have the persist queue information in all the nodes.
We will lost some performance here. But the good things is that when one node is down, we can go on serving from
other nodes.

3. Sharding based on Cluster
From the document, it is said, we will not just mirror all the queue information to all the nodes, the more nodes
we have, we will lost more performance.
Instead of simple mirror, we will sharding different data into different queues in different nodes.

I did not read more about that since we are using mirror on production. I will begin from there.

Set up RabbitMQ Cluster
details here
http://sillycat.iteye.com/blog/2066116

>chmod 400 ~/.erlang.cookie
>sudo chown -R carl ~/.erlang.cookie
>sudo chgrp -R staff ~/.erlang.cookie

enable the plugin
>sudo rabbitmq-plugins enable rabbitmq_management

Start the first node as rabbitmq1 on local MAC
>sudo RABBITMQ_NODE_PORT=5672 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15672}]" RABBITMQ_NODENAME=rabbit1 sbin/rabbitmq-server -detached

Start the second node
>sudo RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" RABBITMQ_NODENAME=rabbit2 sbin/rabbitmq-server -detached

Check the status of these 2 nodes, make sure they are running fine separately.
>sbin/rabbitmqctl -n rabbit2 cluster_status
>sbin/rabbitmqctl -n rabbit1 cluster_status

Stop the second node, and make the second node join the first node as a cluster
>sudo sbin/rabbitmqctl -n rabbit2 stop_app
>sbin/rabbitmqctl -n rabbit2 join_cluster rabbit1@sparkworker1
>sudo sbin/rabbitmqctl -n rabbit2 start_app

Check the status again, it will be a running cluster.
 
In the basic class, we will do that
def setPolicy(): Unit = {
  val auth = "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes)
  rabbitAdmin.split(",").map(h => new URL("http://" + h.trim + "/api/policies/%2f/high-availability")).
    foreach { url =>
      logger.debug("setting policy for " + url)
      val conn = url.openConnection().asInstanceOf[HttpURLConnection]
      conn.setDoOutput(true)
      conn.setRequestMethod("PUT")
      List(
        "Content-Type" -> "application/json",
        "Content-Length" -> haDefinition.length.toString,
        "Authorization" -> auth
      ).foreach(t => conn.setRequestProperty(t._1, t._2))
      val os = conn.getOutputStream
      os.write(haDefinition.getBytes)
      os.close
      logger.debug("response " + conn.getResponseCode + conn.getResponseMessage)
    }
}
 
 
 
 
References:
old blog
 
sharding
 
HA
 
cluster
 

 

 

 

ServHA Mirror为运行在Windows平台和Linux平台上的双机镜像产品,能够让用户无需购买昂贵的磁盘阵列的同时享受到双机集群带来的稳定、可靠,ServHA Mirror负责管理2台主机运行各自的应用系统,当主机或主机上的软件出现故障时,可以自动检测出该主机的故障,不需人工干预,准确、快速地将原主机的应用系统移交到备用主机上继续运行,实现整个系统的不间断运行;同时,当系统数据发生改变时,ServHA Mirror会将更改复制至备机, 此时,用户的数据在主机和备机中各有一份,一旦其中一台服务器发生故障、甚至损毁,不但服务不会中断,用户的数据也不会丢失。而且采用ServHA Mirror 产品后,能够更灵活的部署服务器,数据都是通过网络传输,不再受制于存储。        ServHA Mirror 对于上层应用是透明的,其故障检测、故障恢复、数据同步都是在底层自动完成,与上层应用无直接依赖,所以,ServHA Mirror不但能够胜任现今的应用容器、数据库容器的保护,还能够支持用户自行开发的应用、服务的备份,再加上ServHA Mirror强大、灵活的插件机制,完全能够适应用户个各种需求。 综上所述,采用ServHA Mirror产品主要的优势有: 1. 节省资金:能够让您无需购买昂贵的磁盘阵列的同时享受到双机集群带来的稳定与可靠。 2. 避免了磁盘阵列的单点故障。杜绝了以往磁盘阵列损坏导致集群服务中断。 3. ServHA Mirror对于应用透明,加以插件机制,能够满足各种用户需求。 4. 不受距离的限制,数据通过网络传输,不受制于存储,部署灵活。 5. 在镜像中,数据是双份的,即使一台服务器完全物理损毁也不会造成数据丢失和应用的可用性。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值