openstack --rabbitmq message queue shared components (1)

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

An application communication method to the application . Applications communicate via 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.

二、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. Is an open standard application-layer protocol is 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 .


       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 . Between objects higher coupling, higher maintenance costs , so the design should minimize the object class and the coupling between the member.

  3, classification: there is 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, to reduce the degree of coupling can be understood as decoupling i.e., there must exist dependencies between modules coupling , the coupling is zero theoretically absolutely 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: is simply a message queue server entity . ?

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

Queue: Message Queuing carrier , each message will be put into one or more queues. ? The 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, a broker where you can set up multiple 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, some return immediately without time-consuming operations and extracted performs asynchronous processing and asynchronous processing in this manner greatly saving requests the 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)

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

       RAM only the Node metadata stored in the RAM

       Disk node metadata will be persisted to disk. 

  Single-node system is not any choice, allowing only disk node, or because there is no data redundancy, once restarted will lose all the configuration information, but in a clustered environment can choose which nodes are RAM node. Declare (declare) in the cluster Creating exchange queue binding, such operations until all nodes are finished creating will return: 
       If it is necessary to modify the memory node memory data, 
       if it is necessary to wait for the write to disk disk node, the node excessive speed here will be greatly the slow down.

    Some scenes exchang queue fairly constant, change very little, and that even if all disc node, there is no effect if used Rabbitmq do RPC. (RPC: Remote Procedure Call- remote procedure call), RPC or RPC-like scene this serious problem the frequent destruction create a temporary queue, the disk reading and writing skills quickly become a performance bottleneck. Therefore, in most cases, we try to create a Node for the RAM Node. Here there is a problem, metadata in order to restart the cluster may need to restore the cluster metadata persisted to disk, it requires planning RabbitMQ cluster RAM Node and Disc Node.

    As long as there is a node Disc Node will be able to provide the conditions for the cluster metadata written to the disk, RabbitMQ and indeed such requirements: a cluster as long as one disk node can, others can be a RAM node cluster nodes to join or withdraw from certain at least to notify a disk node in the cluster.

    As if the cluster disk node are dawdle away, do not change the metadata of the cluster. Disclaimer exchange queue modify user permissions, add users, etc. These changes can not be recovered after a node restart.

    A situation requires that all disk node to be the case in order to operate online that add or remove nodes .RAM node will start when connected to the predefined disk node to download the latest cluster metadata. If you have two disk node (d1 d2), when a RAM node join you just tell d1, and just this RAM node restart when d1 does not start, restart will fail. so when adding RAM nodes, all the disk node information to tell it will RAM node disk node information is persisted to disk for subsequent startup can find what you want.

 

 

Eight, Rabbitmq cluster deployment

 

First, preparation
 
(1) Conditions: Prepare three linux system to ensure good source configuration, and epel source
 
(2) three machines can still resolve each other
192.168.253.135 bb     192.168.253.171 aa 192.168.253.153 cc
(3) setting can keyless landing
 ssh-keygen
 ssh-copy-id
 
Second, the installation process:
 
(1) All node installation rabbtimq and package erlang:
yum install -y erlang rabbitmq-server.noarch systemctl enable rabbitmq-server.service systemctl start rabbitmq-server.service systemctl status rabbitmq-server.service
 
Check listening port:
netstat -lantp | grep 5672
Profiles:
vim /etc/rabbitmq/rabbitmq.config
 
(2) node1: Modify guest password is admin (default user: guest password: guest)
change_password the Guest ADMIN rabbitmqctl # change the password admin, and user name can not begin with numbers      
 
(3) node1: add a mama's user, and the password is admin. And set permissions and become an administrator
Three * mean are:
All switch all queues of all virtual hosts
 
Copy the code
node1 :  rabbitmqctl add_user Mama ADMIN  rabbitmqctl set_permissions Mama " *. " " *. " " *. "   rabbitmqctl set_user_tags Mama Administrator # Set the administrator can log in  
Copy the code

 

(4) node1: edit rabbittmq variable file
vim /etc/rabbitmq/rabbitmq-env.conf
Copy the code
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=192.168.253.135
Copy the code
 
(5) node1: rabbittmq the files are copied to two other variable nodes, and modifies the corresponding node after ip
scp /etc/rabbitmq/rabbitmq-env.conf aa:/etc/rabbitmq/ scp /etc/rabbitmq/rabbitmq-env.conf cc:/etc/rabbitmq/
 
View rabbitmq plug-ins (add functionality)
/usr/lib/rabbitmq/bin/rabbitmq-plugins list
 
(6) All node open web management page of rabbitmq
192.168.253.135: 15672
  systemctl restart rabbitmq-server.service
  systemctl status rabbitmq-server.service
rabbitmq-plugins enable rabbitmq_management
 
 
(7) node1 erlang.cookie sent to other nodes in the cluster configuration ** (cluster key)
 
scp / var / lib / rabbitmq /. erlang . cookie aa : / var / lib / rabbitmq / . erlang . cookie scp / var / lib / rabbitmq /. erlang . cookie cc : / var / lib / rabbitmq /. erlang . cookie
 
(8) cc stop the application, and in a manner ram added bb node restart after application
Similarly aa do, here's only experiment with cc
Note: Removing operating modifications and other cluster node application must first shut down
 
Copy the code
systemctl restart rabbitmq-server.service rabbitmqctl stop_app rabbitmqctl join_cluster --ram rabbit@bb rabbitmqctl start_app 
Copy the code

 

(9) node1 check the cluster status
r abbitmqctl cluster_status
 
 
(10) login authentication: http://192.168.253.135: 15672 /         
    guest/admin
 
 
 
Other commands:
 
(2) change the node type (type of memory or disk type)
Copy the code
rabbitmqctl stop_app
rabbitmqctl change_cluster_node_type disc (ram)

  The Rabbit @ CC INTO A Turning the Node RAM ...
  Error:. Mnesia IS ON Still running the Node The Rabbit @ CC
  . Please STOP with the Node at The First # rabbitmqctl stop_app can see the need to stop the application

  After stopping execution again

   [root@cc rabbitmq]# rabbitmqctl change_cluster_node_type ram
   Turning rabbit@cc into a ram node ...

rabbitmqctl start_app
Copy the code
 然后在web界面上查看即可
 
 
(3)节点脱离集群(或者节点重置) reset
Copy the code
rabbitmqctl stop_app
rabbitmqctl reset

----》 Resetting node rabbit@cc ...
[root@cc rabbitmq]# rabbitmqctl cluster_status  #查看状态发现节点cc脱离了集群 Cluster status of node rabbit@cc ... [{nodes,[{disc,[rabbit@cc]}]},          #脱离集群后的节点自动会变成disc的方式,原因在下方 1 {running_nodes,[rabbit@cc]}, {cluster_name,<<"rabbit@cc">>},    #并没有其他节点的名称说明不在集群内了 {partitions,[]}, {alarms,[{rabbit@cc,[]}]}]
Copy the code
 
(4) removal of other nodes in the cluster from a node
rabbitmqctl forget_cluster_node rabbit@node3
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
 
1. ensure that the cluster has at least one type of disk nodes to prevent data loss , when you change the node type with particular attention.
2. If the entire cluster to be stopped, and should ensure that the last one down out of the first node is started , if not will have to use the command to move it out of the cluster forget_cluster_node
3. If the cluster nodes almost simultaneously in an uncontrolled manner down the case in which a node uses force_boot command to reset the node

Guess you like

Origin www.cnblogs.com/daisyyang/p/10956748.html