centos7-rabbitmq 3.8 集群部署

基于CentOS 7 x86_64 rabbitmq 3.8

1. 安装依赖
1
安装docker-ce环境
1
2
3
4
5
6
#mkdir -p /data/rabbitmq/rabbit-docker-database 
#vim /data/rabbitmq/rabbit-docker-hosts

10.250.250.120 rabbit1 ostack120
10.250.250.121 rabbit2 ostack121
10.250.250.122 rabbit3 ostack122

3. 安装rabbitmq

1
2
3
4
主节点 120 执行
#docker run -d --restart=always --net host --hostname rabbit1 --name myrabbit1 -v /data/rabbitmq/rabbit-docker-hosts:/etc/hosts -v /data/rabbitmq/rabbit-docker-database:/var/lib/rabbitmq -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.8.5-management
从节点 121 执行
#docker run -d --restart=always --net host --hostname rabbit2 --name myrabbit2 -v /data/rabbitmq/rabbit-docker-hosts:/etc/hosts -v /data/rabbitmq/rabbit-docker-database:/var/lib/rabbitmq -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.8.5-management

4. 加入集群

1
2
3
4
5
6
#docker exec -it myrabbit2 bash # 进入镜像命令行
#rabbitmqctl stop_app
//rabbitmqctl reset
#rabbitmqctl join_cluster rabbit@rabbit1 #rabbit1为主节点的hostname
#rabbitmqctl start_app
#rabbitmq-plugins enable rabbitmq_management

5. 权限初始化

1
2
3
4
5
新增账号权限
#rabbitmqctl add_user openstack Openstack
#rabbitmqctl set_permissions openstack ".*" ".*" ".*";
#rabbitmqctl set_policy ha-all "" '{"ha-mode":"all", "ha-sync-mode": "automatic"}'

排错

rabbitmq1 可能会挂掉,可能需要重启 myrabbit1

附录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
启动rabbitmq
rabbitmqctl start_app

停止rabbitmq
rabbitmqctl stop_app

rabbitmq 查看所有队列信息
rabbitmqctl list_queues

还原 rabbitmq 清除所有队列
rabbitmqctl reset

rabbitmq 查看用户
rabbitmqctl list_users

rabbitmq添加用户
rabbitmqctl add_user root root

rabbitmq设置权限
rabbitmqctl set_permissions -p / root ".*" ".*" ".*"

rabbitmq查看集群状态信息
rabbitmqctl cluster_status

移除某个集群节点:一般情况当节点故障时,在正常的节点中,移除该故障节点
rabbitmqctl -n rabbit@rabbit1 forget_cluster_node rabbit@rabbit3