RabbitMQ安装

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

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

下载网址

安装依赖

bash

# 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。

img

bash

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编译器

bash

# 解压
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

配置环境变量

bash

vi /etc/profile
# 添加下面的配置
# set erlang environment
ERLANG_HOME=/usr/local/erlang
export PATH=${PATH}:${ERLANG_HOME}/bin
# 使配置文件生效
source /etc/profile

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

bash

# 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下载安装

下载

bash

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

解压

bash

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

配置环境变量

bash

vi /etc/profile
# 添加以下配置
# set rabbitmq environment
RABBIT_HOME=/usr/local/rabbitmq
export PATH=${PATH}:${RABBIT_HOME}/sbin
# 使得文件生效
source /etc/profile

bash

rabbitmq-server -detached

查看服务状态

bash

rabbitmqctl status

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

停止RabbitMQ

bash

rabbitmqctl stop

开启网页管理界面

bash

rabbitmq-plugins enable rabbitmq_management

添加用户

bash

rabbitmqctl add_user test test

设置为管理员

bash

rabbitmqctl set_user_tags test administrator

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

bash

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

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

bash

rabbitmqctl clear_permissions -p / test

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

bash

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

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

bash

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 即可。

bash

yum clean all
yum makecache

安装Erlang

bash

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

下载

bash

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

输入秘钥

bash

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

安装

bash

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

image-20221009161831194

rabbitmq.conf.example

bash

systemctl start rabbitmq-server.service

查看状态

bash

systemctl status rabbitmq-server.service

开启网页管理界面

bash

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

bash

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无法正常启动应用

image-20221014104308082

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

text

ERLANG_HOME=/usr/local/erlang
PATH=$PATH:$ERLANG_HOME/bin

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

image-20221028145302522

缺少 ssl 库

bash

apt install -y libssl-dev

安装后结果

image-20221028145336942

相关内容