vim /etc/hosts 192.168.0.100 rabbit1 192.168.0.101 rabbit2 192.168.0.104 rabbit3
wget [https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm](https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm) yum install epel-release -y rpm -Uvh erlang-solutions-1.0-1.noarch.rpm yum install erlang -y
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.22/rabbitmq-server-3.8.22-1.el7.noarch.rpm yum -y install rabbitmq-server-3.8.22-1.el7.noarch.rpm systemctl enable --now rabbitmq-server
开启插件:rabbitmq-plugins enable rabbitmq_management
http://ip:15672/
配置guest可登录:
vim /etc/rabbitmq/rabbitmq.config [{rabbit, [{loopback_users, []}]}]. rabbitmq-plugins list
重启服务:systemctl restart rabbitmq-server
mkdir -p /data/rabbitmq/{mnesia,log} vim /etc/rabbitmq/rabbitmq-env.conf RABBITMQ_MNESIA_BASE=/data/rabbitmq/mnesia RABBITMQ_LOG_BASE=/data/rabbitmq/log
rabbitmq1作为群集的管理节点,将rabbit1的.erlang.cookie文件拷贝到其它节点,权限为400,用户为rabbitmq
[root@rabbit1 ~]# scp /var/lib/rabbitmq/.erlang.cookie 192.168.0.101:/var/lib/rabbitmq/ [root@rabbit1 ~]# scp /var/lib/rabbitmq/.erlang.cookie 192.168.0.104:/var/lib/rabbitmq/ chmod 400 /var/lib/rabbitmq/.erlang.cookie 重启rabbitmq服务 systemctl restart rabbitmq-server
将rabbit2、rabbit3加入群集
rabbit2内存节点加入集群:
停止rabbitmq2上的服务 [root@rabbitmq2 ~]# rabbitmqctl stop_app 将rabbitmq2加入集群,--ram是以内存方式加入 [root@rabbit2 ~]# rabbitmqctl join_cluster --ram rabbit@rabbit1 [root@rabbit2 ~]# rabbitmqctl start_app
rabbit3磁盘节点加入集群:
停止rabbit3上的服务 [root@rabbitmq3 ~]# rabbitmqctl stop_app 将rabbit3加入集群,默认磁盘节点 [root@rabbitmq3 ~]# rabbitmqctl join_cluster rabbit@rabbit1 [root@rabbitmq3 ~]# rabbitmqctl start_app
rabbitmqctl cluster_status
所有队列exchanges 或者 queue都为镜像模式,在其中一个节点操作:
rabbitmqctl set_policy ha-all “^” ‘{“ha-mode”:“all”}’