RabbitMQ安装

RabbitMQ是一个实现了AMQP(Advanced Message Queuing Protocol)高级消息队列协议的消息队列服务,用Erlang语言。

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

下载网址

安装依赖

1
2
3
4
# Centos
yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto
# Ubuntu
apt -y install libssl-dev ncurses-dev

下载地址

在安装 RabbitMQ 之前,您必须安装Erlang/OTP支持的版本。标准红帽、Fedora、CentOS 存储库提供的 Erlang 版本通常过时,不能用于运行最新的 RabbitMQ 版本。

根据官网资料可知,CentOS7支持不了Erlang 24,所以如果是CentOS7安装的版本需要小于24。

https://img.bwcxtech.com/img/202210140955396.png

1
2
wget https://github.com/erlang/otp/releases/download/OTP-24.2.1/otp_src_24.2.1.tar.gz
wget https://erlang.org/download/otp_src_24.2.tar.gz

解压编译安装

--without-javac禁用java编译器

1
2
3
4
5
6
# 解压
tar -zxf otp_src_24.2.1.tar.gz
# 配置安装路径编译代码
cd otp_src_24.2.1/
./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
export PATH=${PATH}:${ERLANG_HOME}/bin
# 使配置文件生效
source /etc/profile

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

1
2
3
4
5
6
7
8
# erl

Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1]

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

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
export PATH=${PATH}:${RABBIT_HOME}/sbin
# 使得文件生效
source /etc/profile

启动服务

1
rabbitmq-server -detached

查看服务状态

1
rabbitmqctl status

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

https://img.bwcxtech.com/img/20200928171939.png

停止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

首先信任 erlang-solutions 的 GPG 公钥:

1
rpm --import https://packages.erlang-solutions.com/rpm/erlang_solutions.asc

新建/etc/yum.repos.d/erlang-solutions.repo

1
2
3
4
5
6
7
8
cat > /etc/yum.repos.d/erlang-solutions.repo << 'EOF'
[erlang-solutions]
name=CentOS $releasever - Erlang Solutions
baseurl=https://mirrors.tuna.tsinghua.edu.cn/erlang-solutions/centos/$releasever/
gpgcheck=1
gpgkey=https://packages.erlang-solutions.com/rpm/erlang_solutions.asc
enabled=1
EOF

刷新缓存并安装 erlang 即可。

1
2
yum clean all
yum makecache

安装Erlang

1
2
yum list erlang --showduplicates | sort -r
yum install erlang-24.2.1-1.el7

下载

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

https://img.bwcxtech.com/img/202210091619783.png

rabbitmq.conf.example

1
systemctl start rabbitmq-server.service

查看状态

1
systemctl status rabbitmq-server.service

开启网页管理界面

1
2
rabbitmq-plugins enable rabbitmq_management
systemctl restart rabbitmq-server.service
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

WARNING: As of RabbitMQ 3.9, all of the docker-specific variables listed below are deprecated and no longer used. Please use a configuration file instead; visit rabbitmq.com/configure to learn more about the configuration file. For a starting point, the 3.8 images will print out the config file it generated from supplied environment variables.

/etc/profile或者/etc/security/limit.d这些文件中配置的环境变量仅对通过pam登录的用户生效,而systemd是不读这些配置的,所以这就造成登录到终端时查看环境变量和手动启动应用都一切正常,但是systemd无法正常启动应用

https://img.bwcxtech.com/img/202210141043377.png

修改rabbitmq-server,添加环境变量

1
2
ERLANG_HOME=/usr/local/erlang
export PATH=$PATH:${ERLANG_HOME}/bin

https://img.bwcxtech.com/img/202210141048111.png

源码安装erlang的时候,在执行./configure的时候, 最后会看到类似如下的的提示信息

https://img.bwcxtech.com/img/202210281453910.png

缺少ssl库

1
apt install -y libssl-dev

安装后结果

https://img.bwcxtech.com/img/202210281453799.png