Set up a RabbitMq cluster and a rabbitmq Cluster

Source: Internet
Author: User
Tags set cookie rabbitmq

Set up a RabbitMq cluster and a rabbitmq Cluster

Lab environment:

The operating system is Centos 7.2.

IP hostName

192.168.190.132 node132

192.168.190.139 node139

192.168.190.140 node140

RabbitMQ Port

  • 4369 (epmd)
  • 5672,567 1 (AMQP 0-9-1 and 1.0 without and with TLS)
  • 25672. this port used by Erlang distribution for inter-node and CLI tools communication and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000 ). seeNetworking guideFor details.
  • 15672 (if management plugin is enabled)
  • 61613,616 14 (if STOMP is enabled)
  • 1883,888 3 (if MQTT is enabled)

    Enable Firewall settings for corresponding ports

    Add an EPEL Source

    [Root @ node139 ~] # Rpm-Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

    Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

    Warning:/var/tmp/rpm-tmp.2hDPSr: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY

    Preparing... ################################### [100%]

    Updating/installing...

    1: epel-release-7-8 ################################# [100%]


    Add an Erlang Source

    [Root @ node139 ~] # Rpm-Uvh http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm

    Retrieving http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm

    Preparing... ################################### [100%]

    Updating/installing...

    1: erlang-solutions-1.0-1 ################################# [100%]

    -- 06:34:38 -- http://packages.erlang-solutions.com/rpm/centos/erlang_solutions.repo

    Resolving packages.erlang-solutions.com (packages.erlang-solutions.com)... 31.172.186.53

    Connecting to packages.erlang-solutions.com (packages.erlang-solutions.com) | 31.172.186.53 |: 80... connected.

    HTTP request sent, awaiting response... 200 OK

    Length: 245

    Saving to: 'erlang _ solutions. repo'

    100% [============================================== =========================================>] 245 --. -K/s in 0 s

    06:34:39 (27.5 MB/s)-'erlang _ solutions. repo' saved [245/245]


    Install RabbitMQ

    Software Version: http://www.rabbitmq.com/releases/rabbitmq-server

    [Root @ node139 ~] # Wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-3.6.6-1.el7.noarch.rpm

    [Root @ node139 ~] # Rpm -- import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc

    [Root @ node139 ~] # Yum install rabbitmq-server-3.6.6-1.el7.noarch.rpm

    Start the service

    [Root @ node139 ~] # Systemctl enable rabbitmq-server.service

    [Root @ node139 ~] # Systemctl start rabbitmq-server.service


    Enable the RabbitMQ monitoring plug-in

    [Root @ node139 ~] # Rabbitmq-plugins enable rabbitmq_management

    The following plugins have been enabled:

    Mochiweb

    Webmachine

    Rabbitmq_web_dispatch

    Amqp_client

    Rabbitmq_management_agent

    Rabbitmq_management

    Applying plugin configuration to rabbit @ node139... started 6 plugins.

    [Root @ node139 ~] # Netstat-apn | grep 15672

    Tcp 0 0 0.0.0.0: 15672 0.0.0.0: * LISTEN 4119/beam. smp


    RabbitMQ user management

    Add User (username root, password admin)

    [Root @ node139 ~] # Rabbitmqctl add_user admin

    Set User Role (set admin user as Administrator)

    [Root @ node139 ~] # Rabbitmqctl set_user_tags admin administrator

    Setting tags for user "admin" to [administrator]...

    Set User Permissions (set admin user configuration, write, and read permissions)

    [Root @ node139 ~] # Rabbitmqctl set_permissions-p/admin ".*"".*"".*"

    Setting permissions for user "admin" in vhost "/"...

    Delete a user (delete a guest user)

    [Root @ node139 ~] # Rabbitmqctl delete_user guest

    RabbitMQ cluster configuration

    The cluster is configured on the basis of the single-host configuration.

    The following uses node140 as an example. node132 must perform the same operation.

    • Add/etc/hosts entries

    Add:

    192.168.190.132 node132
    192.168.190.139 node139
    192.168.190.140 node140

    • Set Cookie for each node

    Rabbitmq clusters rely on erlang clusters. Therefore, you must first build an erlang cluster environment. Each node in the Erlang cluster is implemented through a magic cookie. This cookie is stored in/var/lib/rabbitmq/. erlang. cookie, and the file has 400 permissions. Therefore, ensure that the cookies of each node are consistent; otherwise, the communication between nodes fails.

    [Root @ node140/] # echo-n "AZVOCZYZZBVFLBPTBXU">/var/lib/rabbitmq/. erlang. cookie

    [Root @ node140 ~] # Chown rabbitmq: root/var/lib/rabbitmq/. erlang. cookie

    [Root @ node140/] # chmod 600/var/lib/rabbitmq/. erlang. cookie

    [Root @ node140/] # cat/var/lib/rabbitmq/. erlang. cookie

    AZVOCZYZZBVFLBPTBXU

    Start the service

    [Root @ node140 ~] # Systemctl start rabbitmq-server.service

    [Root @ node140 ~] # Rabbitmq-server-detached

    Enable Firewall

    [Root @ node140 ~] # Firewall-cmd -- permanent -- add-port = {4369/tcp, 25672/tcp}

    Success

    [Root @ node140 ~] # Firewall-cmd -- reload

    Success

  • Add to cluster

    The default value is a disk node. If it is a memory node, you need to add the -- ram parameter.

    [Root @ node140 ~] # Rabbitmqctl stop_app

    Stopping node rabbit @ node140...

    [Root @ node140 ~] # Rabbitmqctl join_cluster rabbit @ node139

    Clustering node rabbit @ node140 with rabbit @ node139...

    [Root @ node140 ~] # Rabbitmqctl start_app

    Starting node rabbit @ node140...

  • Set image policies

    [Root @ node140 ~] # Rabbitmqctl set_policy ha-all "^" '{"ha-mode": "all", "ha-sync-mode": "automatic "}'

    Setting policy "ha-all" for pattern "^" to "{\" ha-mode \ ": \" all \ ", \" ha-sync-mode \": \ "automatic \"} "with priority" 0 "...


    Enable the RabbitMQ monitoring plug-in

    After the cluster is set up, if the "Node statistics not available" information is displayed in the Nodes section of the Overview of rabbitmq_management in the web management tool, the web management plug-in is not enabled on the Node.

    [Root @ node140 ~] # Rabbitmq-plugins enable rabbitmq_management

    After the cluster is configured, you can run the following command on any node of RabbitMQ to check whether the cluster configuration is successful.

    [Root @ node140 ~] # Rabbitmqctl cluster_status

    Other nodes must perform the same operation.

    Log on to the website http: // 192.168.190.139: 15672/

    Reference URL:Http://www.rabbitmq.com/clustering.html

    Problems encountered during installation:

    In this/var/lib/rabbitmq/. erlang. cookie file, you must modify the permission of the file owner and file to rw. Otherwise, the rabbitmq service cannot be started;

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.