Linux installation RABBITMQ

Source: Internet
Author: User
Tags message queue rabbitmq amq

first, the concept of RABBITMQ
RABBITMQ is a popular open source Message Queuing system and is a standard implementation of the AMQP (Advanced Message Queuing Protocol Premium Messaging Queuing protocol) developed in the Erlang language. RABBITMQ is said to have good performance and timeliness, while also providing excellent support for cluster and load deployments, and is ideal for use in larger distributed systems.

Rabbit mode is roughly divided into the following three types: Single mode, normal mode, mirror mode
Single mode:The simplest case, non-clustered mode, is the single instance service.

Normal Mode:The default cluster mode.
After the queue is created, if there is no other policy, the queue is clustered in normal mode. For a queue, the message entity exists only in one of the nodes, a, b two nodes have only the same metadata, that is, the queue structure, but the queue's metadata is only saved one copy, that is, the RABBITMQ node (a node) to create the queue, when the a node down, you can go to its B node to view,. Rabbitmqctl List_queues found that the queue has been lost, but the declared exchange still exists.
When the message enters the A-node queue, consumer pulls from the B-node, RABBITMQ temporarily transmits the message between A and B, takes the message entity in a and sends it to the consumer by B.
So consumer should try to connect to each node and fetch messages from it. That is, for the same logical queue, a physical queue is established on multiple nodes. Otherwise, whether consumer A or B, the export is always a, it will create a bottleneck.
One problem with this pattern is that when a node fails, the B node cannot fetch the message entities that are not yet consumed in the a node.
If you do a message persistence, you have to wait for the a node to recover before it can be consumed, and if it is not persisted, the queue data is lost.

Mirroring mode:The desired queue is made into a mirror queue, which exists in multiple nodes and belongs to the HA scheme of RABBITMQ.
This mode solves the above problem, the essence of which differs from the normal pattern in that the message entity is actively synchronizing between the mirror nodes rather than being temporarily pulled when the consumer is fetching data.
The side effects of this pattern are also obvious, in addition to reducing system performance, if the number of mirror queue, coupled with a large number of messages, the network bandwidth within the cluster will be greatly consumed by this synchronous communication.
Therefore, in the case of high reliability requirements, a queue to make a mirror queue, you need to set policy, and then the client creates the queue, the RABBITMQ cluster according to the "queue name" automatic setting is normal cluster mode or mirror queue. Specific as follows:
The queue is capable of mirroring through policy. The strategy can change at any moment, and the RABBITMQ queue may change the queue as the strategy changes, and there is a difference between the non-mirrored queue and the mirror queue, which lacks the additional mirroring infrastructure, does not have any slave, and therefore runs faster.
In order for the queue to be called a mirror queue, you will create a policy to match the queue, and set the policy to have two keys "Ha-mode and ha-params (optional)".

understand the basic concepts in a cluster:
RABBITMQ cluster nodes include memory nodes, disk nodes. As the name implies, the memory node is where all the data is placed in memory, and the disk node places the data on disk. However, as mentioned earlier, if the message is persisted when the message is posted, even the memory node, the data is safely placed on the disk.
A RABBITMQ cluster can share user,vhost,queue,exchange, and so on, all the data and state must be replicated on all nodes, with the exception that the message queue that currently belongs only to the node that created it, although they are visible and can be read by all nodes. RABBITMQ nodes can be dynamically added to the cluster, a node can be added to the cluster, or from the cluster ring cluster can be a basic load balancing.

There are two types of nodes in a cluster:
1 Memory nodes: Save state to memory only (one exception is: persistent content of a persistent queue will be saved to disk)
2 disk node: Save state to memory and disk.
A memory node is not written to disk, but it performs better than a disk node. In a cluster, only a single disk node is required to hold the state. If there are only memory nodes in the cluster, you cannot stop them, otherwise all States, messages, and so on will be lost.

second, the installation of RABBITMQ
installing RABBITMQ in 1.ubuntu16.04
1). You must first have an Erlang environment support
To install the necessary libraries before installing:
# sudo apt-get install build-essential
# sudo apt-get install Libncurses5-dev
# sudo apt-get install Libssl-dev
# sudo apt-get install M4
# sudo apt-get install UNIXODBC Unixodbc-dev
# sudo apt-get install Freeglut3-dev Libwxgtk2.8-dev
# sudo apt-get install Xsltproc
# sudo apt-get install FOP
# sudo apt-get install tk8.5

Run after installation:
# sudo apt-get install Erlang
When you are finished, enter the command in the console:
You can view the version of Erlang installation
2). Install RABBITMQ (available in two ways)

Automatic Installation
# sudo apt-get install Rabbitmq-server
If there is no problem, then install directly, do not set anything

View Run status
# Service Rabbitmq-server Status

Manual Installation
1). First create a folder to download RABBITMQ
# mkdir Rabbitmqsoft
# CD Rabbitmqsoft
2). Get the installation package (choose 2.7.0 UNIX version here)
# wget
# TAR-ZXVF Rabbitmq-server-generic-unix-2.7.0.tar.gz
# CD rabbitmq_server-2.7.0/
3). Run
# Sbin/rabbitmq-server
4). View the running status (open another terminal)
# CD ~/rabbitmqsoft/rabbitmq_server-2.7.0/
In the end, the Ubuntu system installed RABBITMQ is completed

installing RABBITMQ in 1.centos7
1). First, you need to install Erlang
#yum Install Erlang
During the installation, you will be prompted to enter "Y".
2). Install RABBITMQ after completion:
Download RPM First:
Install when download is complete:
#yum Install rabbitmq-server-3.6.6-1.el7.noarch.rpm
Start service after completion:
#service rabbitmq-server Start
You can view the status of the service:
#service rabbitmq-server Status

Third, the configuration of RABBITMQ
1. Modify the configuration file
By viewing the status of the service:
#service rabbitmq-server Status

Here you can see the location of the log file, go to the file location, open the file:

This shows that the configuration file is not found and we can create this file ourselves
#vim Rabbitmq.config
Edit the contents as follows:
[{rabbit, [{loopback_users, []}]}].
This means open use, RABBITMQ default created user Guest, password is also guest, this user default can only be native access, localhost or, from external access needs to add the above configuration.

To restart the service after saving the configuration:
#service Rabbitmq-server Stop
#service rabbitmq-server Start

2. Installing Plugins
#/sbin/rabbitmq-plugins Enable Rabbitmq_management
Restart RABBITMQ Service
#service rabbitmq-server Restart
Here, you can use Guest,guest to log on to the Web page via http://ip:15672.

iv. RABBITMQ user Roles and permissions control
1.RabbitMQ User Role categories:
None, management, policymaker, monitoring, administrator
2.RabbitMQ Description of roles:
Cannot access Management plugin

Anything a user can do with AMQP plus:
List the virtual hosts that you can log into via AMQP
View queues, exchanges and bindings in your virtual hosts
View and close your own channels and connections
View statistics about the "global" of your own virtual hosts, including the activities of other users in these virtual hosts.

Anything that management can do plus:
View, create, and delete your own virtual hosts policies and parameters

Anything that management can do plus:
List all virtual hosts, including virtual hosts that they cannot log in to
View connections and channels for other users
View node-level data such as clustering and memory usage
View real global statistics about all virtual hosts

Anything that policymaker and monitoring can do plus:
Create and delete virtual hosts
View, create, and delete users
View Create and Delete permissions
Close other users ' connections

3. Create the user and set the role:
You can create an administrator user who is responsible for the operation of the entire MQ, for example:
$sudo rabbitmqctl add_user user_admin passwd_admin
Give its administrator role:
$sudo rabbitmqctl set_user_tags user_admin Administrator

You can create a RABBITMQ monitoring user that is responsible for monitoring the entire MQ, for example:
$sudo rabbitmqctl add_user user_monitoring passwd_monitor
Give its monitoring role:
$sudo Rabbitmqctl set_user_tags user_monitoring Monitoring

You can create a dedicated user for a project and access only the project's own virtual hosts
$sudo rabbitmqctl add_user user_proj passwd_proj
Give its monitoring role:
$sudo rabbitmqctl set_user_tags user_proj Management

After creating and assigning a role, review and confirm:
$sudo Rabbitmqctl List_users

4.RabbitMQ Permissions Control
Default virtual Host: "/"
Default User: Guest
Guest has full privileges on "/" and only localhost access rabbitmq including plugin, it is recommended to remove or change the password. Restrictions on local access can be canceled by Loopback_users hole in the configuration file:
[{rabbit, [{loopback_users, []}]}]

Users can only manipulate resources in the virtual hosts that they can access. The resources here refer to the exchanges, queues, etc. in virtual hosts, and the operations include configuring, writing, and reading the resources. Configure permissions to create, delete, resource, and modify the behavior of a resource, write permission to send a message to a resource, read permission to get a message from a resource. Like what:
Declare and delete for Exchange and queue require configuration permissions on Exchange and queue, respectively
Exchange Read and Write permissions are required for bind and unbind
Queue bind with Unbind requires queue Write permission for Exchange Read permissions
Send message (publish) requires write permission for Exchange
Get or clear (get, consume, purge) messages require the Read permission of the queue
The permissions for which resources have configuration, write, and read are matched by regular expressions, with the following specific commands:
set_permissions [-P <vhostpath>] <user> <conf> <write> <read>
Where,<conf> <write> <read> locations are matched with regular expressions to match specific resources, such as ' ^ (amq\.gen.*|amq\.default) $ ' Can match server-generated and default Exchange, ' ^$ ' does not match any resources

It is important to note that RABBITMQ caches the permission validation results for each connection or channel, and therefore requires a re-connection to take effect after the permissions have changed.

Empowering the User:
$sudo rabbitmqctl set_permissions-p/vhost1 user_admin '. * '. * '. * '
This command enables the user to user_admin the configuration, write, and read permissions of all resources in this virtual host to manage the resources in the/vhost1
To view permissions:
$sudo Rabbitmqctl list_user_permissions user_admin
Listing Permissions for user "User_admin" ...
/vhost1<span style= "White-space:pre" > </span>.*<span style= "White-space:pre" > </span>.* <span style= "White-space:pre" > </span>.*

$sudo Rabbitmqctl list_permissions-p/vhost1
Listing permissions in Vhost "/vhost1" ...
User_admin<span style= "White-space:pre" > </span>.*<span style= "White-space:pre" > </span>.* <span style= "White-space:pre" > </span>.*

Linux installation RABBITMQ

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.