1 Environment Preparation

1.1 Machine Requirements

Operating system: Centos7

node IP Working mode The operating system
rabbitmq1 192.168.8.171 DISK CentOS 7.0-64 bits
rabbitmq2 192.168.8.172 DISK CentOS 7.0-64 bits (clone Rabbitmq1)
rabbitmq3 192.168.8.173 DISK CentOS 7.0-64 bits (clone Rabbitmq1)

1.2 the hostname

[root@base ~]# hostnamectl set-hostname rabbitmq1 --static
[root@base ~]# echo "192.168.8.171rabbitmq1" >> /etc/hosts
[root@base ~]# echo "192.168.8.172 rabbitmq2" >> /etc/hosts
[root@base ~]# echo "192.168.8.173 rabbitmq3" >> /etc/hosts
Copy the code

1.3 Network Settings

[root@base1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO="static" # DHCP static instead
ONBOOT="yes" # Enable this configuration on startupIPADDR = 192.168.8.171Static IP 172; 173GATEWAY = 192.168.8.2# default gatewayNETMASK = 255.255.255.0# Subnet maskDNS1 = 114.114.114.114# the DNS configurationDNS2 = 8.8.8.8# the DNS configuration

[root@base1 ~]# reboot
Copy the code

Stand-alone version 2

2.1 Updating Software Packages and Repositories

[root@rabbitmq1 ~]# yum -y install wget make gcc gcc-c++ kernel-devel openssl-devel ncurses-deve && yum -y update
Copy the code

2.2 Installing Erlang (Erlang is required to run RabbitMQ) :

[root@rabbitmq1 ~]# vi /etc/yum.repos.d/rabbitmq-erlang.repo
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/23/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
[root@rabbitmq1 ~]# yum -y install erlang socat
Copy the code

2.3 Installing the RabbitMQ Server

[root@rabbitmq1 ~]# mkdir -p ~/download && cd ~/download
[root@rabbitmq1 download]Wget # https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.11/rabbitmq-server-3.8.11-1.el7.noarch.rpm
[root@rabbitmq1 download]# RPM -- the import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
[root@rabbitmq1 download]# yum -y install rabbitmq-server-3.8.11-1.el7.noarch. RPM

Copy the code

Note — Uninstall RabbitMQ as follows:

$RPM -e rabbitmq-server-3.8.11-1.el7.noarch && rm -rf /var/lib/rabbitmq/Copy the code

2.4 Once installed, you can start the RabbitMQ Server

[root@rabbitmq1 ~]#systemctl enable rabbitmq-server && systemctl start rabbitmq-server
Job for rabbitmq-server.service failed because the control process exited with error code. See "systemctl status rabbitmq-server.service" and "journalctl -xe" for details.
Copy the code

2.5 By default, the server is not started as a daemon

[root@rabbitmq1 ~]# chkconfig rabbitmq-server on
Note: Forwarding request to 'systemctl enable rabbitmq-server.service'.
Copy the code

2.5 Checking the RabbitMQ service Status

[root@rabbitmq1 ~]# systemctl status rabbitmq-serverWhen the rabbitmq - server. The service - the rabbitmq broker the Loaded: the Loaded (/ usr/lib/systemd/system/rabbitmq - server. The service; disabled; vendor preset: disabled) Active: active (running) since Fri 2021-02-12 07:08:17 JST; 49s ago Main PID: 6511 (beam.smp) Status:"Initialized"CGroup: /system.slice/rabbitmq-server.service ├─6511 /usr/lib64/erlang/erts-11.1.7/bin/beam.smp -w W -mbas ageffcbf-mhas ageffc... 6526 32768 ├ erl_child_setup ├ ─ ─ 6551 / usr/lib64 / Erlang/erts - 11.1.7 / bin/epmd - daemon ├ ─ 6574 inet_gethost 4 └ ─ 6575 inet_gethost 4 Feb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]:##########  Licensed under the MPL 2.0. We...omFeb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]: Doc guides: https://rabbitmq.com/documenta... ml Feb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]: Support: https://rabbitmq.com/contact.html Feb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]: Tutorials: https://rabbitmq.com/getstarte... ml Feb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]: Monitoring: https://rabbitmq.com/monitorin... ml Feb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]: Logs: /var/log/rabbitmq/[email protected]
Feb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]: /var/log/rabbitmq/rabbit@rabbitmq1_upgrade.log
Feb 12 07:08:15 rabbitmq1 rabbitmq-server[6511]: Config file(s): (none)
Feb 12 07:08:17 rabbitmq1 rabbitmq-server[6511]: Starting broker... completed with 0 plugins.
Feb 12 07:08:17 rabbitmq1 systemd[1]: Started RabbitMQ broker.
Hint: Some lines were ellipsized, use -l to show in full.
Copy the code

2.6 Starting the RabbitMQ Web Management Console

[root@rabbitmq1 ~]# rabbitmq-plugins enable rabbitmq_managementEnabling plugins on node rabbit@rabbitmq1: rabbitmq_management The following plugins have been configured: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch Applying plugin configuration to rabbit@rabbitmq1...  The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins.Copy the code

2.7 Creating Management Users

RabbitMQ Server The default guest user can be accessed only by using the localhost address

[root@rabbitmq1 ~]# rabbitmqctl add_user admin admin123 &&
> rabbitmqctl set_user_tags admin administrator &&
> rabbitmqctl set_permissions -p / admin ". *" ". *" ". *"
Adding user "admin". Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
Setting tags for user "admin" to [administrator] ...
Setting permissions for user "admin" in vhost "/" ...
Copy the code

2.8 Adding a Firewall Port

[root@rabbitmq1 ~]# firewall-cmd --zone=public --permanent --add-port=4369/tcp && 
firewall-cmd --zone=public --permanent --add-port=25672/tcp && 
firewall-cmd --zone=public --permanent --add-port=5671-5672/tcp && 
firewall-cmd --zone=public --permanent --add-port=15672/tcp && 
firewall-cmd --zone=public --permanent --add-port=61613-61614/tcp && 
firewall-cmd --zone=public --permanent --add-port=1883/tcp && 
firewall-cmd --zone=public --permanent --add-port=8883/tcp
Copy the code

2.9 Restarting the Firewall

[root@rabbitmq1 ~]# firewall-cmd --reload
success
Copy the code

2.10 Browser Access

3 Set up a RabbitMQ Server HA cluster

Clone Rabbitmq2 and Rabbitmq3 from Rabbitmq1, repeat 1.2,1.3

3.1 check the.erlang.cookiefile

[root@rabbitmq1 ~]# find / -name ".erlang.cookie"
/var/lib/rabbitmq/.erlang.cookie
[root@rabbitmq1 ~]# cat /var/lib/rabbitmq/.erlang.cookie
VFHQROHPWGMZFFUQPTWO
Copy the code

Note: the cloned.erlang.cookie must be the same

3.2 Starting the RabbitMQ Server in Background Mode

  • Rabbitmq1 node
[root@rabbitmq1 ~]# rabbitmqctl stop
[root@rabbitmq1 ~]# rabbitmq-server -detached
Copy the code
  • Rabbitmq2 node
[root@rabbitmq2 ~]# rabbitmqctl stop
[root@rabbitmq2 ~]# rabbitmq-server -detached
Copy the code
  • Rabbitmq3 node
[root@rabbitmq3 ~]# rabbitmqctl stop
[root@rabbitmq3 ~]# rabbitmq-server -detached
Copy the code

3.3 Then center the cluster with Rabbitmq1

The default is disk node, if memory node, need to add –ram parameter

  • Rabbitmq1 node
[root@rabbitmq1 ~]# rabbitmqctl stop_app
[root@rabbitmq1 ~]# rabbitmqctl reset
[root@rabbitmq1 ~]# rabbitmqctl start_app
Copy the code
  • Rabbitmq2 node
[root@rabbitmq2 ~]# rabbitmqctl stop_app
[root@rabbitmq2 ~]# rabbitmqctl reset
[root@rabbitmq2 ~]# rabbitmqctl join_cluster rabbit@rabbitmq1
[root@rabbitmq2 ~]# rabbitmqctl start_app
Copy the code
  • Rabbitmq3 node
[root@rabbitmq3 ~]# rabbitmqctl stop_app
[root@rabbitmq3 ~]# rabbitmqctl reset
[root@rabbitmq3 ~]# rabbitmqctl join_cluster rabbit@rabbitmq1
[root@rabbitmq3 ~]# rabbitmqctl start_app
Copy the code

3.4 Checking cluster Status

[root@rabbitmq1 ~]# rabbitmqctl cluster_statusCluster status of node rabbit@rabbitmq1 ... Basics Cluster name: rabbit@rabbitmq1 Disk Nodes rabbit@rabbitmq1 rabbit@rabbitmq2 rabbit@rabbitmq3 Running Nodes rabbit@rabbitmq1 rabbit@rabbitmq2 rabbit@rabbitmq3 Versions rabbit@rabbitmq1: RabbitMQ 3.8.11 on Erlang 23.2.4 rabbit@rabbitmq2: RabbitMQ 3.8.11 on Erlang 23.2.4 rabbit@rabbitmq3: RabbitMQ 3.8.11 on Erlang 23.2.4 Maintenance status Node: rabbit@rabbitmq1, status: not under maintenance Node: rabbit@rabbitmq2, status: not under maintenance Node: rabbit@rabbitmq3, status: not under maintenance Alarms (none) Network Partitions (none) Listeners Node: rabbit@rabbitmq1, interface: [::], port: 15672, protocol: http, purpose: HTTP API Node: rabbit@rabbitmq1, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication Node: rabbit@rabbitmq1, interface: [::], port: 5672, protocol: amqp, purpose: AMqp 0-9-1 and AMQP 1.0 Node: rabbit@rabbitmq2, interface: [::], port: 15672, protocol: http, purpose: HTTP API Node: rabbit@rabbitmq2, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication Node: rabbit@rabbitmq2, interface: [::], port: 5672, protocol: amqp, purpose: AMqp 0-9-1 and AMQP 1.0 Node: rabbit@rabbitmq3, interface: [::], port: 15672, protocol: http, purpose: HTTP API Node: rabbit@rabbitmq3, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication Node: rabbit@rabbitmq3, interface: [::], port: 5672, protocol: AMqp, purpose: AMqp 0-9-1 and AMQP 1.0 Feature flags Flag drop_unroutable_metric, state: enabled Flag: empty_basic_get_metric, state: enabled Flag: implicit_default_bindings, state: enabled Flag: maintenance_mode_status, state: enabled Flag: quorum_queue, state: enabled Flag: user_limits, state: enabled Flag: virtual_host_metadata, state: enabledCopy the code

3.5 Creating Management Users

[root@rabbitmq1 ~]# rabbitmqctl add_user admin admin123 &&
> rabbitmqctl set_user_tags admin administrator &&
> rabbitmqctl set_permissions -p / admin ". *" ". *" ". *"
Adding user "admin". Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.
Setting tags for user "admin" to [administrator] ...
Setting permissions for user "admin" in vhost "/" ...

Copy the code

3.6 Browser Access

4 Set up HAProxy load balancer

4.1 Installing HAProxy on Rabbitmq1

[root@rabbitmq1 ~]# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@rabbitmq1 ~]# yum -y install haproxy
Copy the code

4.2 configuration HAProxy

[root@rabbitmq1 ~]# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
[root@rabbitmq1 ~]# vi /etc/haproxy/haproxy.cfg
global
    log     127.0.0.1  local0 info
    log     127.0.0.1  local1 notice
    daemon
    maxconn 4096

defaults
    log     global
    mode    tcp
    option  tcplog
    option  dontlognull
    retries 3
    option  abortonclose
    maxconn 4096
    timeout connect  5000ms
    timeout client  3000ms
    timeout server  3000ms
    balance roundrobin

listen private_monitoring
    bind    0.0.0.0:8100
    mode    http
    option  httplog
    stats   refresh  5s
    stats   uri  /stats
    stats   realm   Haproxy
    stats   auth  admin:admin123

listen rabbitmq_admin
    bind    0.0.0.0:8102
    server  rabbitmq1 rabbitmq1:15672
    server  rabbitmq2 rabbitmq2:15672
    server  rabbitmq3 rabbitmq3:15672

listen rabbitmq_cluster
    bind    0.0.0.0:8101
    mode    tcp
    option  tcplog
    balance roundrobin
    timeout client  3h
    timeout server  3h
    server  rabbitmq1  rabbitmq1:5672  check  inter  5000  rise  2  fall  3
    server  rabbitmq2  rabbitmq2:5672  check  inter  5000  rise  2  fall  3
    server  rabbitmq3  rabbitmq3:5672  check  inter  5000  rise  2  fall  3
Copy the code

4.3 start HAProxy

[root@rabbitmq1 ~]# haproxy -f /etc/haproxy/haproxy.cfg
Copy the code

4.4 Firewall Settings

firewall-cmd --zone=public --permanent --add-port=8100/tcp && firewall-cmd --zone=public --permanent --add-port=8101/tcp  && firewall-cmd --zone=public --permanent --add-port=8102/tcpCopy the code

4.5 Restarting the Firewall

[root@rabbitmq1 ~]# firewall-cmd --reload
success
Copy the code

4.6 Browser Viewing HAProxy Load Balancing Information

http://192.168.8.171:8100/stats: HAProxy load balance information address, account password: admin/admin123

http://192.168.8.171:8102/#/ : the RabbitMQ Server Web management interface (based on load balancing).

http://192.168.8.171:8101: the RabbitMQ Server service address (based on load balancing) reference: www.cnblogs.com/xishuai/p/c…