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

How to build RabbitMQ3.6 stand-alone multi-instance service in CentOs

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to build RabbitMQ3.6 stand-alone multi-instance service in CentOs". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to build RabbitMQ3.6 stand-alone multi-instance service in CentOs.

Introduction to rabbitmq

Rabbitmq is an open source amqp implementation, the server side is written in Erlang language, supports a variety of clients, such as: python, ruby, .net, java, jms, c, php, actionscript, xmpp, stomp, etc., supports ajax. It is used to store and forward messages in distributed systems, and performs well in terms of ease of use, scalability, high availability and so on.

Amqp, namely advanced message queuing protocol, advanced message queuing protocol, is an open standard of application layer protocol and is designed for message-oriented middleware. Message middleware is mainly used for decoupling between components, and the sender of the message does not need to know the existence of the message consumer, and vice versa.

The main features of amqp are message-oriented, queue-oriented, routing (including peer-to-peer and publish / subscribe), reliability and security.

Matters needing attention

Centos 7.x shuts down firewall

$systemctl stop firewalld.service # stop firewall

If you don't want to turn off the firewall, open port 15672. After setting it, you can manage mq through web pages.

Install iptables Firewall

Yum install iptables-services

Add configuration

Iptables-I input-p tcp-- dport 5672-j acceptiptables-I input-p tcp-- dport 15672-j accept

Save configuration

Service iptables save

Restart

Systemctl restart iptables.service

Set Boot self-boot

Systemctl enable iptables.service

Installation

Install erlang

Rabbitmq installation depends on the erlang environment

$cd / usr/local/src$ wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.centos.x86_64.rpm$ yum install erlang-19.0.4-1.el7.centos.x86_64.rpm

Install rabbitmq

$cd / usr/local/src$ wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-3.6.10-1.el7.noarch.rpm$ yum install rabbitmq-server-3.6.10-1.el7.noarch.rpm

Start the service

$service rabbitmq-server start

Service statu

$service rabbitmq-server statusredirecting to / bin/systemctl status rabbitmq-server.service ● rabbitmq-server.service-rabbitmq broker loaded: loaded (/ usr/lib/systemd/system/rabbitmq-server.service; disabled; vendor preset: disabled) active: active (running) since-2018-03-05 21:42:10 cst 15s ago main pid: 2493 (beam.smp) status: "initialized" cgroup: / system.slice/rabbitmq-server.service ├─ 2493 / usr/lib64/erlang/erts-8.0.3/bin/beam.smp-w-a 64-p 1048576-t 5000000-stbt db-zdbbl 32000-k true-- root / usr/lib64/erlang-progname erl-home / var/l... ├─ 2634 / usr/lib64/erlang/erts-8.0.3/bin/epmd-daemon ├─ 2750 erl_child_setup 1024 ├─ 2760 inet_gethost 4 └─ 2761 inet_gethost 4March 05 21:42:07 master01 rabbitmq-server [2493]: rabbitmq 3.6.10. Copyright (c) 2007-2017 pivotal software, inc.3 05 21:42:07 master01 rabbitmq-server [2493]: # licensed under the mpl. See http://www.rabbitmq.com/3 05 21:42:07 master01 rabbitmq-server [2493]: # March 05 21:42:07 master01 rabbitmq-server [2493]: # logs: / var/log/rabbitmq/rabbit@ master01.logMarch 05 21:42:07 master01 rabbitmq-server [2493]: # / var/log/rabbitmq/rabbit@master01-sasl.log3 05 21:42 07 master01 rabbitmq-server [2493]: # March 05 21:42:07 master01 rabbitmq-server [2493]: starting broker...3 05 21:42:10 master01 rabbitmq-server [2493]: systemd unit for activation check: "rabbitmq-server.service" March 05 21:42:10 master01 systemd [1]: started rabbitmq broker.3 05 21:42:10 master01 rabbitmq-server [2493]: completed with 0 plugins.

View the log

$less / var/log/rabbitmq/rabbit\ @ master01.log = info report==== 5-mar-2018::21:42:07 = = starting rabbitmq 3.6.10 on erlang 19.0.4copyright (c) 2007-2017 pivotal software, inc.licensed under the mpl. See http://www.rabbitmq.com/=info report==== 5-mar-2018::21:42:07 = = node: rabbit@master01home dir: / var/lib/rabbitmqconfig file (s): / etc/rabbitmq/rabbitmq.config (not found) cookie hash: + 9losjmr5x/9geguoed28a==log: / var/log/rabbitmq/rabbit@master01.logsasl log: / var/log/rabbitmq/rabbit@master01-sasl.logdatabase dir: / var/lib/rabbitmq/mnesia/rabbit@master01=info report==== 5Murray 2018 node: 21:42:09 = = memory limit set to 732mb of 1831mb total.=info report==== 5-mar-2018::21:42:09 = = enabling free disk space monitoring=info report==== 5-mar-2018::21:42:09 = = disk free limit set to 50mb=info report==== 5-mar-2018::21:42:09 = = limiting to approx 924 file handles (829 sockets) = info report==== 5-mar-2018::21:42:09 = = fhc read buffering: off=info report==== 5-mar-2018::21:42:07 = = starting rabbitmq 3.6.10 on erlang 19.0.4copyright (c) 2007-2017 pivotal software Inc.licensed under the mpl. See http://www.rabbitmq.com/=info report==== 5-mar-2018::21:42:07 = = node: rabbit@master01home dir: / var/lib/rabbitmqconfig file (s): / etc/rabbitmq/rabbitmq.config (not found) cookie hash: + 9losjmr5x/9geguoed28a==log: / var/log/rabbitmq/rabbit@master01.logsasl log: / var/log/rabbitmq/rabbit@master01-sasl.logdatabase dir: / var/lib/rabbitmq/mnesia/rabbit@master01=info report==== 5Murray 2018 node: 21:42:09 = memory limit set to 732mb of 1831mb total.=info report==== 5-mar-2018::21:42:09 = enabling free disk space monitoring=info report==== 5-mar-2018::21:42:09 = disk free limit set to 50mb=info report==== 5-mar-2018::21:42:09 = limiting to approx 924 file handles (829 sockets) = info report==== 5-mar-2018::21:42:09 = = fhc read buffering: offfhc write buffering: on=info report==== 5-mar-2018::21:42:09 = database directory at / var/lib/rabbitmq/mnesia/rabbit@master01 is empty. Initialising from scratch...=info report==== 5-mar-2018::21:42:09 = = waiting for mnesia tables for 30000 ms, 9 retries left=info report==== 5-mar-2018::21:42:09 = = waiting for mnesia tables for 30000 ms, 9 retries left

What is shown here is that the configuration file was not found. We can create this file ourselves.

Config file (s): / etc/rabbitmq/rabbitmq.config (not found)

Create rabbitmq.config

$cd / etc/rabbitmq/$ vim rabbitmq.config

The editing content is as follows:

[{rabbit, [{loopback_users, []}]}].

This means open use. The user created by rabbitmq by default is guest, and the password is also guest. By default, this user can only be accessed locally, localhost or 127.0.0.1. The above configuration needs to be added for external access.

Restart the service after saving the configuration

$service rabbitmq-server restart

Open the management ui

$/ sbin/rabbitmq-plugins enable rabbitmq_management

Restart the service

$service rabbitmq-server restart

Access Management ui

Use guest through http://ip:15672, guest to log in.

Authorized operation

Add user

For security reasons, guest, the default user, can only log in through http://localhost:15672, and other ip cannot use this account directly. This cannot be managed and maintained if the desktop is not installed on the server, unless it is troublesome to provide services by adding a layer of agents in the front, which is implemented through the configuration file.

Command format

Rabbitmqctl add_user $rabbitmqctl add_user zhdya 123456creating user "zhdya"

Delete user

Rabbitmqctl delete_user $rabbitmqctl delete_user admin_testdeleting user "admin_test"

Modify the password

Rabbitmqctl change_password $rabbitmqctl change_password zhdya 123456changing password for user "zhdya"

User authorization

Rabbitmqctl set_permissions [- pvhostpath] {user} {conf} {write} {read}

This command gives the user zhdya / (access to the virtual host) configuration, write, and read permissions of all resources in order to manage the resources in it.

$rabbitmqctl set_permissions-p "/" zhdya ". *" setting permissions for user "zhdya" in vhost "/"

View user authorization

Rabbitmqctl list_permissions [- p vhostpath] $rabbitmqctl list_permissions-p / listing permissions in vhost "/" guest. * zhdya. *

View the list of current users

You can see that the user was added successfully, but not the administrator role

$rabbitmqctl list_userslisting usersguest [administrator] zhdya []

Add Rol

Here we also set the ymq user to the administrator role

Command format

Rabbitmqctl set_user_tags $rabbitmqctl set_user_tags zhdya administratorsetting tags for user "zhdya" to [administrator]

View permissions again

$rabbitmqctl list_userslisting usersguest [administrator] zhdya [administrator]

Clear permission information

Rabbitmqctl clear_permissions [- p vhostpath] ymqrabbitmqctl clear_permissions-p / zhdyaclearing permissions for user "zhdya" in vhost "/"

Official document

Installation:

Access Control:

Network:

Configuration:

Cluster:

Command:

Web interface

Add user

Click on the mouse, draw a red line of the role, choose a

User role classification for rabbitmq:

None 、 management 、 policymaker 、 monitoring 、 administrator

Rabbitmq role description:

None

Cannot access management plugin

Management

Anything a user can do through amqp plus:

List the virtual hosts that you can log in to through amqp

View queues, exchanges, and bindings in your own virtual hosts

View and close your own channels and connections

View statistics about the "global" of your virtual hosts, including the activities of other users in these virtual hosts.

Policymaker

Anything management can do plus:

View, create, and delete policies and parameters to which your own virtual hosts belongs

Monitoring

Anything management can do plus:

List all virtual hosts, including virtual hosts that they cannot log in to

View the connections and channels of other users

View node-level data such as clustering and memory usage

View real global statistics about all virtual hosts

Administrator

Anything policymaker and monitoring can do, plus:

Create and delete virtual hosts

View, create, and delete users

View create and delete permissions

Turn off other users' connections

Set permissions

The user does not have access to any virtual host

Click the user name set permission

Set the configuration, write and read permissions that can access all resources in the virtual host to manage the resources in it

Now that the rabbitmq stand-alone service has been fully built, let's operate multiple instances on a single machine:

Rabbitmq single machine and multiple instances

In fact, I saw a lot of these schemes on the Internet before the operation, most of which are as follows:

Rabbitmq_node_port=5672 rabbitmq_nodename=rabbit1 rabbitmq-server-detachedrabbitmq_node_port=5673 rabbitmq_nodename=rabbit2 rabbitmq-server-detachedrabbitmq_node_port=5674 rabbitmq_nodename=rabbit3 rabbitmq-server-detached

But I think it's too crude and irresponsible for newcomers!

First node

The following specifies the specific hostname startup, of course, you can also specify as localhost.

[root@master01 sbin] # vim / etc/hosts#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6127.0.0.1 master01

Start the first node

Rabbitmq_node_port=5672 rabbitmq_nodename=rabbit@master01. / rabbitmq-server

Second node

[root@master01 sbin] # rabbitmq_node_port=5673 rabbitmq_nodename=rabbit1@master01 rabbitmq-server-detachedwarning: pid file not written;-detached was passed.

You may not find anything, and if you remove-detached, you will find that you end up with an error message like this: crashed message.

Crash dump is being written to: erl_crash.dump...done

Flip up the message or check the log, and you'll see a prompt like this:

Boot failed=error description: {could_not_start,rabbitmq_mqtt, {{shutdown, {failed_to_start_child,'rabbit_mqtt_listener_sup_:::1883', {shutdown, {failed_to_start_child, {ranch_listener_sup, {acceptor, {0,0,0,0,0,0,0,0}, 1883}}, {shutdown, {failed_to_start_child,ranch_acceptors_sup, {listen_error, {acceptor, {0,0,0,0 0,0,0,0}, 1883}, eaddrinuse}, {rabbit_mqtt,start, [normal, []]}

Start the second node

[root@master01 sbin] # rabbitmq_node_port=5673 rabbitmq_server_start_args= "- rabbitmq_management listener [{port,15673}]-rabbitmq_stomp tcp_listeners [61614]-rabbitmq_mqtt tcp_listeners [1884]" rabbitmq_nodename=rabbit1. / rabbitmq-server-detachedwarning: pid file not written;-detached was passed.

View the port:

[root@master01 sbin] #! netnetstat-lntp active 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. 015. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 00 of the proto recv-q send-q local address foreign address state pid/program name tcp 22 0. 0. 0. 0. 0. 0 of the proto recv-q send-q local address foreign address state pid/program name tcp * listen 1348/sshd tcp 0 0. 0. 0. 0. 0. 0. 0 of the 15 672 0. 0. 0. 0 of the proto recv-q send-q local address foreign address state pid/program name tcp * listen 3598/beam.smp tcp 0 0 0.0.0.0 listen 2065/master tcp 15673 0.0.0.0 * listen 5679/beam.smp tcp 0 0127.0.0.1 listen 2065/master tcp 25 0.0.0.0 * listen 2065/master tcp 0 0 0.0.0.014 25672 0.0.0.0 * listen 3598/beam.smp tcp 000.0.0.015 25673 0.0.0.0 * listen 5679 / beam.smp tcp6 00: 3306: * listen 1418/mysqld tcp6 00: 4369:: * listen 3779/epmd tcp6 00: 22: * listen 1348/sshd tcp6 00:: 1:25:: * listen 2065/master tcp6 00: 5672: * listen 3598/beam.smp tcp6 00: 5673:: * listen 5679/beam.smp

View the status of rabbit1:

Cd / sbin/./rabbitmqctl status-n rabbit1

The third node

[root@master01 sbin] # rabbitmq_node_port=5674 rabbitmq_nodename=rabbit2@master01 rabbitmq-server-detachedwarning: pid file not written;-detached was passed.

Start the third node

[root@master01 sbin] # rabbitmq_node_port=5674 rabbitmq_server_start_args= "- rabbitmq_management listener [{port,15674}]-rabbitmq_stomp tcp_listeners [61615]-rabbitmq_mqtt tcp_listeners [1885]" rabbitmq_nodename=rabbit2. / rabbitmq-server-detachedwarning: pid file not written;-detached was passed.

View the status of rabbit2:

Cd / sbin/./rabbitmqctl status-n rabbit2

View startup status:

[root@master01 sbin] #! netnetstat-lntp active internet connections (only servers) proto recv-q send-q local address foreign address state pid/program name tcp 0 0 0.0.0 0 only servers 25674 0.0 0 proto recv-q send-q local address foreign address state pid/program name tcp * listen 6759/beam.smp tcp 0 0 0 0.0 0 0 7 3 69 0 0 0 8 * listen 3779/epmd tcp 0 0 0. 0 0 Listen 1348/sshd tcp 0 0 0.0.0. 0 listen 1348/sshd tcp 15672 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. Listen 5679/beam.smp tcp 0 0 127. 0. 0. 0. 1 listen 5679/beam.smp tcp 25 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0 of the listen 2065/master tcp 15674 0. 0. 0. 0. 0 of the listen 6759. / beam.smp tcp 0 0 0.0.0 0 listen 6759/beam.smp tcp6 25672 0.0.0 listen 5679/beam.smp tcp6 0 0:: 5674:: * listen 6759/beam.smp tcp6 0 0: * listen 1418/mysqld tcp6 0 0: 4369:: * Listen 3779/epmd tcp6 0 0: 22: * listen 1348/sshd tcp6 0 0:: 1:25:: * listen 2065/master tcp6 0 0: 5672: * listen 3598/beam.smp tcp6 0 0: 5673:: * listen 5679/beam.smp

In this case, you can visit web through: http://192.168.161.161:15672/#/, http://192.168.161.161:15673/#/, http://192.168.161.161:15674/#/ to see if the relevant nodes really exist. Here is how to implement the cluster operation.

Cluster operation

Add node rabbit1 to rabbit

1. Stop the application of the second node

. / rabbitmqctl-n rabbit1@master01 stop_app

two。 Reset the metadata and status of the second node to the empty state.

. / rabbitmqctl-n rabbit1@master01 reset

3. Join the first node

. / rabbitmqctl-n rabbit1@master01 join_cluster rabbit@localhost

4. Restart the second node

. / rabbitmqctl-n rabbit1@master01 start_app

Now log in to the web interface again and you can go to the web and see that the cluster already exists!

Add node rabbit2 to rabbit

Same as 1234 in the previous step: note that if you need to set the third cluster node to memory mode instead of disk mode, you can refer to the current version of the command prompt and add the-ram parameter at the end

Complete command to add the third node

. / rabbitmqctl-n rabbit2@master01 stop_app./rabbitmqctl-n rabbit2@master01 reset./rabbitmqctl-n rabbit2@master01 join_cluster rabbit@master01./rabbitmqctl-n rabbit2@master01 start_app

Note: as in step 3 above, if you want to set the third cluster node to memory mode instead of disk mode, you need-- ram

. / rabbitmqctl-n rabbit2@master01 join_cluster rabbit@master01-- ram

View cluster status

. / rabbitmqctl cluster_status-n rabbit@localhost [root@master01 sbin] #. / rabbitmqctl cluster_status-n rabbit@localhostcluster status of node rabbit@localhost [{nodes, [{disc, ['rabbit1@master01','rabbit2@master01', rabbit@localhost]}]}, {running_nodes, [' rabbit2@master01','rabbit1@master01', rabbit@localhost]}, {cluster_name,}, {partitions, []}, {alarms, [{'rabbit2@master01', []} {'rabbit1@master01', []}, {rabbit@localhost, []}]

Go to the web end to see the effect!

At this point, the cluster has been built.

Problems encountered:

Rabbitmq may fail to start after installation, such as:

Applying plugin configuration to rabbit@192... Failed.* could not contact node rabbit@192.changes will take effect at broker restart.* options:-- online-fail if broker cannot be contacted.--offline-do not try to contact broker.error: unable to connect to node rabbit@192: nodedowndiagnostics=attempted to contact: [rabbit@192] rabbit@192:* unable to connect to epmd (port 4369) on: badarg (unknown posix error) current node details:- node name: 'rabbitmq-cli-97@192'- home dir: / var/lib/rabbitmq- cookie Hash: rb2cnggdqm+k5+jq1wj6vg==error: unable to connect to node rabbit@192: nodedown

Solution.

Vi / etc/rabbitmq/rabbitmq-env.conf

Write "nodename=rabbit@localhost" in the file and save it.

At this point, I believe you have a deeper understanding of "how to build RabbitMQ3.6 stand-alone multi-instance service in CentOs". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report