1. Install Erlang

Pay attention to

The RabbitMQ and Erlang version, please pay attention to the compatibility, specific posted, I will not see https://www.cnblogs.com/gne-hwz/p/10714013.html for detailsCopy the code

Normal download address

http://www.erlang.org/downloads
Copy the code

But the top one was super slow to download, so I googled it and used the bottom one

https://www.erlang-solutions.com/resources/download.html
Copy the code

Optional operating system

I am a virtual machine installed CentOS7, you can install according to their own machine situation:Copy the code

Select version, I plan to install RabbitMQ 3.6.15, so select 20.3:Copy the code

download

Wget HTTP: / / https://packages.erlang-solutions.com/erlang/rpm/centos/7/x86_64/esl-erlang_20.3-1~centos~7_amd64.rpmCopy the code

The installation

RPM -ivh esl-erlang_20.3-1 to centos to 7_amd64. RPM --nodeps --forceCopy the code

Enter erl to check whether the installation is successful

2. Install simpleJson

Download address

https://pypi.org/project/simplejson/#files
Copy the code

download

wget https://files.pythonhosted.org/packages/49/45/a16db4f0fa383aaf0676fb7e3c660304fe390415c243f41a77c7f917d59b/simplejson-3. 17.2. The tar. GzCopy the code

The installation

Install RabbitMQ

Download address

https://www.rabbitmq.com/releases/rabbitmq-server/
Copy the code

download

Wget HTTP: / / https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.15/rabbitmq-server-generic-unix-3.6.15.tar.xzCopy the code

The installation

The tar XVF - the rabbitmq server - generic - Unix - 3.6.15. Tar. XzCopy the code

configuration

Vim/etc/profile then add the export PATH = $PATH: / opt/rabbitmq/rabbitmq_server - 3.6.15 / sbin according to your own installation PATHCopy the code

Put the change into effect

source /etc/profile
Copy the code

Modify hosts. Make sure that the red circles are consistent

vim/etc/hosts
Copy the code

Start the

Run the following command to switch to the directory: CD /opt/rabbitmq/rabbitmq_server-3.6.15/sbin/./ rabbitmq-server-detached Start the system as user rootCopy the code

Check whether the startup is successful

./rabbitmqctl status
Copy the code

If you want remote access, it works

/rabbitmq-plugins enable rabbitmq_management enable rabbitmq_managementCopy the code

CentOS7 Command used to disable the firewall

Systemctl stop firewalld.service systemctl status firewalld.service systemctl disable Firewalld. service Is permanently disabledCopy the code

access

Some basic operations on RabbitMQ

$sudo chkconfig rabbitmq-server on $sudo /sbin/service rabbitmq-server start $sudo Run the following command to set the status of rabbitmq-server-detached: /sbin/service rabbitmq-server-detached $sudo /sbin/service rabbitmq-server status $sudo rabbitmqctl list_users $sudo rabbitmqctl list_users $sudo rabbitmqctl List_user_permissions guest # Since RabbitMQ default username and password are guest. To be on the safe side, $sudo rabbitmqctl add_user username password $sudo rabbitmqctl add_user username password $sudo Rabbitmqctl set_user_tags username administrator $sudo rabbitmqctl set_permissions -p/username $sudo rabbitmqctl list_user_permissions username ".*" ".*Copy the code

So far the standalone RabbitMQ has been installed, if only for a standalone installation, this is it, cluster setup

4. Cluster construction

First find.erlang.cookie

Cookie is a necessary file for Erlang to implement distribution. Every node of Erlang distribution must keep the same. Erlang. Cookie file, and ensure that the file permissions are 400. Cookie: $home/.erlang. Cookie: $home/.erlang. Cookie: $home/.erlang. The second place is/var/lib/rabbitmq /. Erlang. Cookies. If we install deployed RabbitMQ using unzipped files, the file will be in the ${home} directory, $home/.erlang.cookie. This file will be stored in /var/lib/rabbitmq if you install it using RPM or other packages. We can check the rabbitMQ startup logs to see where the home directory is and where.erlang. cookies are stored, as well as the Mnesia database information.Copy the code

Find the RabbitMQ startup log, mine in

Then look at the home directory

The.erlang.cookie is copied under /root and overwrites the.erlang.cookie of the other two nodes (localhost1 as the primary node).Copy the code

Modify the hosts files on the three hosts

start

1. Start three nodes:./ rabbitmq-server-detached 2. Then run rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster rabbit@localhost1 on localhost2 and localhost3 rabbitmqctl start_app 3. You can run the./rabbitmqctl cluster_status command to check the cluster statusCopy the code

You can also access the address directly to viewCopy the code

Detached Start rabbitmq-server-detached if the node hangs later./ rabbitmq-server-detached start the elementCopy the code

Setting a Mirroring Policy

Common mode: The default cluster mode. Mirrored mode: The required queue is mirrored on multiple nodes, which is the HA scheme for RabbitMQ. This mode can be used only when the active node is down.Copy the code
Parameters for details

Rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}' clear: rabbitmqctl clear_policy [-p <vhost>] <name>  rabbitmqctl list_policies [-p <vhost>]Copy the code

This will work even if the primary node failsCopy the code

5, conclusion

Due to didn’t before the RabbitMQ, for not a short period of time, I finally figure out, is not very detailed, but the individual feels will be enough, if have change I will slowly change, online to find a lot of tutorials, not listed one by one, in this thank you write tutorial predecessors, also welcome to see the bosses of this article points out the deficiency of the younger brother, thank you!