RabbitMQ installation and use
1, the installation dependent on the environment
Review the installation rabbitmq need to install erlang corresponds http://www.rabbitmq.com/which-erlang.html page version
Find the need to download the https://github.com/rabbitmq/erlang-rpm/releases page erlang version, `erlang -. * Centos.x86_64.rpm` is centos version.
After you copy the download address, use the wget command to download, wget -P / home / download https://github.com/rabbitmq/erlang-rpm/releases/download/v21.2.3/erlang-21.2.3-1.el7.centos .x86_64.rpm
Install Erlang sudo rpm -Uvh /home/download/erlang-21.2.3-1.el7.centos.x86_64.rpm
If the installation prompts 'libcrypto.so.10 (OPENSSL_1.0.2) (64bit) is needed' need to download openssl-libs-1.0.2k-16.el7.x86_64.rpm, address http://rpmfind.net/linux /centos/7.6.1810/os/x86_64/Packages/openssl-libs-1.0.2k-16.el7.x86_64.rpm, then look to upgrade rpm -ivh openssl-libs-1.0.2k-16.el7.x86_64.rpm --force
安装 socat sudo yum install -y socat
2, install RabbitMQ
In the official download page http://www.rabbitmq.com/download.html) found CentOS7 version of the download link to download the installation package rpm
wget -P /home/download https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.9/rabbitmq-server-3.7.9-1.el7.noarch.rpm
Historical version can be downloaded at https://github.com/rabbitmq/rabbitmq-server/tags
Adding Environment Configuration vi / etc / RabbitMQ / RabbitMQ - env . Conf, create the corresponding directory when no directory, add NODENAME = rabbit @ localhost
Installation sudo rpm -Uvh /home/download/rabbitmq-server-3.7.9-1.el7.noarch.rpm
3, the basic operation
Start Service sudo systemctl start rabbitmq-server
View the status sudo systemctl status rabbitmq-server
Stop service sudo systemctl stop rabbitmq-server
Set boot sudo systemctl enable rabbitmq-server
Open Web management plug rabbitmq-plugins enable rabbitmq_management, rabbitmq have a default guest user, but can only be accessed via localhost, so you need to add a user to remotely access
Add User rabbitmqctl add_user admin admin
Assign authority to operate rabbitmqctl set_user_tags admin administrator for the user
Assign resource permissions rabbitmqctl set_permissions -p / admin for the user. "*". "*". "*"
4, add firewall ports
sudo firewall-cmd --zone=public --add-port=4369/tcp --permanent
sudo firewall-cmd --zone=public --add-port=5672/tcp --permanent
sudo firewall-cmd --zone=public --add-port=25672/tcp --permanent
sudo firewall-cmd --zone=public --add-port=15672/tcp --permanent
Restart the firewall sudo firewall-cmd --reload
Multi-machine multi-node cluster deployments
1, ready RabbitMQ installed three machines, ip were 192.168.5.125,192.168.5.135,192.168.5.145
2, modify the hosts file, sudo vim / etc / hosts, three machines are added respectively as follows, by sudo scp / etc / hosts [email protected]: / etc / copy to node2
192.168.5.125 node1
192.168.5.135 node2
192.168.5.145 node3
3, the corresponding modification of the host name hostname hostnamectl set-hostname (still valid after the restart)
4, the files on the copy /var/lib/rabbitmq/.erlang.cookie 192.168.5.125 to the other two machines
5, each machine to add firewall ports
6, each machine start RabbitMQ, sudo systemctl start rabbitmq-server or rabbitmq-server -detached
7, 192.168.5.135 to the cluster, stop RabbitMQ application rabbitmqctl stop_app, reset RabbitMQ set rabbitmqctl reset to the cluster rabbitmqctl join_cluster rabbit @ node1 --ram
Start RabbitMQ application rabbitmqctl start_app
8, view the cluster status, see `running_nodes, [rabbit @ node1, rabbit @ node2]` node that represents a successful start rabbitmqctl cluster_status
9, see the end in the management interface interface
Mirror mode cluster queue
Mirror queue belongs RabbitMQ high availability solutions, see: https: //www.rabbitmq.com/ha.html#mirroring-arguments
By the previous step to build clusters belonging to the ordinary mode of the cluster, the cluster is achieved by sharing metadata
Mirror mode is turned on queue management strategies need to add a page, add way:
1. Go to the administration page select the default virtual host "/" -> Admin -> Policies (on the right page) -> Add / update a policy
2. Fill in the form:
name: ha-all policy name, if using an existing name, save will modify the original information
Apply to: Queues on what policy to target
Pattern: ^ when the policy is applied to an object, the object name matching rules (regular expressions)
Priority: 0 priority, the larger the value, the higher the priority, the same priority level takes a last
Definition: receiving the policy class definition, the configuration for mirroring the queue, it only contains three parts: `ha-mode`,` ha-params` and `ha-sync-mode`. Wherein, `ha-sync-mode` synchronous manner, automatically or manually, automatically default. `Ha-mode` and` ha-params` combination. Composition as follows:
| All | (empty) | queue mirrored to all nodes in the cluster category |
| Exactly | count | queue within a specified number of mirror to the cluster nodes. If the cluster nodes within less than this value, the queue will be mirrored to all nodes. If greater than this value, and a node that contains the mirror stopped, the new image is not created in other nodes. |
| Nodes | nodename | queue mirrored to a specified node, the node is not specified in the cluster without error. When the queue stated, if the specified node is not online, the queue will be created on the client node is connected. |
Mirror queue mode compared normal mode, mirror mode consumes more bandwidth to be synchronized, the queue is less than a certain mirror the normal mode, the normal mode but not highly available, a node linked to the rear, this node the message will not be consumed, in order to be post-consumer nodes need to wait to start.
In addition to the mirror mode queue, also by means of plug-shovel, federation to achieve high availability, but not commonly used, is the difference between the following two ways