版本
- rabbitmq-server-3.7.6-1.el7
- centOS 7
单机集群搭建
- 为每个RabbitMQ服务节点设置不同的端口号和节点名称来启动相应服务
1 | [root@localhost rabbitmq]# RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit1 rabbitmq-server -detached |
or
若开启了rabbitmq管理服务,执行下面的命令1
2
3
4
5
6[root@172 rabbitmq]# RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit1 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15672}]" rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
[root@172 rabbitmq]# RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=rabbit2 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
[root@172 rabbitmq]# RABBITMQ_NODE_PORT=5674 RABBITMQ_NODENAME=rabbit3 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15674}]" rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
- 启动各节点的服务后,将rabbit2@localhost节点加入rabbit1@localhost
1 | [root@localhost rabbitmq]# rabbitmqctl -n rabbit2@localhost stop_app |
- rabbit3@localhost也加入集群
1 | [root@localhost rabbitmq]# rabbitmqctl -n rabbit3@localhost stop_app |
- rabbitmqctl cluster_status查看各服务节点的集群状态
1 | [root@localhost rabbitmq]# rabbitmqctl -n rabbit1@localhost cluster_status |
- 设置镜像
1
2
3
4
5
6[root@172 rabbitmq]# rabbitmqctl -n rabbit1@localhost set_policy ha-all "^" '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "^" to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...
[root@172 rabbitmq]# rabbitmqctl -n rabbit2@localhost set_policy ha-all "^" '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "^" to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...
[root@172 rabbitmq]# rabbitmqctl -n rabbit3@localhost set_policy ha-all "^" '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "^" to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...