RabbitMQ安装

摘要

源码安装

RabbitMQ是由Erlang语言开发,所以需要先安装Erlang环境

新版本的RabbitMQ都需要在Github下载(有科学上网会快一点),网址https://github.com/rabbitmq/rabbitmq-server/releases

安装Erlang

安装依赖

1
yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto

下载安装,地址:http://www.erlang.org/downloads,选择版本下载。

1
wget http://erlang.org/download/otp_src_21.3.tar.gz

解压编译安装

1
2
3
4
5
6
#解压
tar -zxf otp_src_21.3.tar.gz
#配置安装路径编译代码
cd otp_src_21.3/
./configure --prefix=/usr/local/erlang --without-javac
make && make install

配置环境变量

1
2
3
4
5
6
7
vi /etc/profile
#添加下面的配置
#set erlang environment
ERLANG_HOME=/usr/local/erlang
PATH=${PATH}:${ERLANG_HOME}/bin
#使配置文件生效
source /etc/profile

测试

测试erlang是否安装成功,执行erl进行简单计算测试

1
2
3
4
5
6
7
8
# erl

Erlang/OTP 21 [erts-10.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Eshell V10.3 (abort with ^G)
1> 1+2.
3
2> halt().

安装RabbitMQ

RabbitMQ下载安装

下载

1
2
#二进制包
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/rabbitmq-server-generic-unix-3.7.14.tar.xz

解压

1
2
tar -xf rabbitmq-server-generic-unix-3.7.14.tar.xz
mv rabbitmq_server-3.7.14 /usr/local/rabbitmq

配置环境变量

1
2
3
4
5
6
7
vi /etc/profile
#添加以下配置
#set rabbitmq environment
RABBIT_HOME=/usr/local/rabbitmq
PATH=${PATH}:${RABBIT_HOME}/sbin
#使得文件生效
source /etc/profile

创建用户

1
2
3
groupadd --system rabbitmq
useradd --system -g rabbitmq -d /usr/lib/rabbitmq -s /sbin/nologin -c "rabbitmq server" rabbitmq
chown -R rabbitmq.rabbitmq /usr/local/rabbitmq

添加服务

1
vi /usr/lib/systemd/system/rabbitmq-server.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=RabbitMQ broker
After=syslog.target network.target

[Service]
Type=notify
User=rabbitmq
Group=rabbitmq
WorkingDirectory=/usr/local/rabbitmq
ExecStart=/usr/local/rabbitmq/bin/rabbitmq-server
ExecStop=/usr/local/rabbitmq/bin/rabbitmqctl stop

[Install]
WantedBy=multi-user.target

启动服务

1
2
systemctl daemon-reload
systemctl start mysql.service

启动服务

1
rabbitmq-server -detached

查看服务状态

1
rabbitmqctl status

显示如下信息,说明已经启动

停止RabbitMQ

1
rabbitmqctl stop

开启网页管理界面

1
rabbitmq-plugins enable rabbitmq_management

添加用户

1
rabbitmqctl add_user test test

设置为管理员

1
rabbitmqctl set_user_tags test administrator

给用户test在test_host分配所有权限

1
rabbitmqctl set_permissions -p test_host test ".*" ".*" ".*" 

移除用户test在分配的所有权限

1
rabbitmqctl clear_permissions -p / test

yum安装

安装Erlang

安装依赖

1
yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto

添加yum源

在网站查看需要的yum源,https://github.com/rabbitmq/erlang-rpm

1
2
3
4
5
6
7
8
9
10
11
vi /etc/yum.repos.d/rabbitmq_erlang.repo

#添加Erlang 21.x yum源(适用于centos7)

[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/21/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1

清楚yum缓存

1
2
yum clean all
yum makecache

安装Erlang

1
yum install erlang

安装RabbitMQ

下载

1
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/rabbitmq-server-3.7.14-1.el7.noarch.rpm

输入秘钥

1
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc

安装

1
yum install rabbitmq-server-3.7.14-1.el7.noarch.rpm

启动

1
systemctl start rabbitmq-server.service

查看状态

1
systemctl status rabbitmq-server.service

开启网页管理界面

1
2
rabbitmq-plugins enable rabbitmq_management
systemctl restart rabbitmq-server.service

docker启动

1
2
3
4
5
6
7
8
docker run -d \
-p 5672:5672 \
-p 15672:15672 \
-h my-rabbit \
-e RABBITMQ_DEFAULT_USER=rabbit \
-e RABBITMQ_DEFAULT_PASS=rabbit \
-v /rabbitmq:/var/lib/rabbitmq \
rabbitmq:3.8.15-management-alpine

One of the important things to note about RabbitMQ is that it stores data based on what it calls the “Node Name”, which defaults to the hostname. What this means for usage in Docker is that we should specify / explicitly for each daemon so that we don’t get a random hostname and can keep track of our data:-h --hostname