RabbitMQ super detailed installation tutorial (Linux)

1 Introduction

Official website : https://www.rabbitmq.com/

RabbitMQ is an open source AMQPprotocol implemented based on Erlang language, supports multiple clients (languages), is used to store and forward messages in distributed systems, and has the characteristics of high availability, high scalability, and ease of use.
image-20210306004740486



2. Download and install RabbitMQ

Environment preparation : Aliyun centos7.6 server

# 查看系统版本
[root@zsr ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.6.1810 (Core) 
Release:	7.6.1810
Codename:	Core

2.1. Download RabbitMQ

Download address : https://www.rabbitmq.com/download.html
image-20210505195722340
Select the corresponding system version and click download. After downloading, you will get the .rpmfile
image-20210306171625359

2.2. Download Erlang

RabbitMQ is developed in Erlang language, so the system environment must provide Erlang environment, and Erlang needs to be installed

ErlangCompare with RabbitMQversion: https://www.rabbitmq.com/which-erlang.html

image-20210306105403265

Install the latest version 3.8.14 here RabbitMQ, the corresponding Erlangversion is recommended 23.x, we downloaderlang-23.2.7-2.el7.x86_64.rpm

Download address: https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-23.2.7-2.el7.x86_64.rpm
image-20210306155749846
which el7means Red Hat 7.x, that isCentOS 7.x

Click on the upper right corner to download to get the .rpmfile
image-20210306171649898

2.3. Install Erlang

First upload the downloaded file to the server and create a folder to store the file

[root@zsr ~]# mkdir -p /usr/rabbitmq

Then use xftpthe tool to upload the two files downloaded above .rpmto the newly created folder of the server,
image-20210306171754048
then switch to the /usr/rabbitmqdirectory, decompress and installerlang

# 解压
rpm -Uvh erlang-23.2.7-2.el7.x86_64.rpm

# 安装
yum install -y erlang

image-20210306172313930
After the installation is complete, enter the following command to view the version number

erl -v

image-20210306172327030

2.4. Install RabbitMQ

During the RabiitMQinstallation process, you need to depend on socatthe plug-in, first install the plug-in

yum install -y socat

Then unzip RabbitMQthe installed installation package

# 解压
rpm -Uvh rabbitmq-server-3.8.14-1.el7.noarch.rpm

# 安装
yum install -y rabbitmq-server

2.5. Start the RabbitMQ service

# 启动rabbitmq
systemctl start rabbitmq-server

# 查看rabbitmq状态
systemctl status rabbitmq-server

If it is displayed active, it means that the service is installed and started successfully
image-20210306173012889
. Other commands:

# 设置rabbitmq服务开机自启动
systemctl enable rabbitmq-server

# 关闭rabbitmq服务
systemctl stop rabbitmq-server

# 重启rabbitmq服务
systemctl restart rabbitmq-server


3. RabbitMQ Web management interface and authorization operation

3.1. Install and start the RabbitMQ Web management interface

By default, rabbitmq does not have the client software installed on the web side, and it needs to be installed to take effect.

# 打开RabbitMQWeb管理界面插件
rabbitmq-plugins enable rabbitmq_management

image-20210306191329997
Then we open the browser, access 服务器公网ip:15672(note to open the Aliyun security group and port 15672 of the firewall), and you can see the management interface
image-20210306193911485

rabbitmqThere is a default account password guest, but this situation is limited to local localhost access, so you need to add a remote login user

3.2. Add remote users

# 添加用户
rabbitmqctl add_user 用户名 密码

# 设置用户角色,分配操作权限
rabbitmqctl set_user_tags 用户名 角色

# 为用户添加资源权限(授予访问虚拟机根节点的所有权限)
rabbitmqctl set_permissions -p / 用户名 ".*" ".*" ".*"

There are four roles :

  • administrator: You can log in to the console, view all information, and manage rabbitmq
  • monToring: Monitor; log in to the console to view all information
  • policymaker: Policy maker; log in to the console to specify the policy
  • managment: Ordinary administrator; login control

Here, create a user zsr, password 123456, set a adminstatorrole, and give all permissions
image-20210306195558911
. After the creation is complete, access 服务器公网ip:15672to log in, and then you can enter the background
image-20210306200132821
Other instructions:

# 修改密码
rabbitmqctl change_ password 用户名 新密码

# 删除用户
rabbitmqctl delete_user 用户名

# 查看用户清单
rabbitmqctl list_users


4. Docker install RabbitMQ

4.1. Install Docker

# 1.yum包更新到最新
yum update

# 2.安装需要的软件包(yum-utils提供yum-config-manager的功能,,并且device mapper存储驱动程序需要device-mapper-persistent-data和lvm2)
yum install -y yum-utils device-mapper-persistent-data lvm2

# 3.设置yum源为阿里云
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 4.安装docker
yum install docker-ce -y

# 5.安装后查看docker版本
docker -v

# 6.阿里云镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    
    
  "registry-mirrors": ["https://73z5h6yb.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Docker common commands:

# 启动docker
systemctl start docker

# 停止docker
systemctl stop docker

# 重启docker
systemctl restart docker

# 查看docker状态
systemctl status docker

# 开机启动
systemctl enable docker
systemctl unenable docker 

# 查看docker概要信息
docker info 

# 查看docker帮助文档
docker --help

4.2, install and start RabbitMQ

# 安装启动rabbitmq容器
docker run -d --name myRabbitMQ -e RABBITMQ_DEFAULT_USER=zsr -e RABBITMQ_DEFAULT_PASS=123456 -p 15672:15672 -p 5672:5672 rabbitmq:3.8.14-management

Then open the browser to access 服务器公网ip:15672, enter the account password we created to log in, successful login means that docker is installed and started successfully

image-20210307153314205

Guess you like

Origin blog.csdn.net/qq_45173404/article/details/116429302