vim /etc/hosts
192.168.1.1 node1
192.168.1.2 node2
192.168.1.3 node3
1、安装rabbitmq-server
# yum install -y rabbitmq-server
2、读取其中一个节点的cookie,并复制到其他节点(节点间通过cookie确定相互是否可通信)
选取node1为主节点
# scp /var/lib/rabbitmq/.erlang.cookie root@192.168.1.2:/var/lib/rabbitmq/
# scp /var/lib/rabbitmq/.erlang.cookie root@192.168.1.3:/var/lib/rabbitmq/
3、逐个启动节点
# systemctl start rabbitmq-server
查看各节点中的RabbitMQ brokers
# rabbitmqctl cluster_status
4、建集群分别在node2、node3 上执行
# rabbitmqctl stop_app
# rabbitmqctl join_cluster --ram rabbit@node1
# rabbitmqctl start_app
5、RabbitMQ cluster 管理
a.查看集群状态可分别在集群中各个节点执行
[root@node1 ~]# rabbitmqctl cluster_status
Cluster status of node rabbit@node1 ...
[{nodes,[{disc,[rabbit@node1]},{ram,[rabbit@node3,rabbit@node2]}]},
{running_nodes,[rabbit@node3,rabbit@node2,rabbit@node1]},
{cluster_name,<<"rabbit@node1">>},
{partitions,[]},
{alarms,[{rabbit@node3,[]},{rabbit@node2,[]},{rabbit@node1,[]}]}]
b.更改节点类型(内存型或磁盘型)
#rabbitmqctl change_cluster_node_type disc
或
# rabbitmqctl change_cluster_node_type ram
# rabbitmqctl start_app
c.重启cluster中的节点停止某个节点或者节点down掉剩余节点不受影响
[root@node2 ~]# rabbitmqctl stop
Stopping and halting node rabbit@node2 ...
添加账户(只需要在一台机器上设置,加入集群后会同步到所有机器)
rabbitmqctl add_user username password
rabbitmqctl set_user_tags username administrator
修改密码
rabbitmqctl change_password Username Newpassword
查看当前用户
rabbitmqctl list_users
开启web管理界面
cd /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.2/sbin/
rabbitmq-plugins enable rabbitmq_management
[root@node1 sbin]# netstat -lunpt | grep 5672
tcp 0 0 0.0.0.0:25672 0.0.0.0:* LISTEN 2032/beam.smp
tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 2032/beam.smp
tcp6 0 0 :::5672 :::* LISTEN 2032/beam.smp
可以看到15672端口已经监听
网友评论