1: 执行以下命令将存储库添加到你的apt仓库
$ echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list
2: 通过apt-key添加trusted key
$ wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
3: 运行下面命令更新package list
$ sudo apt-get update
4: 安装rabbitmq-server
$ sudo apt-get install rabbitmq-server
Rabbitmq cluster install and configure
1: $ sudo vim /etc/hosts(三台节点同时设置)
192.168.x.10 snail1.xx.comsnail1
192.168.x.20 snail2.xx.comsnail2
192.168.x.30 snail3.xx.comsnail3
2: $ sudo cp /var/lib/rabbitmq/.erlang.cookie /var/lib/rabbitmq/.erlang.cookie.bak(三台节点同时备份)
3: $ sudo vim /var/lib/rabbitmq/.erlang.cookie (三台节点同时修改配置跟第一节点保持一致,ps:官方只说明三个节点保持一致没有特殊说明具体跟哪一个节点保持一致)
然后重启三台主机
4:(三个节点同时执行以下操作,)
host1: $ sudo rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
ERROR: node with name "rabbit" already running on "snail1"
host2: $ sudo rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
ERROR: node with name "rabbit" already running on "snail2"
host3: $ sudo rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
ERROR: node with name "rabbit" already running on "snail3"
5: (三个节点同同时执行以下操作)
host1: $ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@snail1
[{nodes,[{disc,[rabbit@snail1]}]},
{running_nodes,[rabbit@snail1]},
{cluster_name,<<"rabbit@snail1.xx.com">>},
{partitions,[]},
{alarms,[{rabbit@snail1,[]}]}]
host2: sudo rabbitmqctl cluster_status
Cluster status of node rabbit@snail2
[{nodes,[{disc,[rabbit@snail2]}]},
{running_nodes,[rabbit@snail2]},
{cluster_name,<<"rabbit@snail2.xx.com">>},
{partitions,[]},
{alarms,[{rabbit@snail2,[]}]}]
host3: sudo rabbitmqctl cluster_status
Cluster status of node rabbit@snail3
[{nodes,[{disc,[rabbit@snail3]}]},
{running_nodes,[rabbit@snail3]},
{cluster_name,<<"rabbit@snail3.xx.com">>},
{partitions,[]},
{alarms,[{rabbit@snail3,[]}]}]
6: 将host2 加入 rabbitmq 集群,在host2执行以下命令
1): sudo rabbitmqctl stop_app
Stopping rabbit application on node rabbit@snail2
2): sudo rabbitmqctl join_cluster rabbit@snail1
Clustering node rabbit@snail2 with rabbit@snail1
3): sudo rabbitmqctl start_app
Starting node rabbit@snail2
7: $ sudo rabbitmqctl cluster_status
Cluster status of node rabbit@snail1
[{nodes,[{disc,[rabbit@snail1,rabbit@snail2]}]},
{running_nodes,[rabbit@snail2,rabbit@snail1]},
{cluster_name,<<"rabbit@snail1.xx.com">>},
{partitions,[]},
{alarms,[{rabbit@snail2,[]},{rabbit@snail1,[]}]}]
8: 将host3加入rabbitmq集群,在host3执行以下操作
1): sudo rabbitmqctl stop_app
Stopping rabbit application on node rabbit@snail3
2): sudo rabbitmqctl join_cluster rabbit@snail2
Clustering node rabbit@snail3 with rabbit@snail2
3): sudo rabbitmqctl start_app
Starting node rabbit@snail3
9: host1: sudo rabbitmqctl cluster_status
Cluster status of node rabbit@snail1
[{nodes,[{disc,[rabbit@snail1,rabbit@snail2,rabbit@snail3]}]},
{running_nodes,[rabbit@snail3,rabbit@snail2,rabbit@snail1]},
{cluster_name,<<"rabbit@snail1.xx.com">>},
{partitions,[]},
{alarms,[{rabbit@snail3,[]},{rabbit@snail2,[]},{rabbit@snail1,[]}]}]
host2: sudo rabbitmqctl cluster_status
Cluster status of node rabbit@snail2
[{nodes,[{disc,[rabbit@snail1,rabbit@snail2,rabbit@snail3]}]},
{running_nodes,[rabbit@snail3,rabbit@snail1,rabbit@snail2]},
{cluster_name,<<"rabbit@snail1.xx.com">>},
{partitions,[]},
{alarms,[{rabbit@snail3,[]},{rabbit@snail1,[]},{rabbit@snail2,[]}]}]
host3:sudo rabbitmqctl cluster_status
Cluster status of node rabbit@snail3
[{nodes,[{disc,[rabbit@snail1,rabbit@snail2,rabbit@snail3]}]},
{running_nodes,[rabbit@snail1,rabbit@snail2,rabbit@snail3]},
{cluster_name,<<"rabbit@snail1.xx.com">>},
{partitions,[]},
{alarms,[{rabbit@snail1,[]},{rabbit@snail2,[]},{rabbit@snail3,[]}]}]
由上面信息可以看出 正在运行的节点有三台rabbit@snail3,rabbit@snail2,rabbit@snail1]
集群名称为rabbit@snail1.xx.com
开启rabbit_management 15672端口web api
$ sudo rabbitmq-plugins set rabbitmq_management
其余两节点分别开启rabbitmq_management_agent
$ sudo rabbitmq-plugins enable rabbitmq_management_agent