openstack- message queue rabbitmq (2)

A, MQ called the Message Queue, the message queue (MQ)

It is an application communication method according to the application. Application to communicate via a message (data for the application program) read out of the queue, without the need for a dedicated connection to link them.

Refers to message passing communication between a program in the data message transmitted by, rather than through direct calls to communicate with each other, is a technique commonly called directly, such as remote procedure calls. It refers to the application queue by the queue to communicate. Removed using a queue and transmission requirements received concurrently executing applications.

It refers to the application queue by the queue to communicate. Removed using a queue and transmission requirements received concurrently executing applications.

二、AMQP  即 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.

AMQP main feature is a message for the queue, the routing (including point and publish / subscribe), reliability and safety.

Three, Rabbitmq concept:

       Belonging to a popular open source system message queue. Belonging to the AMQP (Advanced Message Queuing Protocol) to achieve a standard. It is an open standard application-layer protocol for message-oriented middleware design. In a distributed system for store and forward messages, in terms of ease of use, scalability, high availability, and so doing well.

       Message middleware mainly for decoupling between the components, sender of the message without knowing the user's presence information, and vice versa.
       AMQP main feature is a message for the queue, the routing (including point and publish / subscribe), reliability and safety.

       RabbitMQ Features:
    Use written in Erlang
    support persistence
    support HA
    provides C #, erlang, java, perl , python, ruby and other client-side development

Fourth, what is the coupling, decoupling

A coupling
  1, the coupling means between two or more systems or affect the movement of both forms interact with each other as well as together by the phenomenon.

  2, in software engineering, is the degree of coupling between objects dependencies between objects. The higher the coupling between objects, higher maintenance costs, so the design should minimize the object class and the coupling between the member.

  3, Classification: coupling between the coupling, as well as hardware and software between the software modules. Coupling is a measure of the program structure of the linkages between the various modules. It depends on the complexity of the interface between each module, the calling module and what information the way through the interface.

Second, decoupling
  1, decoupling, literally means to decouple the relationship.

  2, in software engineering, i.e. to reduce the degree of coupling can be understood as decoupling, dependent relationship must exist between the coupling module, coupled to the theoretical absolute zero is impossible, but can be identified by conventional methods to reduce the degree of coupling to a minimum.

  3, the design of the core idea: to minimize coupling of code, if the code is coupled found, it is necessary to take decoupling technology. Let data model, business logic and views between the three lower display coupled to one another, the association relies to a minimum, and thus will not affect the situation as a whole. A principle feature of the code is not written in the function code B, if needed interaction between the two, through the interface, through a message, or even the introduction of the framework, but in short, is not to write directly cross.

Five, RabbitMQ conceptual terms

Broker: Message Queue Server is simply an entity. ?

Exchange: Message switch that specifies what the message according to the rules, which are routed to a queue. ?

Queue: vector message queue, each message will be put into one or more queues. ? Binding: binding, its role is to exchange routing and queue bind in accordance with the rules.

? Routing Key: routing keywords, exchange of messages delivered in accordance with this keyword.

? Vhost: web hosting, where a broker can offer more vhost, as a different user privilege separation.

producer: news producer, is the program delivered the message. ?

consumer: consumer news, is that the program accepts messages. ?

channel: message channels, in each client's connection can create multiple channel, each channel representing a conversation task?.

Six, RabbitMQ work management

MQ consumption - a model representative of typical producer, end to continue to write messages in the message queue, and the other end can be read or subscribe to messages in the queue. MQ is a concrete follow AMQP protocol implementations and products. In the project, without some return immediately extracted and time-consuming operation, made asynchronous processing, and this processing asynchronous requests greatly saving server response time, thereby increasing the throughput of the system.

(1) Message Queuing clients connect to the server to open a channel. ?

(2) a declaration client exchange, and provision of the relevant property. ?

(3) The client declares a queue, and set the associated property. ?

(4) The client uses routing key, establish a good relationship between the exchange and the binding queue.

? (5) client posting messages to the exchange. ?

(6) exchange after receiving the message, according to the message and key binding has been set, into? OK message routing, message delivered to one or more queue

Seven, Rabbitmq of metadata

  Metadata can be persistent in the RAM Disc or RabbitMQ from this angle can be divided into two nodes in the cluster:. RAM Node and Disk Node.

       RAM only the Node metadata stored in the RAM

       Disk node 会将元数据持久化到磁盘。 

   单节点系统就没有什么选择了 , 只允许 disk node, 否则由于没有数据冗余一旦重启就会丢掉所有的配置信息 . 但在集群环境中可以选择哪些节点是 RAM node.在集群中声明(declare) 创建 exchange queue binding, 这类操作要等到所有的节点都完成创建才会返回 :
       如果是内存节点就要修改内存数据 ,
       如果是 disk node 就要等待写磁盘 , 节点过多这里的速度就会被大大的拖慢 .

    有些场景 exchang queue 相当固定 , 变动很少 ,那即使全都是 disc node, 也没有什么影响 . 如果使用 Rabbitmq 做 RPC( RPC :Remote Procedure Call—远程过程调用),  RPC 或者类似 RPC 的场景这个问题就严重了 , 频繁创建销毁临时队列 , 磁盘读写能力就很快成为性能瓶颈了。所以 , 大多数情况下 , 我们尽量把 Node 创建为RAM Node. 这里就有一个问题了 , 要想集群重启后元数据可以恢复就需要把集群元数据持久化到磁盘 , 那需要规划 RabbitMQ 集群中的 RAM Node 和 Disc Node 。

    只要有一个节点是 Disc Node 就能提供条件把集群元数据写到磁盘 ,RabbitMQ 的确也是这样要求的 : 集群中只要有一个 disk node 就可以 , 其它的都可以是 RAM node. 节点加入或退出集群一定至少要通知集群中的一个 disk node 。

    如果集群中 disk node 都宕掉 , 就不要变动集群的元数据 . 声明 exchange queue 修改用户权限 , 添加用户等等这些变动在节点重启之后无法恢复 。

    有一种情况要求所有的 disk node 都要在线情况在才能操作 , 那就是增加或者移除节点 .RAM node 启动的时候会连接到预设的 disk node 下载最新的集群元数据 . 如果你有两个 disk node(d1 d2), 一个 RAM node 加入的时候你只告诉 d1, 而恰好这个 RAM node 重启的时候 d1 并没有启动 , 重启就会失败 . 所以加入 RAM 节点的时候 , 把所有的disk node 信息都告诉它 ,RAM node 会把 disk node 的信息持久化到磁盘以便后续启动可以按图索骥 .

八、Rabbitmq 集群部署

 

一、前期准备
 
(1)条件:准备3台linux系统,确保配置好源,及epel源
 
(2)三台机器能够静态解析彼此
(3)设置可以无密钥登陆
 
二、安装过程:
 
(1)所有node安装rabbtimq和erlang软件包:
yum install -y erlang rabbitmq-server.noarch
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server.service
systemctl status rabbitmq-server.service
 
查看监听端口:
netstat -lantp | grep 5672
配置文件:
vim /etc/rabbitmq/rabbitmq.config
 
(2)node1:修改guest密码为admin(默认用户为:guest 密码为:guest)
rabbitmqctl change_password guest admin
 
(3)node1:添加一个openstack的用户,并设密码为admin。并设置权限和成为管理员
node1:
rabbitmqctl add_user openstack admin
rabbitmqctl set_permissions openstack ".*" ".*" ".*"
rabbitmqctl set_user_tags openstack administrator
 
(4)node1:编辑rabbittmq变量文件
vim /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODE_PORT=5672
ulimit -S -n 4096
RABBITMQ_SERVER_ERL_ARGS="+K true +A30 +P 1048576 -kernel inet_default_connect_options [{nodelay,true},{raw,6,18,<<5000:64/native>>}] -kernel inet_default_listen_options [{raw,6,18,<<5000:64/native>>}]"
RABBITMQ_NODE_IP_ADDRESS=172.16.254.60
 
(5)node1:将rabbittmq变量文件拷贝到其他两节点,之后并修改相应节点的ip
scp /etc/rabbitmq/rabbitmq-env.conf con2:/etc/rabbitmq/
scp /etc/rabbitmq/rabbitmq-env.conf con3:/etc/rabbitmq/
 
查看rabbitmq插件
/usr/lib/rabbitmq/bin/rabbitmq-plugins list
 
(6)所有node 开启rabbitmq的web管理页面
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management mochiweb webmachine rabbitmq_web_dispatch amqp_client rabbitmq_management_agent
或者:rabbitmq-plugins enable rabbitmq_management
 
systemctl restart rabbitmq-server.service
systemctl status rabbitmq-server.service
 
(7)node1发送erlang.cookie到其他节点配置集群
rabbitmqctl status
scp /var/lib/rabbitmq/.erlang.cookie con2:/var/lib/rabbitmq/.erlang.cookie
scp /var/lib/rabbitmq/.erlang.cookie con3:/var/lib/rabbitmq/.erlang.cookie
 
(8)node2和node3停止应用,并以ram的方式加入node1节点,之后重启应用
systemctl restart rabbitmq-server.service
rabbitmqctl stop_app
rabbitmqctl join_cluster --ram rabbit@con1
rabbitmqctl start_app
 
(9)node1检查集群状态
[root@con1 conf]# rabbitmqctl cluster_status
Cluster status of node rabbit@con1 ...
[{nodes,[{disc,[rabbit@con1]},{ram,[rabbit@con3,rabbit@con2]}]},
{running_nodes,[rabbit@con3,rabbit@con2,rabbit@con1]},
{cluster_name,<<"rabbit@con1">>},
{partitions,[]},
{alarms,[{rabbit@con3,[]},{rabbit@con2,[]},{rabbit@con1,[]}]}]
 
(10)登陆验证: http://172.16.254.60:15672/#/             guest/admin
 
 
 
 
其他命令:
(1)添加管理员:
rabbitmqctl add_user mqadmin mqadmin
rabbitmqctl set_user_tags mqadmin administrator
rabbitmqctl set_permissions -p / mqadmin ".*" ".*" ".*"
 
(2)更改节点类型(内存型或磁盘型)
rabbitmqctl stop_app
rabbitmqctl change_cluster_node_type disc 或 rabbitmqctl change_cluster_node_type ram
rabbitmqctl start_app
 
(3)从集群移除节点(或者重置节点)
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
 
(4)从某个节点移除集群中其他节点
rabbitmqctl forget_cluster_node rabbit@node3
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
 
1. 保证集群中至少有一个磁盘类型的节点以防数据丢失,在更改节点类型时尤其要注意。
2. 若整个集群被停掉了,应保证最后一个 down 掉的节点被最先启动,若不能则要使用 forget_cluster_node 命令将其移出集群
3. 若集群中节点几乎同时以不可控的方式 down 了此时在其中一个节点使用 force_boot 命令重启节点

Guess you like

Origin www.cnblogs.com/biht/p/11653883.html