先部署单台 RabbitMQ
#环境 centos 7
#1、安装依赖:
yum install socat -y
#2、安装Erlang
#下载
#https://github.com/rabbitmq/erlang-rpm/releases/download/v23.0.2/erlang-23.0.2-1.el7.x86_64.rpm
#安装
rpm -ivh erlang-23.0.2-1.el7.x86_64.rpm
#rpm -ivh erlang-23.0.2-1.el8.x86_64.rpm
#3、安装RabbitMQ
#下载地址:
#https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.5/rabbitmq-server-3.8.5-1.el7.noarch.rpm
#安装
rpm -ivh rabbitmq-server-3.8.5-1.el7.noarch.rpm
#rpm -ivh rabbitmq-server-3.8.5-1.el8.noarch.rpm
#默认安装位置
/usr/lib/rabbitmq
#跳转到可执行文件位置
/usr/lib/rabbitmq/lib/rabbitmq_server-3.8.5/sbin
#开启UI插件
rabbitmq-plugins enable rabbitmq_management
#启动rabbitmq
systemctl start rabbitmq-server
#或
./rabbitmq-server
#或
rabbitmq-server
#或者后台启动
rabbitmq-server -detached
#或
./rabbitmq-server -detached
#查看帮助
rabbitmqctl help
#查看用户
rabbitmqctl list_users
#添加用户
➜ / rabbitmqctl add_user root 1234
Adding user "root" ...
#设置标签(角色)
➜ / rabbitmqctl set_user_tags root administrator
Setting tags for user "root" to [administrator] ...
#设置权限 对于虚拟主机/赋予配置、写、读权限
➜ / rabbitmqctl set_permissions --vhost / root ".*" ".*" ".*"
#rabbitmqctl set_permissions --vhost / root" "^$" ".* ".*"
Setting permissions for user "root" in vhost "/" ...
#网页版登陆rabbitmq
http://172.16.94.13:15672/
#idea访问rabbitmq
http://172.16.94.13:15672/
开始单机多部署
下载 rabbitMQ 的源码
https://github.com/rabbitmq/rabbitmq-server/releases
在下面路径下找到 rabbitmq.conf.example
/Users/dulane/Downloads/SafariDownload/rabbitmq-server-3.8.22/deps/rabbit/docs
因为是通过 rpm 安装的 rabbitmq 没有 rabbitmq.conf 文件
参考 rabbitmq.conf.example 这个文件新建 rabbitmq.conf 文件
具体操作
➜ ~ cd /opt
➜ /opt mkdir rabbitconf
➜ /opt ls
rabbitconf
➜ /opt ll
总用量 0
drwxr-xr-x. 2 root root 6 9月 6 18:02 rabbitconf
➜ /opt id rabbitmq
uid=997(rabbitmq) gid=995(rabbitmq) 组=995(rabbitmq)
#更改权限组
➜ /opt chown :rabbitmq -R rabbitconf/
➜ /opt ll
总用量 0
drwxr-xr-x. 2 root rabbitmq 6 9月 6 18:02 rabbitconf
➜ /opt cd rabbitconf
#创建配置文件rabbit.conf
➜ rabbitconf touch rabbit1.conf rabbit2.conf rabbit3.conf
➜ rabbitconf ll
总用量 0
-rw-r--r--. 1 root root 0 9月 6 18:04 rabbit1.conf
-rw-r--r--. 1 root root 0 9月 6 18:04 rabbit2.conf
-rw-r--r--. 1 root root 0 9月 6 18:04 rabbit3.conf
#更改权限组
➜ rabbitconf chown :rabbitmq rabbit*.conf
➜ rabbitconf ll
总用量 0
-rw-r--r--. 1 root rabbitmq 0 9月 6 18:04 rabbit1.conf
-rw-r--r--. 1 root rabbitmq 0 9月 6 18:04 rabbit2.conf
-rw-r--r--. 1 root rabbitmq 0 9月 6 18:04 rabbit3.conf
➜ rabbitconf
#分别修改
vim rabbit1.conf
vim rabbit2.conf
vim rabbit3.conf
#添加如下内容 一个是management ui插件的访问端口默认15672 第二个guest 访问默认不允许远程访问
management.tcp.port = 6001
loopback_users.guest = false
management.tcp.port = 6002
loopback_users.guest = false
management.tcp.port = 6003
loopback_users.guest = false
#分别启动三个rabbitmq
#也可以这种方式 export RABBITMQ_NODE_PORT=5001 export RABBITMQ_NODENAME=rabbit1 rabbitmq-server
RABBITMQ_NODENAME=rabbit1 RABBITMQ_NODE_PORT=5001 RABBITMQ_CONFIG_FILE=/opt/rabbitconf/rabbit1.conf rabbitmq-server
RABBITMQ_NODENAME=rabbit2 RABBITMQ_NODE_PORT=5002 RABBITMQ_CONFIG_FILE=/opt/rabbitconf/rabbit2.conf rabbitmq-server
RABBITMQ_NODENAME=rabbit3 RABBITMQ_NODE_PORT=5003 RABBITMQ_CONFIG_FILE=/opt/rabbitconf/rabbit3.conf rabbitmq-server
#分别访问 用户名密码guest
http://172.16.94.13:6001/
http://172.16.94.13:6002/
http://172.16.94.13:6003/
#查看生成的文件
➜ ~ cd /var/lib/rabbitmq
➜ rabbitmq ls
erl_crash.dump mnesia
➜ rabbitmq cd mnesia
➜ mnesia ls
rabbit1@rabbitmq rabbit2@rabbitmq.pid rabbit@mha
rabbit1@rabbitmq-feature_flags rabbit2@rabbitmq-plugins-expand rabbit@mha-feature_flags
rabbit1@rabbitmq.pid rabbit3@rabbitmq rabbit@mha-plugins-expand
rabbit1@rabbitmq-plugins-expand rabbit3@rabbitmq-feature_flags rabbit@rabbitmq
rabbit2@rabbitmq rabbit3@rabbitmq.pid rabbit@rabbitmq-feature_flags
rabbit2@rabbitmq-feature_flags rabbit3@rabbitmq-plugins-expand rabbit@rabbitmq-plugins-expand
➜ mnesia cd /var/log/rabbitmq/
➜ rabbitmq ls
log rabbit3@rabbitmq_upgrade.log rabbit@rabbitmq.log-20210826.gz
rabbit1@rabbitmq.log rabbit@mha.log rabbit@rabbitmq.log-20210902.gz
rabbit1@rabbitmq_upgrade.log rabbit@mha.log-20210826.gz rabbit@rabbitmq.log-20210905.gz
rabbit2@rabbitmq.log rabbit@mha_upgrade.log rabbit@rabbitmq_upgrade.log
rabbit2@rabbitmq_upgrade.log rabbit@mha_upgrade.log-20210826.gz rabbit@rabbitmq_upgrade.log-20210826.gz
rabbit3@rabbitmq.log rabbit@rabbitmq.log rabbit@rabbitmq_upgrade.log-20210902.gz
#优雅的关闭
➜ rabbitmq rabbitmqctl -n rabbit1 stop
Stopping and halting node rabbit1@rabbitmq ...
➜ rabbitmq rabbitmqctl -n rabbit2 stop
Stopping and halting node rabbit2@rabbitmq ...
➜ rabbitmq rabbitmqctl -n rabbit3 stop
Stopping and halting node rabbit3@rabbitmq ...
➜ rabbitmq
访问客户端
#分别访问 用户名密码 guest
http://172.16.94.13:6001/
http://172.16.94.13:6002/
http://172.16.94.13:6003/
在客户端分别创建 Queue 发现并不互通而是相互独立的