Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The process of building RabbitMQ message middleware

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "RabbitMQ message middleware building process", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "RabbitMQ message middleware building process"!

Introduction to 1.RabbitMQ

Message middleware can also be called message queue, which refers to the platform-independent data exchange with efficient and reliable message delivery mechanism, and the integration of distributed systems based on data communication. By providing messaging and message queuing models, the communication of processes can be extended in a distributed environment. RabbitMQ is an open source message queuing system developed in Erlang language and implemented based on AMQP protocol. The main features of AMQP are message-oriented, queue-oriented, routing (including peer-to-peer and publish / subscribe), reliability and security. AMQP protocol is more used in scenarios with high requirements for data consistency, stability and reliability in enterprise systems, and the requirements for performance and throughput are secondary. Erlang is a general concurrency-oriented programming language.

Reliability.

Expansibility

High availability

Multiple protocols

Multilingual client

Management interface

Plug-in mechanism

two。 Cluster deployment 1. Environment deployment and software installation prepare three virtual machines 192.168.13.139 rabbitmq-1192.168.13.142 rabbitmq-2192.168.13.143 rabbitmq-3

Configure the hosts file to change the computer names of the three MQ nodes to rabbitmq-1, rabbitmq-2, and rabbitmq-3, respectively, then modify the hosts configuration and turn off the firewall and selinux

192.168.13.139 [root @ rabbitmq-1 ~] # hostnamectl set-hostname rabbitmq-1 [root@rabbitmq-1 ~] # vim / etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.13.139 rabbitmq-1192.168.13.142 rabbitmq-2192.168.13.143 rabbitmq-3 [root@rabbitmq-1 ~] # systemctl stop firewalld & & setenforce 0192.168.13.142 [root@rabbitmq -2 ~] # hostnamectl set-hostname rabbitmq-2 [root@rabbitmq-2 ~] # vim / etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.13.139 rabbitmq-1192.168.13.142 rabbitmq-2192.168.13.143 rabbitmq-3 [root@rabbitmq-2 ~] # systemctl stop firewalld & & setenforce 0192.168.13.143 [root @ rabbitmq-3 ~] # hostnamectl set-hostname rabbitmq- 3 [root@rabbitmq-3 ~] # vim / etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.13.139 rabbitmq-1192.168.13.142 rabbitmq-2192.168.13.143 rabbitmq-3 [root@rabbitmq-3 ~] # systemctl stop firewalld & & setenforce 0

Install rabbitmq software and configure

192.168.13.139 [root @ rabbitmq-1 ~] # yum install-y * epel* gcc-c++ unixODBC unixODBC-devel openssl-devel ncurses-devel1.yum install Erlang [root @ rabbitmq-1 ~] # wget-- content-disposition https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-20.3-1.el7.centos.x86_64.rpm/download.rpm # Erlang environment package [root ~] # yum install erlang-20.3-1. El7.centos.x86_64.rpm-y test [root@rabbitmq-1 ~] # erlErlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false] Eshell V9.3 (abort with ^ G) 1 > 2. Install rabbitmq [root @ rabbitmq-1 ~] # wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.5/rabbitmq-server-3.7.5-1.el7.noarch.rpm[root@rabbitmq-1 ~] # yum-y install rabbitmq-server-3.7.5-1.el7.noarch.rpm3. Launch [root@rabbitmq-1 ~] # systemctl daemon-reload [root@rabbitmq-1 ~] # systemctl start rabbitmq-server [root@rabbitmq-1 ~] # systemctl enable rabbitmq-server [root@rabbitmq-1 ~] # systemctl status rabbitmq-se server [root @ rabbitmq-1 ~] # rabbitmq-plugins enable rabbitmq_management # Management Interface # if an error is reported, restart the service

192.168.13.1394. Note for creating users: add user and password [root@rabbitmq-1 ~] # rabbitmqctl add_user yjssjm yjssjmAdding user "yjssjm" in a machine operation. Set to administrator [root@rabbitmq-1 ~] # rabbitmqctl set_user_tags yjssjm administratorSetting tags for user "yjssjm" to [administrator]... Check the user [root@rabbitmq-1 ~] # rabbitmqctl list_usersListing users... guest [administrator] yjssjm [administrator]... room.[ root @ rabbitmq-1 ~] # rabbitmqctl set_permissions-p "/" yjssjm ". *" Setting permissions for user "yjssjm" in vhost "/". When setting permissions here, note that there are three spaces between'.* 'that represent conf permissions. Read permissions and write permissions for example: when not given 5. Enable user remote login [root@rabbitmq-1 ~] # cd / etc/rabbitmq/ [root@rabbitmq-1 rabbitmq] # cp / usr/share/doc/rabbitmq-server-3.7.5/rabbitmq.config.example / etc/rabbitmq/ rabbitmq.config.config[ root @ rabbitmq-1 rabbitmq] # lsenabled_plugins rabbitmq.config[ root @ rabbitmq-1 rabbitmq] # vim rabbitmq.config and modify it as follows: around line 61 {loopback_users []} [root@rabbitmq-1 ~] # systemctl restart rabbitmq-server # restart the service

192.168.13.142 [root @ rabbitmq-2 ~] # yum install-y * epel* gcc-c++ unixODBC unixODBC-devel openssl-devel ncurses-devel1.yum install Erlang [root @ rabbitmq-2 ~] # wget-- content-disposition https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-20.3-1.el7.centos.x86_64.rpm/download.rpm # Erlang environment package [root ~] # yum install erlang-20.3-1. El7.centos.x86_64.rpm-y [rabbitmq-2 ~] # erlErlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false] Eshell V9.3 (abort with ^ G) 1 > 2. Install rabbitmq [root @ rabbitmq-2 ~] # wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.5/rabbitmq-server-3.7.5-1.el7.noarch.rpm[root@rabbitmq-2 ~] # yum-y install rabbitmq-server-3.7.5-1.el7.noarch.rpm3. Start [root@rabbitmq-2 ~] # systemctl daemon-reload [root@rabbitmq-2 ~] # systemctl start rabbitmq-server [root@rabbitmq-2 ~] # systemctl enable rabbitmq-server [root@rabbitmq-2 ~] # systemctl status rabbitmq-se server [root @ rabbitmq-2 ~] # rabbitmq-plugins enable rabbitmq_management # management interface # if you report an error, restart the service 4. Enable user remote login [root@rabbitmq-2 ~] # cd / etc/rabbitmq/ [root@rabbitmq-2 rabbitmq] # cp / usr/share/doc/rabbitmq-server-3.7.5/rabbitmq.config.example / etc/rabbitmq/ rabbitmq.config.config[ root @ rabbitmq-2 rabbitmq] # lsenabled_plugins rabbitmq.config[ root @ rabbitmq-2 rabbitmq] # vim rabbitmq.config and modify it as follows: around line 61 {loopback_users []} [root@rabbitmq-2 ~] # systemctl restart rabbitmq-server192.168.13.143 [root@rabbitmq-3 ~] # yum install-y * epel* gcc-c++ unixODBC unixODBC-devel openssl-devel ncurses-devel1.yum install Erlang [root @ rabbitmq-3 ~] # wget-- content-disposition https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-20.3-1.el7.centos.x86_64.rpm/download.rpm # Erlang environment package [root @ rabbitmq-3 ~] # yum install erlang-20.3-1.el7.centos.x86_64.rpm-y [root @ rabbitmq-3 ~] # erlErlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false] Eshell V9.3 (abort with ^ G) 1 > 2. Install rabbitmq [root @ rabbitmq-3 ~] # wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.5/rabbitmq-server-3.7.5-1.el7.noarch.rpm[root@rabbitmq-3 ~] # yum-y install rabbitmq-server-3.7.5-1.el7.noarch.rpm3. Start [root@rabbitmq-3 ~] # systemctl daemon-reload [root@rabbitmq-3 ~] # systemctl start rabbitmq-server [root@rabbitmq-3 ~] # systemctl enable rabbitmq-server [root@rabbitmq-3 ~] # systemctl status rabbitmq-se server [root @ rabbitmq-3 ~] # rabbitmq-plugins enable rabbitmq_management # management interface # if you report an error, restart the service 4. Open the user remote login [root@rabbitmq-3 ~] # cd / etc/rabbitmq/ [root@rabbitmq-3 rabbitmq] # cp / usr/share/doc/rabbitmq-server-3.7.5/rabbitmq.config.example / etc/rabbitmq/ rabbitmq.config[ root @ rabbitmq-3 rabbitmq] # lsenabled_plugins rabbitmq.config[ root @ rabbitmq-3 rabbitmq] # vim rabbitmq.config and modify it as follows: around line 61 {loopback_users, []} [root@rabbitmq-3 ~] # systemctl restart rabbitmq-server2. Visit the web page to view the port [root@rabbitmq-1 rabbitmq] # netstat-lntpActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0: 22 0.0.0.0 LISTEN 985/sshd tcp * 15672 0.0.0.0 * LISTEN 988/beam.smp tcp 0 0127.0.1 15 0.0.0.0 LISTEN 1285/master tcp 0 0 0.0.0.0 LISTEN 1205/epmd tcp6 25672 0.0.0.0 LISTEN 1205/epmd tcp6 0 0: 4369: 22 : * LISTEN 985/sshd tcp6 0 0:: 1:25:: * LISTEN 1285/master tcp6 0 0: 5672:: * LISTEN 988/beam.smp = 4369-- erlang port 5672-- Program connection port 15672-- Management interface ui port 25672-- Internal communication port between server

Access page: 192.168.13.139guest rabbitmq default administrator user: guest password: guest newly added user: yjssjm password: yjssjm

3. Deploy the cluster 192.168.13.1391. First, create a data storage directory and a log storage directory: [root@rabbitmq-1 ~] # mkdir-p / data/rabbitmq/ data [root @ rabbitmq-1 ~] # mkdir-p / data/rabbitmq/ logs [root @ rabbitmq-1 ~] # chmod 777-R / data/ rabbitmq [root @ rabbitmq-1 ~] # chown rabbitmq.rabbitmq / data/-R [root @ rabbitmq-1 ~] # vim / etc/rabbitmq/rabbitmq-env.conf # create a configuration file Add the following: RABBITMQ_MNESIA_BASE=/data/rabbitmq/dataRABBITMQ_LOG_BASE=/data/rabbitmq/ logs [root @ rabbitmq-1 ~] # systemctl restart rabbitmq-server # restart service 2. The cluster that copies erlang.cookieRabbitmq is attached to the cluster of erlang, so the cluster of erlang must be built first. The nodes in the Erlang cluster are implemented through each cookie, this cookie is stored in / var/lib/rabbitmq/.erlang.cookie, and the file has 400 permissions. Therefore, it is necessary to ensure that the cookie of each node is the same, otherwise the nodes will not be able to communicate. (the official document introducing the cluster mentioned that .erlang.cookies usually exist at these two addresses: the first is home/.erlang.cookie; and the second place is / var/lib/rabbitmq/.erlang.cookie. If we unzipped the deployed rabbitmq, the file would be in the {home} directory, which is $home/.erlang.cookie. If we install it using an installation package such as rpm, this file will be in the / var/lib/rabbitmq directory.) = [root@rabbitmq-1 ~] # cat / var/lib/rabbitmq/.erlang.cookieHOUCUGJDZYTFZDSWXTHJscp copies the value of the .erlang.cookie of the rabbitmq-1 node to the other two nodes. [root@rabbitmq-1 ~] # scp / var/lib/rabbitmq/.erlang.cookie root@192.168.13.142:/var/lib/rabbitmq/ [root @ rabbitmq-1 ~] # scp / var/lib/rabbitmq/.erlang.cookie root@192.168.13.143:/var/lib/rabbitmq/192.168.13.1421. First, create a data storage directory and a log storage directory: [root@rabbitmq-2 ~] # mkdir-p / data/rabbitmq/ data [root @ rabbitmq-2 ~] # mkdir-p / data/rabbitmq/ logs [root @ rabbitmq-2 ~] # chmod 777-R / data/ rabbitmq [root @ rabbitmq-2 ~] # chown rabbitmq.rabbitmq / data/-R [root @ rabbitmq-2 ~] # vim / etc/rabbitmq/rabbitmq-env.conf # create a configuration file Add the following: RABBITMQ_MNESIA_BASE=/data/rabbitmq/dataRABBITMQ_LOG_BASE=/data/rabbitmq/ logs [root @ rabbitmq-2 ~] # systemctl restart rabbitmq-server # restart service 2. Add mq-2 as a memory node to the mq-1 node cluster [root@rabbitmq-2 ~] # rabbitmqctl stop_app # stop node, remember not to stop service [root@rabbitmq-2 ~] # rabbitmqctl reset # if there is data that needs to be reset, do not use it

If you execute the command # rabbitmqctl stop_app, an error is reported.

Pay attention to check the echo. If it is not in the above picture, it is an error. If there is an error, restart the rabbitmq service [root@rabbitmq-2 ~] # systemctl restart rabbitmq-server if it still reports an error: give the passed file the correct permissions [root@rabbitmq-2 ~] # chmod 400 / var/lib/rabbitmq/ .erlang.cookie [root @ rabbitmq-2 ~] # chown rabbitmq.rabbitmq / var/lib/rabbitmq/.erlang.cookie add node 2 to the cluster Specify the role [root@rabbitmq-2 ~] # rabbitmqctl join_cluster-- ram rabbit@rabbitmq-1 # add to the memory node Clustering node 'rabbit@rabbitmq-2' with' rabbit@rabbitmq-1'... [root@rabbitmq-2 ~] # rabbitmqctl start_app # launch node Starting node 'rabbit@rabbitmq-2'... Completed with 3 plugins.192.168.13.1431. First, create a data storage directory and a log storage directory: [root@rabbitmq-3 ~] # mkdir-p / data/rabbitmq/ data [root @ rabbitmq-3 ~] # chmod-p / data/rabbitmq/ logs [root @ rabbitmq-3 ~] # chmod 777-R / data/ rabbitmq [root @ rabbitmq-3 ~] # chown rabbitmq.rabbitmq / data/-R [root @ rabbitmq-3 ~] # vim / etc/rabbitmq/rabbitmq-env.conf add the following : RABBITMQ_MNESIA_BASE=/data/rabbitmq/dataRABBITMQ_LOG_BASE=/data/rabbitmq/ logs [root @ rabbitmq-3 ~] # systemctl restart rabbitmq-server 2. Add mq-2 as a memory node to the mq-1 node cluster [root@rabbitmq-3 ~] # rabbitmqctl stop_app [root@rabbitmq-3 ~] # rabbitmqctl reset [root@rabbitmq-3 ~] # rabbitmqctl join_cluster-- ram rabbit@rabbitmq-1Clustering node 'rabbit@rabbitmq-3' with' rabbit@rabbitmq-1'. [root@rabbitmq-3 ~] # rabbitmqctl start_appStarting node 'rabbit@rabbitmq-3'. Completed with 3 plugins. (1) the default rabbitmq is the disk node after startup. Under this cluster command, mq-2 and mq-3 are the memory nodes, and mq-1 is the disk node. (2) if you want to make mq-2 and mq-3 both disk nodes, you can remove the-ram parameter. (3) if you want to change the node type, you can use the command rabbitmqctl change_cluster_node_typedisc (ram), as long as the rabbitmq application must be stopped.

View cluster status

Execute rabbitmqctl cluster_status on any node of the RabbitMQ cluster to see if the cluster configuration is successful. Check [root@rabbitmq-1 ~] # rabbitmqctl cluster_status on the mq-1 disk node

Each machine shows three nodes, indicating that it has been added successfully! Log in to view, open a browser and enter http://192.168.13.139:15672

Thank you for your reading. the above is the content of "the process of building RabbitMQ message middleware". After the study of this article, I believe you have a deeper understanding of the process of building RabbitMQ message middleware, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report