19.问题:如何在Linux服务器上部署运行RabbitMq消息队列服务?

解决方案:如下所示

第1步:下载安装RabbitMQ的环境依赖

yum -y install make gcc gcc-c++ m4 kernel-devel glibc-devel ncurses-devel openssl-devel unixODBC-devel xmlto

第2步:下载Erlang源码压缩包

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
http://erlang.org/download/otp_src_22.0.tar.gz

第3步:创建Erlang的安装目录

mkdir /usr/local/erlang

第4步:解压下载好的Erlang

tar -xvf otp_src_22.0.tar.gz

第5步:将解压好的Erlang拷贝到Erlang安装目录

cp otp_src_22.0 /usr/local/erlang/otp_src_22.0 -r

第6步:进入Erlang安装目录进行编译安装Erlang

cd /usr/local/erlang/otp_src_22.0
配置安装路径编译代码
./configure --prefix=/usr/local/erlang
执行编译安装
make && make install

第7步:配置Erlang环境变量

cd /etc
cp profile profile.2019.06.04
vim profile
添加以下内容
export ERLANG_HOME=/usr/local/erlang
export PATH=/usr/local/java/jdk1.8.0_201/bin:$PATH:/usr/local/nginx/sbin:$PATH:/usr/local/erlang/bin
保存退出
source profile

第8步:验证Erlang是否验证成功

erl
如果输出以下内容,那么说明安装成功!
[root@hbs20190406 ~]# erl
Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]

Eshell V10.4  (abort with ^G)
1> 
输入halt().退出

第9步:下载RabbitMQ压缩包

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-generic-unix-3.7.15.tar.xz

第10步:创建RabbitMQ的安装目录

mkdir /usr/local/RabbitMQ

第11步:解压RabbitMQ

xz -d rabbitmq-server-generic-unix-3.7.15.tar.xz
tar -xvf rabbitmq-server-generic-unix-3.7.15.tar

第12步:将rabbitmq_server-3.7.15拷贝到RabbitMQ的安装目录

cp rabbitmq_server-3.7.15 /usr/local/RabbitMQ/rabbitmq_server-3.7.15 -r

第13步:配置RabbitMQ环境变量

cd /etc
vim profile
添加以下内容
export PATH=/usr/local/java/jdk1.8.0_201/bin:$PATH:/usr/local/nginx/sbin:$PATH:/usr/local/erlang/bin:$PATH:/usr/local/RabbitMQ/rabbitmq_server-3.7.15/sbin
保存退出
source profile

第14步:配置RabbitMQ网页插件

mkdir /etc/rabbitmq
cd /usr/local/RabbitMQ/rabbitmq_server-3.7.15/sbin
./rabbitmq-plugins enable rabbitmq_management
./rabbitmq-server -detached

[root@hbs20190406 sbin]# ./rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@hbs20190406:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@hbs20190406...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

set 3 plugins.
Offline change; changes will take effect at broker restart.

第15步:配置RabbitMQ的延时插件(下载完插件后,将其拷贝到RabbitMQ安装目录下的plugins目录下,并使用启动插件)

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
https://dl.bintray.com/rabbitmq/community-plugins/3.7.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171201-3.7.x.zip
unzip rabbitmq_delayed_message_exchange-20171201-3.7.x.zip
cp rabbitmq_delayed_message_exchange-20171201-3.7.x.ez /usr/local/RabbitMQ/rabbitmq_server-3.7.15/plugins/rabbitmq_delayed_message_exchange-20171201-3.7.x.ez -r
cd /usr/local/RabbitMQ/rabbitmq_server-3.7.15/sbin
rabbitmq-plugins enable rabbitmq_delayed_message_exchange

[root@hbs20190406 sbin]# rabbitmq-plugins enable rabbitmq_delayed_message_exchange
Enabling plugins on node rabbit@hbs20190406:
rabbitmq_delayed_message_exchange
The following plugins have been configured:
  rabbitmq_delayed_message_exchange
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@hbs20190406...
The following plugins have been enabled:
  rabbitmq_delayed_message_exchange

started 1 plugins.
[root@hbs20190406 sbin]# 

重启RabbitMQ服务
./rabbitmqctl stop
./rabbitmq-server -detached

查看RabbitMQ服务状态
./rabbitmqctl status

第16步:使用RabbitMQ

cd /usr/local/RabbitMQ/rabbitmq_server-3.7.15/sbin

启动服务:
./rabbitmq-server -detached

查看服务状态:
./rabbitmqctl status

关闭服务:
./rabbitmqctl stop

查看用户
./rabbitmqctl list_users

第17步:开放linux防火墙端口: 15672 网页管理, 5672 AMQP端口

第18步:远程访问配置【添加账户】

查看mq用户
rabbitmqctl list_users
查看用户【guest】的权限
rabbitmqctl list_user_permissions guest
新增用户并设置密码
rabbitmqctl add_user root 【这里设置你的mq用户登录密码】
赋予用户【root】管理员权限
rabbitmqctl set_user_tags root administrator
rabbitmqctl set_permissions -p "/" root ".*" ".*" ".*"

第19步:验证:在浏览器地址栏输入47.107.77.101:15672访问RabbitMQ,输入账号密码登录【默认用户guest 密码guest】

祝你好运~


6/4/2019 5:11:49 PM 已解决!