Rabbitmq installation and configuration

Source: Internet
Author: User
Rabbitmq

Rabbitmq is an open-source implementation of amqp developed by Erlang. Amqp: Advanced Message Queue, Advanced Message Queue Protocol. It is an open standard for the application layer protocol and is designed for message-oriented middleware. The client and message-oriented middleware based on this protocol can transmit messages and are not subject to product or development language conditions.

What is a message queue?

Message refers to the data transmitted between applications. Messages can be very simple. For example, messages that only contain text strings can be more complex and may contain embedded objects. Message Queue is a communication method between applications. messages can be returned immediately after being sent. The message system ensures reliable transmission of messages. The message publisher only publishes messages to MQ, but does not care who gets them. The message consumer only obtains messages from MQ, regardless of who publishes them. In this way, both the publisher and the user do not need to know the other party's existence.

Why Message Queue

From the above description, we can see that message queue is an asynchronous collaboration mechanism between applications. When do I need to use MQ? Taking the common order system as an example, the business logic after you click the "place order" button may include: Inventory deduction, generating corresponding documents, sending red packets, and sending text message notifications. In the early stages of business development, these logics may be put together for Synchronous execution. As the business grows, the order volume increases and the system service performance needs to be improved, in this case, some operations that do not need to take effect immediately can be split into asynchronous operations, such as red packets and text message notifications. In this scenario, MQ can be used to send a message to MQ after the main process (such as inventory deduction and corresponding document generation) of the Order is completed, so that the main process can be quickly completed, another independent thread pulls MQ messages (or pushes messages by MQ). When MQ finds messages such as red packets or text messages, it executes the corresponding business logic. The above is used for business decoupling. Other common scenarios include final consistency, broadcast, and peak-to-peak traffic control.

Rabbitmq features

Rabbitmq is an open-source implementation of amqp developed by Erlang. Amqp: Advanced Message Queue, Advanced Message Queue Protocol. It is an open standard for the application layer protocol and is designed for message-oriented middleware. The client and message-oriented middleware based on this protocol can transmit messages and are not subject to product or development language conditions. Rabbitmq originally originated from the financial system and is used to store and forward messages in distributed systems. It has good performance in terms of ease of use, scalability, and high availability. Specific features include:

  1. Reliability)
    Rabbitmq uses some mechanisms to ensure reliability, such as persistence, transmission validation, and release validation.
  2. Flexible Routing)
    Exchange is used to route messages before they enter the queue. Rabbitmq provides some built-in exchange for typical routing functions. For more complex routing functions, You can bind multiple exchanges together and implement your own exchange through the plug-in mechanism.
  3. Clustering)
    Multiple rabbitmq servers can form a cluster to form a logical broker.
  4. High Availability (highly available queues)
    The queue can be mirrored on machines in the cluster, so that the queue is still available when some nodes have problems.
  5. Multi-Protocol)
    Rabbitmq supports multiple Message Queue protocols, such as stomp and mqtt.
  6. Multi-language Client)
    Rabbitmq supports almost all common languages, such as Java,. net, and Ruby.
  7. Management UI)
    Rabbitmq provides an easy-to-use user interface that allows users to monitor and manage many aspects of Message Broker.
  8. Tracing)
    If a message is abnormal, rabbitmq provides a message tracking mechanism to identify what happened.
  9. Plugin system)
    Rabbitmq provides many plug-ins to expand from multiple aspects, or you can write your own plug-ins.
Install rabbitmq

Rabbitmq can be directly installed through software repositories such as Yum, but the versions are generally conservative. The rabbitmq official website provides a new version of the RPM package (http://www.rabbitmq.com/download.html), but the installation will prompt the need for Erlang version> = 19.3, but the default Yum repository version is lower. In fact, rabbitmq provides a new Erlang package (https://github.com/rabbitmq/erlang-rpm) on GitHub, which can also be directly added to the yum source.

#cat /etc/yum.repos.d/rabbitmq-erlang.repo[rabbitmq-erlang]name=rabbitmq-erlangbaseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7gpgcheck=1gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.ascrepo_gpgcheck=0enabled=1#yum clean all#yum makecache

Then download the RPM package (http://www.rabbitmq.com/download.html) of rabbitmq)

Here is the centos7 version # wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.4/rabbitmq-server-3.7.4-1.el7.noarch.rpm#yum install rabbitmq-server-3.7.4-1.el7.noarch.rpmyum will automatically go to the source to install dependency packages

Installation is complete here

Basic operations
$ Sudo chkconfig rabbitmq-server on # Add and start the rabbitmq service $ sudo/sbin/service rabbitmq-Server start # Start the service $ sudo/sbin/service rabbitmq-server status # view the service status $ sudo/sbin/service rabbitmq-server stop # Stop the service # view all current users $ sudo rabbitmqctl list_users # view the permissions of Default Guest users $ sudo rabbitmqctl list_user_permissions guest # The default account of rabbitmq the username and password are both guest. For security, delete the Default User $ sudo rabbitmqctl delete_user guest # Add a new user $ sudo rabbitmqctl add_user Username Password # Set User tag $ sudo rabbitmqctl set_user_tags username administrator # grant all operation permissions for the default vhost $ sudo rabbitmqctl set_permissions-P/username ". *"". *"". * "# view User Permissions $ sudo rabbitmqctl list_user_permissions Username

More aboutrabbitmqctlFor more information, see the help manual.

Enable Web Management Interface

It is inconvenient to operate rabbitmq only from the command line. Fortunately, rabbitmq comes with the Web management interface, which can be used only by starting the plug-in.

$ sudo rabbitmq-plugins enable rabbitmq_management

Then access: IP: 15672 through a browser

Enter the user name and password to access the Web management interface.

Configure rabbitmq

For the configuration of rabbitmq, you can download the configuration file template of rabbitmq/etc/rabbitmq/rabbitmq.configAnd then change it as needed. For more information about the specific functions of each configuration item, see the official documentation. After updating the configuration, do not forget to restart the service.

#!/bin/bashrpm -vih epel-release-latest-6.noarch.rpmyum install -y erlangrpm -vih rabbitmq-server-3.3.4-1.noarch.rpmmkdir -p /data/rabbitmqmkdir -p /data/weblogs/rabbitmqchown -R rabbitmq:rabbitmq /data/weblogs/rabbitmq/chown -R rabbitmq:rabbitmq /data/rabbitmq/cat >> /etc/rabbitmq/rabbitmq-env.conf<<EOFRABBITMQ_MNESIA_BASE=/data/rabbitmq/mnesiaRABBITMQ_LOG_BASE=/data/weblogs/rabbitmqEOF/usr/sbin/rabbitmq-plugins enable rabbitmq_managementcp /usr/share/doc/rabbitmq-server-3.3.4/rabbitmq.config.example /etc/rabbitmq/rabbitmq.configsed -i ‘9a\    {loopback_users, []}‘ /etc/rabbitmq/rabbitmq.confi
Enable remote access

By default, the defaultguestThe user only allows access from the local machine.guestYou only needloopback_usersLeave the list empty, as shown below:

{loopback_users, []}

In addition, the newly added users can be accessed remotely. If you want to allow only local access to the newly added users, you can add the user name to the list above. For example, only allowadminUser access on the local machine.

{loopback_users, ["admin"]}

Update the configuration and restart it.

[[Email protected] Access] # systemctl status rabbitmq-server ● rabbitmq-server.service-rabbitmq broker loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; Enabled; vendor preset: Disabled) active: active (running) Since wed 2018-10-31 21:50:01 CST; 13 h ago main PID: 30926 (beam. SMP) Status: "initialized" cgroup:/system. slice/rabbitmq-server.service restart-30926/usr/lib64/Erlang/erts-9.3.3.4/bin/beam. SMP-w-a 128-P 1048576-T 5000000-stbt DB-zdbbl 1280000-K true ---root/usr/lib64/Erlang-progname ERL ---home/var/... capacity-31097/usr/lib64/Erlang/erts-9.3.3.4/bin/EPMD-daemon capacity-31322 erl_child_setup 1024 capacity-31358 inet_gethost 4 Capacity-31359 inet_gethost 4oct 31 21:50:00 localhost. localdomain rabbitmq-server [30926]: #### Oct 31 21:50:00 localhost. localdomain rabbitmq-server [30926]: #### rabbitmq 3.7.4. copyright (c) 2007-2018 pivotal software, Inc. oct 31 21:50:00 localhost. localdomain rabbitmq-server [30926]: ######### licensed under the MPL. see http://www.rabbitmq.com/Oct 31 21:50:00 localhost. localdomain rabbitmq-server [30926]: ####### Oct 31 21:50:00 localhost. localdomain rabbitmq-server [30926]: ######### logs:/data/weblogs/rabbitmq/[email protected] Oct 31 21:50:00 localhost. localdomain rabbitmq-server [30926]:/data/weblogs/rabbitmq/[email protected] _ upgrade. logoct 31 21:50:00 localhost. localdomain rabbitmq-server [30926]: Starting broker... oct 31 21:50:01 localhost. localdomain rabbitmq-server [30926]: systemd unit for activation check: "rabbitmq-server.service" Oct 31 21:50:01 localhost. localdomain systemd [1]: started rabbitmq broker. oct 31 21:50:01 localhost. localdomain rabbitmq-server [30926]: Completed with 0 plugins. here we can see the location of the log file, go to the file location, and open the file:

Firewall Configuration:

/sbin/iptables -I INPUT -p tcp --dport 5672 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 15672 -j ACCEPT

Rabbitmq installation and configuration

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: info-contact@alibabacloud.com 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.