Preface
RabbitMQ is an open source message broker software (also known as message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP), and its server is written in Erlang. It is lightweight, can be deployed in distributed and federated configurations for high-scale, high-availability requirements, and its installation process is uncomplicated. (Please make sure your virtual machine has jdk installed before installation)
Step 1: Download and upload
As mentioned earlier, rabbitmq is written in erlang language, so you need to download two compressed packages
1. Erlang recommended download link: Download all versions of erlang
2. Rabbitmq official download link: https://www.rabbitmq.com/
2020-05-07 Update :
Rabbitmq is actually updated very quickly. Now the official website has version 3.8. I haven’t used the new version yet, but 3.7 is definitely enough.
Considering that the download speed of erlang and rabbitmq will be very slow, it has been uploaded to a certain disk Just go here and download it.
Link: https://pan.baidu.com/s/14j3afDiLhMwP073wUQyx3w Extraction code: ramq
(If it shows that the resource has been canceled or expired, please manually copy the link and open it in a new window)
3. Pay attention to the version
Rabbitmq and erlang are version dependent, and the two versions cannot be too different. The official version description: rabbitmq and erlang version dependency description
After the download is complete, it can be backed up to your USB flash drive. It can be summarized and installed at any time in the future.
4. Upload to Linux
Create a rabbitmq folder under /usr/local
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mkdir rabbitmq
Upload the two compressed packages just downloaded to the rabbitmq folder
Here I use the rz command to upload files from Windows to Linux. After executing yum install -y lrzsz, the rz upload function can be supported.
Enter rz on the command line to select local files to upload
Step 2: Install Erlang
1. Environment
[root@localhost rabbitmq]# yum -y install ncurses-devel
[root@localhost rabbitmq]# yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
2. Unzip
[root@localhost rabbitmq]# tar -xvf otp_src_21.1.tar.gz
3. Installation
Enter the decompressed otp_src_21.1 directory, execute the following command to generate the erlang directory (my directory is placed in the rabbitmq folder, feel free)
[root@localhost rabbitmq]# cd otp_src_21.1
[root@localhost otp_src_21.1]# ./configure --prefix=/usr/local/rabbitmq/erlang --without-javac
Then compile and install (the process is a bit slow)
[root@localhost otp_src_21.1]# make
[root@localhost otp_src_21.1]# make install
4. Test
[root@localhost otp_src_21.1]# cd ..
[root@localhost rabbitmq]# cd erlang/
[root@localhost erlang]# ./bin/erl
If you can enter the erlang shell, it means that erlang has been installed (Ctrl + C twice to exit), as shown in the figure below (configure the environment variables later)
Step 3: Install RabbitMQ
1. Environment
[root@localhost rabbitmq]# yum install python -y
[root@localhost rabbitmq]# yum install xmlto -y
2. Decompress (get the tar format file first, then decompress)
[root@localhost rabbitmq]# xz -d rabbitmq-server-generic-unix-3.7.17.tar.xz
[root@localhost rabbitmq]# tar -xvf rabbitmq-server-generic-unix-3.7.17.tar
3. Rename (if the original name is too long, it will be changed to rabbitmq)
[root@localhost rabbitmq]# mv rabbitmq_server-3.7.17/ rabbitmq
Now the directory of rabbitmq under /usr/local/ is as follows: erlang is generated by otp, and the decompressed rabbitmq does not need to perform make operation, and can be used directly. This is the sbin
directory in rabbitmq, which contains some commands, including start and stop. Check the directory in rabbitmq by yourself
4. Configure environment variables
[root@localhost rabbitmq]# vi /etc/profile
Add the following sentence at the end of the profile file (including the environment variable configuration of erlang), pay attention to the correct path, and finally save and exit with wq
export PATH=$PATH:/usr/local/rabbitmq/erlang/bin:/usr/local/rabbitmq/rabbitmq/sbin
Make the configuration take effect immediately
[root@localhost rabbitmq]# source /etc/profile
5. start
Since the environment variables have been configured above, it is not necessary to enter the sbin command directory of rabbitmq, and the rabbitmq-server can be started directly.
Of course, you can also enter the sbin directory and use ./rabbitmq-server to start (currently it is not started in the background, you can clearly see the startup situation)
6. Close
In fact, the command to close rabbitmq is also in its sbin directory, which is the second rabbitmqctl. The command is as follows
[root@localhost sbin]# ./rabbitmqctl stop
In fact, at this point, rabbitmq has been installed and can be used normally in general projects.
Rabbitmq will create an account guest by default, and the password is also guest, but the default account authority is relatively low, you can only use localhost to connect, and you cannot connect remotely (in fact, the official website also has instructions, of course there are solutions, and a solution will be introduced below)
Step 4: RabbitMQ account settings
1. Start the plug-in function
[root@localhost sbin]# ./rabbitmq-plugins enable rabbitmq_management
At this time, rabbitmq will have a webpage port number, which is 15672 by default. After starting rabbitmq, visit the IP+port in the browser, such as: http://192.168.183.129:15672/, a login interface will appear, enter the default guest account Try it and find that you can’t log in (because the default guest user can only use localhost to connect).
If you want to log in, you can modify the configuration of the guest, but it is not recommended. You can create an account here.
2. Create an account
(1) Before creating, you can check which users and permissions are currently available
[root@localhost sbin]# ./rabbitmqctl list_users
[root@localhost sbin]# ./rabbitmqctl list_user_permissions guest
(2) Add users (my account here is set to admin, password is also admin, feel free)
[root@localhost sbin]# ./rabbitmqctl add_user admin admin
(3) Set its role (super administrator)
[root@localhost sbin]# ./rabbitmqctl set_user_tags admin administrator
(4) Set its permissions
[root@localhost sbin]# ./rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
At this time, try to log in with the newly created admin account, and find that you can log in (you can use the admin account in the project at this time).
From the above figure, we can see some basic conditions of rabbitmq, such as Connections and Channels , Exchanges, Queues, the admin tab on the far right can see all user status, and you can also create users. You can click on it yourself to get familiar with the RabbitMQ Server server.
In addition, in addition to direct operation on the above web page, it is also possible to use the command line under the virtual machine for operation and management. Execute: rabbitmqctl help, all command help will appear, and execute it in the form of rabbitmqctl xxx Here is an introduction to
RabbitMQ Some basic concepts:
keywords | illustrate |
---|---|
Broker | The entity of the message queue server is a middleware application responsible for receiving messages from producers and then sending messages to message receivers or other Brokers |
Exchange | The message switch is the first place where the message arrives, and the message is distributed to different message queues through the routing rules specified by it. |
Queue | Message queues, where messages end up after being sent and routed. Messages arriving at Queue enter the state of waiting for consumption, and each message will be sent to one or more queues |
Binding | Binding, its function is to bind Exchange and Queue according to routing rules, that is, the virtual connection between Exchange and Queue |
Routing Key | Routing keyword, Exchange delivers messages based on this keyword |
Virtual host | Virtual host, which is a virtual division of Broker, isolates consumers, producers and the AMQP-related structures they depend on, generally for safety considerations. For example, we can set multiple virtual hosts in one Broker to separate permissions for different users |
Connection | Connection, representing the physical network for communication between producers, consumers, and Brokers |
Channel | Message channel, a logical structure used to connect producers and consumers. In each connection of the client, multiple Channels can be established, and each Channel represents a session task. Through the Channel, different interactive content in the same connection can be isolated |
Producer | Message producers, programs that make and send messages |
Consumer | Message consumers, programs that receive and process messages |
The whole process of posting messages to the queue is roughly as follows:
1. The client connects to the message queue server and opens a Channel
2. The client declares an Exchange and sets related attributes
3. The client declares a Queue and sets related attributes
4. The client uses the Routing Key between the Exchange and the Queue Establish a binding relationship between them
5. The client delivers the message to Exchange
6. After the Exchange receives the message, it performs message routing according to the Key of the message and the Binding that has been set, and delivers the message to one or more Queues
So far, the installation of RabbitMQ has been completed. If you follow this step, it is guaranteed to be OK.