Rabbitmq Cluster Deployment

Bowen outline:
a, Rabbitmq concept
Second, the deployment of a single Rabbitmq
three cluster deployment Rabbitmq
four single node join or leave the cluster configuration

A, Rabbitmq concept

RabbitMQ AMQP protocol is an open-source by the service, the server in Erlang language, supports a variety of clients, such as: Python, Ruby, .NET, Java , JMS, C, PHP, ActionScript, XMPP, STOMP , and support AJAX. In a distributed system for store and forward messages, in terms of ease of use, scalability, high availability, and so doing well.
AMQP, namely Advanced Message Queuing Protocol, Advanced Message Queuing Protocol, is an open standard application layer protocol for message-oriented middleware design. Message middleware mainly for decoupling between the components, sender of the message without knowing the user's presence information, and vice versa.
It will make the corresponding client (client) corresponding to messaging middleware (Broker) interact. Messaging middleware publisher (publisher), where you receive a message (application posting, also known as producer), and then forwards them to the consumer (consumers, the application message processing). Since AMQP is a network protocol, publishers, consumers and messaging middleware can be deployed on different physical machines.

Rabbitmq usage scenarios

Message queue in practical applications used in asynchronous processing, decoupling applications, and message communication flow front cutting four scenes.

Second, the deployment of a single Rabbitmq

Note: Before you begin, the best host name for the default localhosts (if not, will complain when you start rabbitmq, Solution: restart the host, and then start rabbitmq)

Free to the official website to download the required software, you can also download my network disk rpm package, and then uploaded to the server itself.

IP Below this server is 192.168.20.2.

[root@localhost src]# ls      #确认所需RPM包
erlang-18.1-1.el6.x86_64.rpm
rabbitmq-server-3.6.6-1.el6.noarch.rpm
socat-1.7.3.2-2.el7.x86_64.rpm
[root@localhost src]# yum -y localinstall erlang-18.1-1.el6.x86_64.rpm rabbitmq-server-3.6.6-1.el6.noarch.rpm socat-1.7.3.2-2.el7.x86_64.rpm
#安装RPM包
[root@localhost src]# chkconfig rabbitmq-server on   #rabbitmq加入开机自启
[root@localhost src]# /etc/init.d/rabbitmq-server start    #启动rabbitmq服务

OK rabbitmq is running:

[root@localhost src]# ps -ef | grep rabbitmq    

Returns the result of the command is as follows:

Rabbitmq Cluster Deployment

#开启rabbitmq的web管理插件,以便可以通过浏览器进行访问
[root@localhost src]# rabbitmq-plugins enable rabbitmq_management
#创建登录用户
[root@localhost src]# rabbitmqctl add_user admin 123.com
#将创建的admin用户添加至administrator组
[root@localhost src]# rabbitmqctl set_user_tags admin administrator

Client Access server rabbitmq port 15672, using the newly created admin user login, the login is successful is shown below:

Rabbitmq Cluster Deployment

Can access success, it represents a single rabbitmq to build complete.

Third, the deployment of a cluster Rabbitmq

Rabbitmq cluster roughly divided into two methods:
1, Normal mode: The default mode of the cluster, the message bodies there is only one node;
2, mirror mode: the need to make the mirror queue present in the plurality of nodes.
ha-mode:

  • all: queued to all nodes;
  • exatly: random image to other nodes;
  • nodes: mirrored to the specified node.

Cluster node modes:
1 memory node: work on memory;
2, the disk node: Work on the disk;
exception: memory and disk nodes nodes co-exist, to improve access speed increase while data persistence.

Compared memory nodes, although not written to disk, but it performs better than the disk node cluster, you only need a disk to save the state would be sufficient, if only the memory cluster node, the node once down, all status messages It will be lost, can not be achieved persistent data.

1, the deployment environment as follows:

Rabbitmq Cluster Deployment

Wherein 192.168.20.2 is based on the above single rabbitmq to do.

2, installation services rabbitmq

The following operations and 20.4 192.168.20.3 two nodes (node ​​then back to 20.5), in order to deploy services rabbitmq:

#上传所需rpm包
[root@localhost src]# ls      
erlang-18.1-1.el6.x86_64.rpm
rabbitmq-server-3.6.6-1.el6.noarch.rpm
socat-1.7.3.2-2.el7.x86_64.rpm
#安装rabbitmq
[root@localhost src]# yum -y localinstall erlang-18.1-1.el6.x86_64.rpm rabbitmq-server-3.6.6-1.el6.noarch.rpm socat-1.7.3.2-2.el7.x86_64.rpm 
#启动rabbitmq并加入开机自启
[root@localhost src]# /etc/init.d/rabbitmq-server start
[root@localhost src]# chkconfig rabbitmq-server on

3, configure host 192.168.20.2

[root@localhost ~]# tail -4 /etc/hosts     #配置本地解析(主机名直接写想要自定义的即可)
192.168.20.2 rabbitmq01
192.168.20.3 rabbitmq02
192.168.20.4 rabbitmq03
192.168.20.5 rabbitmq04
#将hosts文件复制到其他节点
[root@localhost ~]# scp /etc/hosts [email protected]:/etc/
[root@localhost ~]# scp /etc/hosts [email protected]:/etc/
[root@localhost ~]# scp /etc/hosts [email protected]:/etc/
#将rabbitmq01的cookie节点信息复制到其他需要加入群集的节点
#部署群集的时候需要节点cookie信息一致
[root@localhost ~]# scp /var/lib/rabbitmq/.erlang.cookie [email protected]:/var/lib/rabbitmq/
[root@localhost ~]# scp /var/lib/rabbitmq/.erlang.cookie [email protected]:/var/lib/rabbitmq/

4, restart all server to join a cluster node

Execute the following command to restart (including rabbitmq01) to join in on all the cluster servers.

[root@localhost ~]# init 6       #重启后就会发现主机名已经更改为hosts文件中定义的了

If after the restart when an interface card, you need to force restart.

[root@rabbitmq01 ~]# ps -ef | grep rabbit    #重启后确定已经启动

5, in a cluster configuration rabbitmq01

[root@rabbitmq01 ~]# rabbitmqctl  stop_app   #停止rabbitmq节点服务
[root@rabbitmq01 ~]#  rabbitmqctl reset     #重置rabbitmq节点
[root@rabbitmq01 ~]# rabbitmqctl start_app    #启动rabbit节点服务
Starting node rabbit@rabbitmq01 ... #复制返回的节点名称

6, adding rabbitmq01 cluster configuration rabbitmq02,03

[root@rabbitmq02 ~]# rabbitmqctl stop_app   #停止节点服务
[root@rabbitmq02 ~]# rabbitmqctl reset     #重置节点
[root@rabbitmq02 ~]# rabbitmqctl join_cluster --ram rabbit@rabbitmq01          #以内存方式加入群集,后面是复制的rabbitmq01的节点名
[root@rabbitmq02 ~]# rabbitmqctl start_app   
[root@rabbitmq02 ~]# rabbitmq-plugins enable rabbitmq_management

7, view node status on rabbitmq01

[root@rabbitmq01 ~]# rabbitmqctl cluster_status       #查看节点状态
Cluster status of node rabbit@rabbitmq01 ...
[{nodes,[{disc,[rabbit@rabbitmq01]},
         {ram,[rabbit@rabbitmq03,rabbit@rabbitmq02]}]},
 {running_nodes,[rabbit@rabbitmq03,rabbit@rabbitmq02,rabbit@rabbitmq01]},
 {cluster_name,<<"rabbit@rabbitmq01">>},
 {partitions,[]},
 {alarms,[{rabbit@rabbitmq03,[]},
          {rabbit@rabbitmq02,[]},
          {rabbit@rabbitmq01,[]}]}]
# rabbit01工作模式为磁盘节点;rabbit02和03为内存节点模式
# running_nodes:正在运行的节点
# cluster_name:节点名称
# alarms:发生问题时rabbit01、02、03会进行报警

8, in rabbitmq create an administrative user and join the management group

Since the reset node is reset, so users need to be recreated.

[root@rabbitmq01 ~]# rabbitmqctl add_user admin 123.com
[root@rabbitmq01 ~]# rabbitmqctl set_user_tags admin administrator

9, login web interface

IP + 15672 within any port cluster node can log in:

You can see information about the cluster nodes in the following page:
Rabbitmq Cluster Deployment

10, the configuration web interface to add Vhost

Rabbitmq Cluster Deployment

Enter the virtual host created:

Rabbitmq Cluster Deployment

Then configure the following:

Rabbitmq Cluster Deployment

After setup is complete view a virtual host again:

Rabbitmq Cluster Deployment

Set match policy:

Rabbitmq Cluster Deployment

make an announcement:

Rabbitmq Cluster Deployment

Set publish news content:

Rabbitmq Cluster Deployment

Rabbitmq Cluster Deployment

Rabbitmq Cluster Deployment

Then refresh the current page, you can see the total number of queues in the current virtual host:

Rabbitmq Cluster Deployment

Fourth, a single node join or leave the cluster configuration

1, node joining the cluster

Because when I deploy cluster above, hosts can parse files already node in the cluster, so here is omitted resolved

#在节点192.168.20.5服务器上安装rabbitmq并配置
[root@localhost src]# yum -y localinstall erlang-18.1-1.el6.x86_64.rpm rabbitmq-server-3.6.6-1.el6.noarch.rpm socat-1.7.3.2-2.el7.x86_64.rpm 
[root@localhost src]# chkconfig rabbitmq-server on
[root@localhost src]# /etc/init.d/rabbitmq-server start
#将群集中的cookie信息复制到本地
[root@localhost src]# scp root@rabbitmq01:/var/lib/rabbitmq/.erlang.cookie /var/lib/rabbitmq/
[root@localhost src]# init 6       #重启本机
#加入群集
[root@rabbitmq04 ~]# rabbitmqctl stop_app
[root@rabbitmq04 ~]# rabbitmqctl reset
[root@rabbitmq04 ~]# rabbitmqctl join_cluster --ram rabbit@rabbitmq01
#以内存运行的方式加入群集,若要以磁盘的方式加入,省略“--ram”选项即可
[root@rabbitmq04 ~]# rabbitmqctl start_app
#开启web管理页面
[root@rabbitmq04 ~]# rabbitmq-plugins enable rabbitmq_management

View web interface, confirmed rabbitmq04 added to the cluster:

Rabbitmq Cluster Deployment

2, a single-node cluster exit

1) stop node rabbitmq04 above

[root@rabbitmq04 ~]# rabbitmqctl stop_app

2) back to the master node rabbitmq01 delete nodes

[root@rabbitmq04 ~]# rabbitmqctl -n rabbit@rabbitmq01 forget_cluster_node rabbit@rabbitmq04
# -n:指定节点名称
# forget_cluster_node:后面跟要删除的节点名称 

-------- end of this article so far, thanks for reading --------

Guess you like

Origin blog.51cto.com/14154700/2452783
Recommended