RabitMQ installation

Single machine installation

Install dependencies

Website: www.rabbitmq.com/install-rpm… www.rabbitmq.com/which-erlan… Github.com/rabbitmq/er…

Sudo RPM -uvh Erlang -23.3.3-1.el7.x86_64. RPM yum install socat -y sudo RPM -uvh rabbitmq-server-3.8.15-1.el7.noarch systemctl start rabbitmq-server systemctl enable rabbitmq-server systemctl status rabbitmq-server systemctl stop rabbimq-serverCopy the code
Installing a plug-in

Rabbitmq_delayed_message_exchange (rabbitmq_delayed_message_exchange); rabbitmq_prometheus (rabbitmq_delayed_message_exchange); rabbitmq_prometheus (rabbitmq_prometheus); Delay message need to download the plugin, and website address is www.rabbitmq.com/community-p… , after downloading in/usr/lib/rabbitmq/lib/rabbitmq_server – 3.8.15 / plugins.

  rabbitmq-plugins enable rabbitmq_management
  rabbitmq-plugins enable rabbitmq_prometheus
  rabbitmq-plugins enable rabbitmq_delayed_message_exchange
  ## check
  cat /etc/rabbitmq/enabled_plugins
  rabbitmq-plugins list
Copy the code
A firewall

The RabbitMQ need to open some port, generally speaking, there are 4369567, 2256, 72156, 72, the website address is www.rabbitmq.com/networking…. .

  firewall-cmd --zone=public --add-port=5672/tcp --permanent
  firewall-cmd --reload
  firewall-cmd --query-port=5672/tcp
Copy the code
Set users and permissions
  rabbitmqctl add_user admin admin
  rabbitmqctl set_user_tags admin administrator
  rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
Copy the code

none

Cannot access the Managerment Plugin

management

Users can do anything with AMQP plus

  • List the virtual hosts you can log into through AMQP
  • View queues, exchanges, and Bindings in your virtual hosts
  • Check and close your channels and connections
  • View global statistics about your own virtual hosts, including the activities of other users in those virtual hosts

policymaker

  • Anything management does
  • View, create, and delete policies and parameters of your own virtual hosts

monitoring

  • Anything management does
  • List all virtual hosts, including those they cannot log in to
  • Check connections and Channels for other users
  • View node-level data, such as clustering and memory usage
  • View real global statistics about virtual hosts

administrator

  • Anything policymaker does
  • Anything that Monitor does
  • View creating and deleting virtual hosts
  • View creating and deleting users
  • View the create and delete permissions
  • View creating and deleting connections

www.rabbitmq.com/management….

The configuration file

By default start the RabbitMQ without configuration file, if you want to configure, you can add the/etc/RabbitMQ/RabbitMQ conf file, specific parameters and information reference github.com/rabbitmq/ra… , www.rabbitmq.com/configure.h…

Cluster deployment

Multi-node cluster deployment

Install dependencies

Prepare three machines with RabbitMQ installed. For details, see Installing RabbitMQ on a Single machine

Modifying a Configuration File
Vim /etc/hosts 10.10.1.12 node1 10.10.1.13 node2 10.10.1.14 node3   #Send the file to node2 node3
   scp /etc/hosts  root@node2:/etc/
   scp /var/lib/rabitmq/.erlang.cookie root@node2:/var/lib/rabbitmq/
   ## set the hostname
   hostname node1
Copy the code
Open the corresponding port and start RabbitMQ
Systemctl start Rabbitmq-server or rabbitmq-server-detachedCopy the code

To join the cluster

   rabbitmqctl stop_app
   rabbitmqctl reset
   rabbitmqctl join_cluster rabbit@node1 --ram
   rabbitmqctl start_app
Copy the code

Viewing Cluster Status

    rabbitmqctl cluster_status
Copy the code

Common Commands

rabbitmq-server
rabbitmq-server -detached
rabtitmq-server stop
rabbitmqctl list_queues
rabbitmqctl list_vhosts
rabbitmqctl start_app
rabbitmqctl stop_app
rabbitmqctl status
rabbitmq-plugins list
rabbitmqctl add_user username password
rabbitmqctl list_users
rabbitmqctl delete user
rabbitmqctl clear_user_permissions username
rabbitmqctl clear_permissions -p vhostpath username
rabbitmqctl list_user_permissions username
rabbitmqctl change_password username password
rabbitmqctl set_permissions -p vhostpath username ".*" ".*" ".*"
rabbitmqctl add_vhost
rabbitmqctl list_hosts
rabbitmqctl list_permissions -p  vhostpath
rabbitmqctl delete_vhost vhostpath
rabbitmqctl reset
Copy the code

Single-node multi-node deployment

For the machines on which RabbitMQ has been installed, see Single-node Installation

Add a port and restart the firewall
Start the RabbitMq

Add the following contents to /etc/rabbitmq/rabbimq-env.conf

    RABBITMQ_NODE_PORT=5672
    RABBITMQ_NODENAME=rabbit1
Copy the code
  rabbimq-server -detached
  RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener[{port, 15673}]"  RABBITMQ_NODENAME=rabbit2 rabbitmq-server -detached
  RABBITMQ_NODE_PORT=5674 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener[{port, 15674}]"  RABBITMQ_NODENAME=rabbit4 rabbitmq-server -detached
Copy the code
   rabbitmqctl -n rabbit2 stop_app
   rabbitmqctl -n rabbit2 reset
   rabbitmqctl -n rabbit2 join_cluster rabbit1 --ram
   rabbitmqctl -n rabbit2 start_app
   rabbitmqctl cluster_status
   rabbitmqctl -n rabbit3 stop_app
   rabbitmqctl -n rabbit forget_cluster_node rabbit3
   rabbitmqctl set_cluster_name abc
Copy the code

In common mode, metadata is synchronized but queue content is not synchronized. Node faults occur

Metadata includes:

  • Queue metadata (queue name and attributes)
  • Switch (name and properties of the switch)
  • Binding relationship metadata (switch to queue or switch to switch)
  • Vhost metadata: Provides binding relationships between namespaces and security attributes for queues, switches, and bindings

Mirrored queue

Website: www.rabbitmq.com/ha.html#mir… Management >Admin >Policies > Add/ Update a Policy The queue content is copied and data is redundant

name: ha-all
Pattern: ^
Apply to:Queues
Priority: 0
Definition: ha-mode=all
Copy the code

Or run the command on three machines./rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:”all”}’

ha-mode ha-params
exactly count
all none
nodes node names

HAProxy

Yum install gcc-y tar -zxf haproxy-2.1.0.tar.gz CD haproxy-2.1.0 make TARGET=linux-glibc make install mkdir /etc/haproxy groupadd -r -g 149 haproxy useradd -g haproxy -r -s /sbin/nologin -u 149 haproxy touch /etc/haproxy/haproxy.cfg yum -y install haproxyCopy the code
global
  log 127.0.0.1 local0 info
  # Maximum number of concurrent connections to the server
  maxconn 5120
  # chroot /tmp
  # select user
  uid 149
  # specified group
  gid 149
  daemon
  quiet
  Haproxy can only be used in daemon mode. One haproxy process is started by default
  nbprox 1
  pidfile /var/run/haproxy.pid
  
defaults
   log global
   TCP instance running in TCP mode, layer 4 proxy
   mode tcp
   option tcplog
   option dontlognull
   retries 3
   option redispath
   maxconn 2000
   timeout connect 5s
   timeout client 60000
   timeout server 15000
   
listen rabbitmq_cluster
   bind 192.168.100.101:5672
   mode tcp
   balance roundrobin
   server rabbitmqNode1 192.168.100:102:5672 inner  5000 rise 2 fail 2
   server rabbitmqNode2 192.168.100:102:5673 inner  5000 rise 2 fail 2

# monitoring
listen stats
   bind 192.168.100.101:9000
   mode http
   option httplog
   stats enable
   stats uri /rabbitmq-stats
   stats refresh 5s
Copy the code
haproxy -f /etc/haproxy/haproxy.cfg
Copy the code