RabbitMQ安装
RabbitMQ是一个实现了AMQP(Advanced Message Queuing Protocol)高级消息队列协议的消息队列服务,用Erlang语言。
1 源码安装
RabbitMQ是由Erlang语言开发,所以需要先安装Erlang环境
1.1 安装 Erlang
安装依赖
# 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。
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编译器
# 解压
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
配置环境变量
vi /etc/profile
# 添加下面的配置
# set erlang environment
ERLANG_HOME=/usr/local/erlang
export PATH=${PATH}:${ERLANG_HOME}/bin
# 使配置文件生效
source /etc/profile
1.1.1 测试
测试erlang是否安装成功,执行erl进行简单计算测试
# 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().
1.2 安装 RabbitMQ
RabbitMQ下载安装
下载
# 二进制包
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/rabbitmq-server-generic-unix-3.7.14.tar.xz
解压
tar -xf rabbitmq-server-generic-unix-3.7.14.tar.xz
mv rabbitmq_server-3.7.14 /usr/local/rabbitmq
配置环境变量
vi /etc/profile
# 添加以下配置
# set rabbitmq environment
RABBIT_HOME=/usr/local/rabbitmq
export PATH=${PATH}:${RABBIT_HOME}/sbin
# 使得文件生效
source /etc/profile
1.3 启动 RabbitMQ 服务
rabbitmq-server -detached
查看服务状态
rabbitmqctl status
显示如下信息,说明已经启动
停止RabbitMQ
rabbitmqctl stop
1.4 插件管理
开启网页管理界面
rabbitmq-plugins enable rabbitmq_management
1.5 权限管理
添加用户
rabbitmqctl add_user test test
设置为管理员
rabbitmqctl set_user_tags test administrator
给用户test在test_host分配所有权限
rabbitmqctl set_permissions -p test_host test ".*" ".*" ".*"
移除用户test在分配的所有权限
rabbitmqctl clear_permissions -p / test
2 yum 安装
2.1 安装 Erlang
首先信任 erlang-solutions 的 GPG 公钥:
rpm --import https://packages.erlang-solutions.com/rpm/erlang_solutions.asc
新建/etc/yum.repos.d/erlang-solutions.repo
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 即可。
yum clean all
yum makecache
安装Erlang
yum list erlang --showduplicates | sort -r
yum install erlang-24.2.1-1.el7
2.2 安装 RabbitMQ
下载
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.14/rabbitmq-server-3.7.14-1.el7.noarch.rpm
输入秘钥
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
安装
yum install rabbitmq-server-3.7.14-1.el7.noarch.rpm
2.2.1 配置
2.2.2 启动
systemctl start rabbitmq-server.service
查看状态
systemctl status rabbitmq-server.service
开启网页管理界面
rabbitmq-plugins enable rabbitmq_management
systemctl restart rabbitmq-server.service
3 docker 启动
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.
4 报错
4.1 exec: erl: not found
/etc/profile
或者/etc/security/limit.d
这些文件中配置的环境变量仅对通过pam登录的用户生效,而systemd是不读这些配置的,所以这就造成登录到终端时查看环境变量和手动启动应用都一切正常,但是systemd无法正常启动应用
修改rabbitmq-server
,添加环境变量
ERLANG_HOME=/usr/local/erlang
PATH=$PATH:$ERLANG_HOME/bin
4.2 {“no such file or directory“,“crypto.app“}
源码安装erlang的时候,在执行./configure
的时候, 最后会看到类似如下的的提示信息
缺少 ssl 库
apt install -y libssl-dev
安装后结果